def test_trial(self): self.billing.state = Billing.STATE_TRIAL self.billing.save() self.billing.invoice_set.all().delete() self.add_project() # No expiry set billing_check() notify_expired() perform_removal() self.billing.refresh_from_db() self.assertEqual(self.billing.state, Billing.STATE_TRIAL) self.assertEqual(self.billing.projects.count(), 1) self.assertIsNone(self.billing.removal) self.assertEqual(len(mail.outbox), 0) # Future expiry self.billing.expiry = timezone.now() + timedelta(days=1) self.billing.save() billing_check() notify_expired() perform_removal() self.billing.refresh_from_db() self.assertEqual(self.billing.state, Billing.STATE_TRIAL) self.assertEqual(self.billing.projects.count(), 1) self.assertIsNone(self.billing.removal) self.assertEqual(len(mail.outbox), 0) # Past expiry self.billing.expiry = timezone.now() - timedelta(days=1) self.billing.save() billing_check() notify_expired() perform_removal() self.billing.refresh_from_db() self.assertEqual(self.billing.state, Billing.STATE_EXPIRED) self.assertEqual(self.billing.projects.count(), 1) self.assertIsNotNone(self.billing.removal) self.assertEqual(len(mail.outbox), 1) self.assertEqual( mail.outbox.pop().subject, 'Your translation project is scheduled for removal' ) # Removal self.billing.removal = timezone.now() - timedelta(days=30) self.billing.save() billing_check() perform_removal() self.billing.refresh_from_db() self.assertEqual(self.billing.state, Billing.STATE_TERMINATED) self.assertEqual(self.billing.projects.count(), 0) self.assertEqual(len(mail.outbox), 1) self.assertEqual( mail.outbox.pop().subject, 'Your translation project was removed' )
def test_trial(self): self.billing.state = Billing.STATE_TRIAL self.billing.save(skip_limits=True) self.billing.invoice_set.all().delete() self.add_project() # No expiry set billing_check() notify_expired() perform_removal() self.refresh_from_db() self.assertEqual(self.billing.state, Billing.STATE_TRIAL) self.assertTrue(self.billing.paid) self.assertEqual(self.billing.projects.count(), 1) self.assertIsNone(self.billing.removal) self.assertEqual(len(mail.outbox), 0) # Future expiry self.billing.expiry = timezone.now() + timedelta(days=30) self.billing.save(skip_limits=True) billing_check() notify_expired() perform_removal() self.refresh_from_db() self.assertEqual(self.billing.state, Billing.STATE_TRIAL) self.assertTrue(self.billing.paid) self.assertEqual(self.billing.projects.count(), 1) self.assertIsNone(self.billing.removal) self.assertEqual(len(mail.outbox), 0) # Close expiry self.billing.expiry = timezone.now() + timedelta(days=1) self.billing.save(skip_limits=True) billing_check() notify_expired() perform_removal() self.refresh_from_db() self.assertEqual(self.billing.state, Billing.STATE_TRIAL) self.assertTrue(self.billing.paid) self.assertEqual(self.billing.projects.count(), 1) self.assertIsNone(self.billing.removal) self.assertEqual(len(mail.outbox), 1) self.assertEqual(mail.outbox.pop().subject, "Your trial period is about to expire") # Past expiry self.billing.expiry = timezone.now() - timedelta(days=1) self.billing.save(skip_limits=True) billing_check() notify_expired() perform_removal() self.refresh_from_db() self.assertEqual(self.billing.state, Billing.STATE_TRIAL) self.assertTrue(self.billing.paid) self.assertEqual(self.billing.projects.count(), 1) self.assertIsNone(self.billing.expiry) self.assertIsNotNone(self.billing.removal) self.assertEqual(len(mail.outbox), 1) self.assertEqual( mail.outbox.pop().subject, "Your translation project is scheduled for removal", ) # There should be notification sent when removal is scheduled billing_check() notify_expired() perform_removal() self.refresh_from_db() self.assertEqual(self.billing.state, Billing.STATE_TRIAL) self.assertTrue(self.billing.paid) self.assertEqual(self.billing.projects.count(), 1) self.assertIsNotNone(self.billing.removal) self.assertEqual(len(mail.outbox), 1) self.assertEqual( mail.outbox.pop().subject, "Your translation project is scheduled for removal", ) # Removal self.billing.removal = timezone.now() - timedelta(days=1) self.billing.save(skip_limits=True) billing_check() perform_removal() self.refresh_from_db() self.assertEqual(self.billing.state, Billing.STATE_TERMINATED) self.assertFalse(self.billing.paid) self.assertEqual(self.billing.projects.count(), 0) self.assertEqual(len(mail.outbox), 1) self.assertEqual(mail.outbox.pop().subject, "Your translation project was removed")