budjeto/authentication/tests/test_signup.py

107 lines
2.9 KiB
Python
Raw Normal View History

from django.urls import reverse_lazy
from rest_framework import status
def test_signup__ok(client, User):
assert 0 == User.objects.count()
resp = client.post(reverse_lazy('auth:signup'), {
'username': 'dan',
'password': 'danpassword',
'email': 'dan@email.com'
})
assert resp.status_code == status.HTTP_201_CREATED
assert 1 == User.objects.count()
assert 'dan' == User.objects.first().username
assert 'dan@email.com' == User.objects.first().email
def test_signup__err_username_already_taken(client, User, mkuser):
mkuser('dan')
assert 1 == User.objects.count()
resp = client.post(reverse_lazy('auth:signup'), {
'username': 'dan',
'password': 'danpassword',
'email': 'dan@email.com'
})
assert resp.status_code != status.HTTP_201_CREATED
assert 1 == User.objects.count()
def test_signup__err_email_already_taken(client, User, mkuser):
mkuser('sam', 'dan@email.com')
assert 1 == User.objects.count()
resp = client.post(reverse_lazy('auth:signup'), {
'username': 'dan',
'password': 'danpassword',
'email': 'dan@email.com'
})
assert resp.status_code != status.HTTP_201_CREATED
assert 1 == User.objects.count()
def test_signup__err_blank_username(client, User):
resp = client.post(reverse_lazy('auth:signup'), {
'username': '',
'password': 'danpassword',
'email': 'dan@email.com'
})
assert resp.status_code == status.HTTP_400_BAD_REQUEST
assert 0 == User.objects.count()
def test_signup__err_no_username(client, User):
resp = client.post(reverse_lazy('auth:signup'), {
'password': 'danpassword',
'email': 'dan@email.com'
})
assert resp.status_code == status.HTTP_400_BAD_REQUEST
assert 0 == User.objects.count()
def test_signup__err_blank_password(client, User):
resp = client.post(reverse_lazy('auth:signup'), {
'username': 'dan',
'password': '',
'email': 'dan@email.com'
})
assert resp.status_code == status.HTTP_400_BAD_REQUEST
assert 0 == User.objects.count()
def test_signup__err_no_password(client, User):
resp = client.post(reverse_lazy('auth:signup'), {
'username': 'dan',
'email': 'dan@email.com'
})
assert resp.status_code == status.HTTP_400_BAD_REQUEST
assert 0 == User.objects.count()
def test_signup__err_blank_email(client, User):
resp = client.post(reverse_lazy('auth:signup'), {
'username': 'dan',
'password': 'danpassword',
'email': ''
})
assert resp.status_code == status.HTTP_400_BAD_REQUEST
assert 0 == User.objects.count()
def test_signup__err_no_email(client, User):
resp = client.post(reverse_lazy('auth:signup'), {
'username': 'dan',
'password': 'danpassword',
})
assert resp.status_code == status.HTTP_400_BAD_REQUEST
assert 0 == User.objects.count()