class SubscriptionModelAdminTest(TestCase): def setUp(self): self.model_admin = SubscriptionModelAdmin(Subscription, admin) Subscription.objects.create(name='Gustavo', cpf='12345678901', email='*****@*****.**', phone='938654321') self.subscription = Subscription(created_at=timezone.now()) def test_subscribed_one_day_ago(self): self.subscription.created_at = timezone.now() + datetime.timedelta( hours=24) self.assertFalse(self.model_admin.subscribed_today(self.subscription)) def test_subscribed_just_now(self): self.assertTrue(self.model_admin.subscribed_today(self.subscription)) def test_has_action(self): """ Action mark_as_paid should be installed """ self.assertIn('mark_as_paid', self.model_admin.actions) def test_mark_all(self): """ It should mark all selected subscription as paid """ self.call_action_mark_as_paid() self.assertEqual(1, Subscription.objects.filter(paid=True).count()) def test_message(self): """ It should send message to the user """ mock = self.call_action_mark_as_paid() mock.assert_called_once_with(None, '1 inscrição foi marcada como pago') def call_action_mark_as_paid(self): selected_subscriptions = Subscription.objects.all() mock = Mock() old_message_user = SubscriptionModelAdmin.message_user SubscriptionModelAdmin.message_user = mock self.model_admin.mark_as_paid(None, selected_subscriptions) SubscriptionModelAdmin.message_user = old_message_user return mock
def test_subscribed_today(self): self.assertTrue( SubscriptionModelAdmin.subscribed_today(self, self.obj), '')