Guest User

Untitled

a guest
Sep 19th, 2018
459
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. """ File location: authors/apps/authentication/tests.py
  2. Description: tests that a user cannot login with an invalid email address format.
  3. """
  4.  
  5. from django.test import TestCase, Client
  6. from .models import UserManager
  7.  
  8. class AuthenticationTest(TestCase):
  9. """ Tests authentication functionality of the application such as registration,
  10. logging in, log out and refreshing of JWT tokens.
  11. """
  12.  
  13. def setUp(self):
  14. # create the test client...
  15. self.client = Client()
  16.  
  17. # create at least one user...
  18. UserManager.create_user(
  19. username='John Doe',
  20. email='john@doe.com',
  21. password='1234567'
  22. )
  23.  
  24.  
  25. def test_cannot_login_with_invalid_email(self):
  26. # try logging in with an invalid email...
  27. resp = self.client.post('/api/users/login',
  28. {'user': {
  29. 'email': 'NOT-AN-EMAIL-CLEARLY',
  30. 'password': '1234567'}})
  31.  
  32. # we should should get an Unprocessable Entity error.
  33. self.assertEqual(resp.status_code, 422)
  34. self.assertIn(resp.content, b'Invalid email format')
Add Comment
Please, Sign In to add comment