-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.py
42 lines (31 loc) · 1.65 KB
/
tests.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
from django.test.utils import setup_test_environment
setup_test_environment()
#Imports for the test run
from django.test import Client
import pytest
class TestClient(object):
def test_get_index(self):
c = Client()
url = '/'
response = c.get(url)
assert response.content, 'No html in the response of get({0})'.format(url)
assert response.context['context'], 'Context is not loaded in the response of get({0})'.format(url)
def test_post_signin(self):
c = Client()
url = '/'
response_unauth = c.post(url, {'name':'sign_in', 'username':'unauth', 'password':'pass'})
assert response_unauth.status_code == 401, 'Should have raised unauthorized response >> response: {0}'.format(response_unauth)
response_invalid = c.post(url, {'name': 'sign_in', 'test':'test'})
assert response_invalid.status_code == 400, 'Bad form should have given HTTP400 error >> response: {0}'.format(response_invalid)
pytest.raises(NameError, c.post, url, {'name':'test'})
def test_post_signup(self):
c = Client()
url = '/'
# Create User
response_create = c.post(url, {'name':'sign_up', 'username':'test', 'password':'pass'})
assert response_create.status_code == 200
# Check that user exists
response_login = c.post(url, {'name':'sign_in', 'username':'test', 'password':'pass'})
assert response_login.status_code == 200
# Try to create andother user
pytest.raises(NotImplementedError, c.post, url, {'name': 'sign_up', 'username': 'test', 'password': 'pass'})