def test_should_confirmed_email_if_token_is_valid(self): password = '******' user = UserFactory() user.is_email_confirmed = False user.set_password(password) user.save() path = reverse('app:users_confirm_email', args=[user.token]) response = self.client.get(path) self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)
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_logged_user_todos(self): user = UserFactory() user.is_email_confirmed = True user.save() todos = ToDoFactory.create_many(user) path = reverse('app:todos_list_create') 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(todos))
def test_should_return_only_not_overdue_tasks_if_i_add_actual_true_to_query_param( self): finished_minute_before = timezone.now() - timedelta(minutes=1) user = UserFactory() user.is_email_confirmed = True user.save() ToDoFactory(user=user, finish_at=finished_minute_before) path = reverse('app:todos_list_create') + '?actual=True' 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), 0)
def test_should_return_only_is_not_done_tasks_if_i_add_actual_true_to_query_param( self): todos_count = 20 user = UserFactory() user.is_email_confirmed = True user.save() ToDoFactory.create_many(user, is_done=True, count=todos_count) path = reverse('app:todos_list_create', actual=True) 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), 0)
def test_should_raise_error_if_user_email_is_not_confirmed(self): password = '******' user = UserFactory() user.is_email_confirmed = False user.set_password(password) user.save() path = reverse('app:users_login') data = {"username": user.username, "password": password} response = self.client.post(path, data=data, content_type='application/json') body = response.json() self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) self.assertEqual(body['error'][0], 'user.email.notConfirmed')
def test_should_auth_user_if_login_and_password_is_correct(self): password = '******' user = UserFactory() user.is_email_confirmed = True user.set_password(password) user.save() path = reverse('app:users_login') data = {"username": user.username, "password": password} response = self.client.post(path, data=data, content_type='application/json') body = response.json() self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(body['username'], user.username)
def test_should_order_by_finish_at(self): todos_count = 20 user = UserFactory() user.is_email_confirmed = True user.save() todos = ToDoFactory.create_many(user, count=todos_count) todos = todos.order_by('finish_at') path = reverse('app:todos_list_create') 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) for i in range(todos_count): self.equal_to_do_dicts(todos[i].__dict__, body[i])
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__)