-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
59 lines (49 loc) · 1.3 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import requests
# verify validation
verify = '/Users/jcbages/Documents/uniandes/arquitecturasw/solumovil/server.pem'
# POST authentication, returns admin token
# so save it in a constant called TOKEN.
URL = 'http://127.0.0.1:8000/api-token-auth/'
data = {
'username': 'admin',
'password': '123'
}
ans = requests.post(URL, data=data)
print ans.text.encode('utf8')
ADMIN_TOKEN = ans.json().get('token')
print "=" * 100
# Try to make a GET request without
# being authorized, result should
# be bad (no access).
URL = 'http://127.0.0.1:8000/usuarios/'
ans = requests.get(URL)
print ans.text.encode('utf8')
print "=" * 100
# Add a new user
headers = {
'Authorization': 'Token %s' % ADMIN_TOKEN
}
data = {
'nombre': 'Yerson',
'username': 'yerson',
'password': '123'
}
ans = requests.post(URL, data=data, headers=headers)
print ans.text.encode('utf8')
print "=" * 100
# Make a GET request now with admin
# token in headers, expect results.
ans = requests.get(URL, headers=headers)
for x in ans.json():
print x
print "=" * 100
# POST authentication, returns ana token
# so save it in a constant called TOKEN.
URL = 'http://127.0.0.1:8000/api-token-auth/'
data = {
'username': 'yerson',
'password': '123'
}
ans = requests.post(URL, data=data, verify=False)
print ans.text.encode('utf8')
ANA_TOKEN = ans.json().get('token')