remove unnecessary imports
[mygpo.git] / mygpo / api / put_test.py
blob24df3cf32825fb59ad6589ba0315d753386f0bc0
1 import httplib
2 import base64
3 import time
5 def put_data(dev_uid, format, data, username, password):
6 cmd = '/subscriptions/%s/%d.%s' % (username, dev_uid, format)
7 connection = httplib.HTTPConnection('127.0.0.1:8000')
8 headers = {}
9 headers['Authorization'] = ' '.join(('Basic', base64.encodestring(':'.join((username, password)))))
10 connection.request('PUT', cmd, data, headers)
11 response = connection.getresponse()
12 print response.read()
13 connection.close()
15 def get_data(dev_uid, format, username, password):
16 data = None
17 cmd = '/subscriptions/%s/%d.%s' % (username, dev_uid, format)
18 connection = httplib.HTTPConnection('127.0.0.1:8000')
19 headers = {}
20 headers['Authorization'] = ' '.join(('Basic', base64.encodestring(':'.join((username, password)))))
21 connection.request('GET', cmd, data, headers)
22 response = connection.getresponse()
23 print response.read()
24 connection.close()
26 if __name__ == "__main__":
27 u = 'ale'
28 p = 'ale'
29 p1 = 'http://www.podcast1.com'
30 p2 = 'http://www.podcast2.com'
31 p3 = 'http://www.podcast3.com'
32 p4 = 'http://www.podcast4.com'
33 data_txt_1 = '%s\n%s\n\n' % (p1, p2)
34 data_txt_2 = '%s\n%s\n\n' % (p2, p3)
35 data_txt_3 = '%s\n%s\n%s\n\n' % (p1, p3, p4)
36 d1 = 1
37 print 'put %s and %s on device %d' % (p1, p2, d1)
38 put_data(d1, 'txt', data_txt_1, u, p)
39 print 'get subscriptions'
40 get_data(d1, 'txt', u, p)
41 time.sleep(2)
42 print 'put %s and %s on device %d' % (p2, p3, d1)
43 put_data(d1, 'txt', data_txt_2, u, p)
44 print 'get subscriptions'
45 get_data(d1, 'txt', u, p)
46 time.sleep(2)
47 print 'put %s, %s and %s on device %d' % (p1, p3, p4, d1)
48 put_data(d1, 'txt', data_txt_3, u, p)
49 print 'get subscriptions'
50 get_data(d1, 'txt', u, p)