Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """ 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 at least one 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 should get an Unprocessable Entity error.
- self.assertEqual(resp.status_code, 422)
- self.assertIn(resp.content, b'Invalid email format')
Add Comment
Please, Sign In to add comment