annotate checkclient.py @ 94:2ef34abbad8d 1.5

Use http error code 422 in CheckView when a merge is not possible. Previously the response used the code 500 in this case. This is not useful because it's not an internal server error when the check whether a PDF file can be merged fails because that's the point of the CheckView. The code used now means "Unprocessable Entity" and fits better. Part of mpuls/issue6009
author Bernhard Herzog <bh@intevation.de>
date Fri, 28 Apr 2017 20:56:22 +0200
parents 3928af61b4ce
children 349d49bb69f4
rev   line source
74
22ce0dc2e71c Add client to test demonstrate the check feature
Frank Koormann <frank.koormann@intevation.de>
parents:
diff changeset
1 #!/usr/bin/env python
22ce0dc2e71c Add client to test demonstrate the check feature
Frank Koormann <frank.koormann@intevation.de>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
22ce0dc2e71c Add client to test demonstrate the check feature
Frank Koormann <frank.koormann@intevation.de>
parents:
diff changeset
3
22ce0dc2e71c Add client to test demonstrate the check feature
Frank Koormann <frank.koormann@intevation.de>
parents:
diff changeset
4 import optparse
22ce0dc2e71c Add client to test demonstrate the check feature
Frank Koormann <frank.koormann@intevation.de>
parents:
diff changeset
5 import sys
22ce0dc2e71c Add client to test demonstrate the check feature
Frank Koormann <frank.koormann@intevation.de>
parents:
diff changeset
6
22ce0dc2e71c Add client to test demonstrate the check feature
Frank Koormann <frank.koormann@intevation.de>
parents:
diff changeset
7 import requests
22ce0dc2e71c Add client to test demonstrate the check feature
Frank Koormann <frank.koormann@intevation.de>
parents:
diff changeset
8
22ce0dc2e71c Add client to test demonstrate the check feature
Frank Koormann <frank.koormann@intevation.de>
parents:
diff changeset
9
22ce0dc2e71c Add client to test demonstrate the check feature
Frank Koormann <frank.koormann@intevation.de>
parents:
diff changeset
10 def main():
22ce0dc2e71c Add client to test demonstrate the check feature
Frank Koormann <frank.koormann@intevation.de>
parents:
diff changeset
11 usage = "usage: %prog [options] infile"
22ce0dc2e71c Add client to test demonstrate the check feature
Frank Koormann <frank.koormann@intevation.de>
parents:
diff changeset
12 parser = optparse.OptionParser(usage=usage)
22ce0dc2e71c Add client to test demonstrate the check feature
Frank Koormann <frank.koormann@intevation.de>
parents:
diff changeset
13 parser.add_option("-s", "--host", default="localhost")
22ce0dc2e71c Add client to test demonstrate the check feature
Frank Koormann <frank.koormann@intevation.de>
parents:
diff changeset
14 parser.add_option("-p", "--port", default="5000")
22ce0dc2e71c Add client to test demonstrate the check feature
Frank Koormann <frank.koormann@intevation.de>
parents:
diff changeset
15 (options, args) = parser.parse_args()
22ce0dc2e71c Add client to test demonstrate the check feature
Frank Koormann <frank.koormann@intevation.de>
parents:
diff changeset
16
75
3928af61b4ce checkclient final fixes
Frank Koormann <frank@intevation.de>
parents: 74
diff changeset
17 if len(args) < 1:
74
22ce0dc2e71c Add client to test demonstrate the check feature
Frank Koormann <frank.koormann@intevation.de>
parents:
diff changeset
18 parser.print_usage()
22ce0dc2e71c Add client to test demonstrate the check feature
Frank Koormann <frank.koormann@intevation.de>
parents:
diff changeset
19 sys.exit(1)
22ce0dc2e71c Add client to test demonstrate the check feature
Frank Koormann <frank.koormann@intevation.de>
parents:
diff changeset
20
22ce0dc2e71c Add client to test demonstrate the check feature
Frank Koormann <frank.koormann@intevation.de>
parents:
diff changeset
21 url = "http://%s:%s/check/" % (options.host, options.port)
22ce0dc2e71c Add client to test demonstrate the check feature
Frank Koormann <frank.koormann@intevation.de>
parents:
diff changeset
22 infilename = args[0]
22ce0dc2e71c Add client to test demonstrate the check feature
Frank Koormann <frank.koormann@intevation.de>
parents:
diff changeset
23
22ce0dc2e71c Add client to test demonstrate the check feature
Frank Koormann <frank.koormann@intevation.de>
parents:
diff changeset
24 files = {'file': open(infilename, 'rb')}
22ce0dc2e71c Add client to test demonstrate the check feature
Frank Koormann <frank.koormann@intevation.de>
parents:
diff changeset
25
75
3928af61b4ce checkclient final fixes
Frank Koormann <frank@intevation.de>
parents: 74
diff changeset
26 r = requests.post(url, files=files)
74
22ce0dc2e71c Add client to test demonstrate the check feature
Frank Koormann <frank.koormann@intevation.de>
parents:
diff changeset
27
22ce0dc2e71c Add client to test demonstrate the check feature
Frank Koormann <frank.koormann@intevation.de>
parents:
diff changeset
28 if r.status_code == 200:
22ce0dc2e71c Add client to test demonstrate the check feature
Frank Koormann <frank.koormann@intevation.de>
parents:
diff changeset
29 print "OK"
22ce0dc2e71c Add client to test demonstrate the check feature
Frank Koormann <frank.koormann@intevation.de>
parents:
diff changeset
30 else:
22ce0dc2e71c Add client to test demonstrate the check feature
Frank Koormann <frank.koormann@intevation.de>
parents:
diff changeset
31 print "An error has occured"
22ce0dc2e71c Add client to test demonstrate the check feature
Frank Koormann <frank.koormann@intevation.de>
parents:
diff changeset
32 print r.status_code, r.headers
22ce0dc2e71c Add client to test demonstrate the check feature
Frank Koormann <frank.koormann@intevation.de>
parents:
diff changeset
33 print r.text
22ce0dc2e71c Add client to test demonstrate the check feature
Frank Koormann <frank.koormann@intevation.de>
parents:
diff changeset
34 sys.exit(2)
22ce0dc2e71c Add client to test demonstrate the check feature
Frank Koormann <frank.koormann@intevation.de>
parents:
diff changeset
35
22ce0dc2e71c Add client to test demonstrate the check feature
Frank Koormann <frank.koormann@intevation.de>
parents:
diff changeset
36
22ce0dc2e71c Add client to test demonstrate the check feature
Frank Koormann <frank.koormann@intevation.de>
parents:
diff changeset
37 if __name__ == "__main__":
22ce0dc2e71c Add client to test demonstrate the check feature
Frank Koormann <frank.koormann@intevation.de>
parents:
diff changeset
38 main()
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)