Skip to content

Instantly share code, notes, and snippets.

@codingedward
Last active September 19, 2018 13:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codingedward/da597467041748d2bfde6fc11e9ce845 to your computer and use it in GitHub Desktop.
Save codingedward/da597467041748d2bfde6fc11e9ce845 to your computer and use it in GitHub Desktop.
""" File location: authors/apps/authentication/tests.py
Description: tests that a user cannot login with an invalid email address format.
"""
from django.test import TestCase, Client
from .models import UserManager
class AuthenticationTest(TestCase):
""" Tests authentication functionality of the application such as registration,
logging in, log out and refreshing of JWT tokens.
"""
def setUp(self):
# create the test client...
self.client = Client()
# create a user...
UserManager.create_user(
username='John Doe',
email='john@doe.com',
password='1234567'
)
def test_cannot_login_with_invalid_email(self):
# try logging in with an invalid email...
resp = self.client.post('/api/users/login',
{'user': {
'email': 'NOT-AN-EMAIL-CLEARLY',
'password': '1234567'}})
# we should get an Unprocessable Entity error.
self.assertEqual(resp.status_code, 422)
self.assertIn(resp.content, b'Invalid email format')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment