Advertisement
Guest User

Untitled

a guest
May 26th, 2015
294
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. Unit tests
  2.  
  3. @override_settings(CELERY_ALWAYS_EAGER = True, BROKER_BACKEND = 'memory')
  4. def test_user_should_get_email_when_is_public_is_true_for_PRIMARY_OFFERINGS_ONLY(self):
  5. """
  6. issue 952 fix
  7. - if offering is primary and is_public goes from false to true then email should be sent
  8. - if offering is not primary and is_public goes from false to true no email should be sent
  9. """
  10. self.assertEqual(len(mail.outbox),0)
  11. self.assertFalse(self.offering.is_public)
  12. self.assertEquals(self.offering.offer_type, Offering.OFFERING_TYPE_PRIMARY)
  13.  
  14. self.offering.is_public = True
  15. self.offering.save()
  16.  
  17. # two users so two emails should get sent
  18. self.assertEqual(len(mail.outbox),2)
  19.  
  20. @override_settings(CELERY_ALWAYS_EAGER = True, BROKER_BACKEND = 'memory')
  21. def test_user_should_not_get_email_when_is_public_is_true_for_ANYTHING_BESIDES_PRIMARY_OFFERING(self):
  22. """
  23. issue 952 fix
  24. - if offering is primary and is_public goes from false to true then email should be sent
  25. - if offering is not primary and is_public goes from false to true no email should be sent
  26. """
  27. self.offering.offer_type = Offering.OFFERING_TYPE_SECONDARY
  28. self.offering.save()
  29.  
  30. self.assertEqual(len(mail.outbox),0)
  31. self.assertFalse(self.offering.is_public)
  32. self.assertEquals(self.offering.offer_type, Offering.OFFERING_TYPE_SECONDARY)
  33.  
  34. self.offering.is_public = True
  35. self.offering.save()
  36.  
  37. self.assertEqual(len(mail.outbox),0)
  38.  
  39.  
  40. Code
  41. if 'is_public' in dirty_fields and instance.is_public and instance.offer_type == Offering.OFFERING_TYPE_PRIMARY:
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement