Last active
September 19, 2018 13:20
-
-
Save codingedward/da597467041748d2bfde6fc11e9ce845 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" 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='[email protected]', | |
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