Guest User

Untitled

a guest
Dec 15th, 2018
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. class TestDeleteRecognizedFood(SoloTeamCreatingTest, APITestCase):
  2. def setUp(self):
  3. super(TestDeleteRecognizedFood, self).setUp()
  4. self.recognizedfood = mommy.make('RecognizedFood', food_log_entry_item__user=self.user)
  5.  
  6. def subject(self, email, password, recognizedfood_uuid=None):
  7. self.client.login(email=email, password=password)
  8.  
  9. if not recognizedfood_uuid:
  10. recognizedfood_uuid = self.recognizedfood.uuid
  11.  
  12. return self.client.delete(
  13. '/api/v4/recognized-foods/{}/'.format(recognizedfood_uuid),
  14. format='json',
  15. )
  16.  
  17. def test_coach_can_delete(self):
  18. response = self.subject(self.coach_email, self.coach_password)
  19. self.assertEqual(response.status_code, 204)
  20.  
  21. def test_user_can_delete(self):
  22. response = self.subject(self.user_email, self.user_password)
  23. self.assertEqual(response.status_code, 204)
  24.  
  25. def test_given_unauthorized_user_returns_403(self):
  26. bad_user_password = '12345678'
  27. bad_user = mommy.make('accounts.User', password=bad_user_password)
  28. response = self.subject(bad_user.email, bad_user_password)
  29. self.assertEqual(response.status_code, 403)
  30.  
  31. def test_given_unexisting_uuid_returns_404(self):
  32. response = self.subject(self.user_email, self.user_password, uuid.uuid4())
  33. self.assertEqual(response.status_code, 404)
Add Comment
Please, Sign In to add comment