def test_should_raise_error_to_get_users_if_user_is_not_admin(self): user = UserFactory() user.is_admin = False user.is_email_confirmed = True user.is_staff = True user.save() path = reverse('app:users_list') headers = {"HTTP_AUTHORIZATION": TOKEN_PREFIX + ' ' + user.token} response = self.client.get(path, **headers) self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
def test_should_return_all_users_except_him_if_user_is_admin(self): user = UserFactory() user.is_admin = True user.is_email_confirmed = True user.is_staff = True user.save() other_users = UserFactory.create_many(10) path = reverse('app:users_list') headers = {"HTTP_AUTHORIZATION": TOKEN_PREFIX + ' ' + user.token} response = self.client.get(path, **headers) body = response.json() self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(len(body), len(other_users)) for i in range(10): self.equal_user_dicts(body[i], other_users[i].__dict__)