def test_login(self): user = UserFactory() user.set_password('123123') user.save() response = self.client.get('/login/') self.assertEqual(response.status_code, 200) response = self.client.post('/login/', data={ 'username': user.username, 'password': '******' }) self.assertRedirects(response, '/')
def test_generate_api_token(self): user = UserFactory() user.api_token = 'aaa' user.save() with mock.patch( 'django.utils.crypto.get_random_string', side_effect=[ 'aaa', 'aaa', 'bbb' ] ): token = generate_api_token() self.assertEqual(token, 'bbb')
def test_update_user_access_groups(self): admin_group = GroupFactory(name='Admin') api_group = GroupFactory(name='API') user = UserFactory(username='******', email='*****@*****.**') user.groups.add(api_group) user.save() self.client.force_login(UserFactory(is_superuser=True)) response = self.client.get('/users/{pk}/'.format(pk=user.pk)) self.assertEqual(response.status_code, 200) response = self.client.post( '/users/{pk}/access/'.format(pk=user.pk), data={'groups': [admin_group.pk, api_group.pk]}) self.assertRedirects(response, '/users/') self.assertEqual(user.groups.count(), 2)