X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/6797be6ce464806fdfb17b6ada71ba7b0b87b2d4..d0ab1d8908cadac9f51a17e2fe9e1193f14e28cc:/scripts/test_api.py?ds=sidebyside diff --git a/scripts/test_api.py b/scripts/test_api.py new file mode 100644 index 000000000..41d3f3d98 --- /dev/null +++ b/scripts/test_api.py @@ -0,0 +1,26 @@ +import httplib2 +from poster.encode import multipart_encode +from poster.streaminghttp import register_openers +import sys +import getpass + +register_openers() + +datagen, headers = multipart_encode({'book_xml_file': open(sys.argv[1], "rb")}) +data = ''.join(list(datagen)) +for key, value in headers.items(): + headers[key] = str(value) + +password = getpass.getpass() + +h = httplib2.Http() +h.add_credentials('zuber', password) +h.follow_all_redirects = True + +resp, content = h.request( + 'http://localhost:8000/api/books.json', + 'POST', + body=data, + headers=headers +) +print resp, content \ No newline at end of file