autocomplete style
[wolnelektury.git] / scripts / test_api.py
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 # This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later.
4 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
5 #
6 import httplib2
7 from poster.encode import multipart_encode
8 from poster.streaminghttp import register_openers
9 import sys
10 import getpass
11
12 register_openers()
13
14 datagen, headers = multipart_encode({'book_xml_file': open(sys.argv[1], "rb")})
15 data = ''.join(list(datagen))
16 for key, value in headers.items():
17     headers[key] = str(value)
18
19 password = getpass.getpass()
20
21 h = httplib2.Http()
22 h.add_credentials('zuber', password)
23 h.follow_all_redirects = True
24
25 resp, content = h.request(
26     'http://localhost:8000/api/books.json',
27     'POST',
28     body=data,
29     headers=headers
30 )
31 print resp, content