I'm trying to test my project and I want to get a 200 status code with the following test:
import requests
def test_200(self):
url_csrftoken = 'http://ift.tt/1m0n8Yg'
url = 'http://127.0.0.1:8000/'
url_login = 'http://ift.tt/2d7U5H9'
client = requests.session()
client.get(url_csrftoken)
csrftoken = client.cookies['csrftoken']
login_data = dict(inputUser='admin', inputPassword='mypass', csrfmiddlewaretoken=csrftoken, next=url)
client.post(url_login, data=login_data)
r = client.get(url)
self.assertEqual(r.status_code,200)
It stops at: client.get(url_csrftoken) and gives the following error:
Traceback (most recent call last):
File "tests2.py", line 115, in test_networking
csrftoken = client.cookies['csrftoken']
File "/home/user/project/env/lib/python2.7/site-packages/requests/cookies.py", line 327, in __getitem__
return self._find_no_duplicates(name)
File "/home/user/project/env/lib/python2.7/site-packages/requests/cookies.py", line 398, in _find_no_duplicates
raise KeyError('name=%r, domain=%r, path=%r' % (name, domain, path))
KeyError: "name='csrftoken', domain=None, path=None"
Aucun commentaire:
Enregistrer un commentaire