class AuthTestCase(APITestCase): def setUp(self): super().setUp() self.email = '*****@*****.**' self.password = '******' self.user = UserFactory(email=self.email) self.user.set_password(self.password) self.user.save() def test_auth(self): user = authenticate(email=self.email, password=self.password) self.assertEqual(user, self.user) def test_login(self): self.url = '/rest-auth/login/' self.data = {"email": self.email, "password": self.password} response = self.client.post(self.url, self.data) self.assertTrue(response.data['key']) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertTrue(self.user.is_authenticated()) def test_logout(self): self.url = '/rest-auth/logout/' response = self.client.post(self.url) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertTrue(self.user.is_authenticated())
def alt_parent_user_password(db): """Creates an alt parent website user with a password. This will be used as an alternative parent user to confirm only children of currently logged in parent are shown in views. """ user = UserFactory(username='******', name='Johny', email='*****@*****.**', user_type=User.TYPE_PARENT, profile_photo='') user.set_password('password') user.save() return user