def test_no_duplicated_emails(mock_send): tester = testsupport.prepare_tester_account() tester_domain = testsupport.prepare_tester_domain( domain_name='abcd.ai', tester=tester, domain_epp_id='aaa123', ) tester_domain.expiry_date = timezone.now() + datetime.timedelta( days=45) # expiry_date 45 days from now tester_domain.status = 'active' tester_domain.save() # first time outgoing_emails = tasks.check_notify_domain_expiring(dry_run=False) assert len(outgoing_emails) == 1 assert outgoing_emails[0][0] == tester assert outgoing_emails[0][1] == tester_domain.name mock_send.return_value = True notifications.process_notifications_queue(iterations=1, delay=0.1) new_notification = Notification.notifications.first() assert new_notification.status == 'sent' # second time outgoing_emails_again = tasks.check_notify_domain_expiring(dry_run=False) assert len(outgoing_emails_again) == 0 # third time outgoing_emails_one_more = tasks.check_notify_domain_expiring( dry_run=False) assert len(outgoing_emails_one_more) == 0
def test_email_sent_and_executed(self, mock_send): tester = testsupport.prepare_tester_account() tester_domain = testsupport.prepare_tester_domain( domain_name='abcd.ai', tester=tester, domain_epp_id='aaa123', ) tester_domain.expiry_date = timezone.now() + datetime.timedelta( days=45) # expiry_date 45 days from now tester_domain.status = 'active' tester_domain.save() outgoing_emails = check_notify_domain_expiring( dry_run=False, min_days_before_expire=30, max_days_before_expire=60, subject='domain_expiring', ) assert len(outgoing_emails) == 1 assert outgoing_emails[0][0] == tester assert outgoing_emails[0][1] == tester_domain.name mock_send.return_value = True process_notifications_queue(iterations=1, delay=0.1, iteration_delay=0.1) new_notification = Notification.notifications.first() assert new_notification.subject == 'domain_expiring' assert new_notification.domain_name == 'abcd.ai' assert new_notification.status == 'sent'
def handle(self, dry_run, delay, *args, **options): iteration = 0 while True: iteration += 1 account_tasks.check_notify_domain_expiring(dry_run=dry_run) back_tasks.sync_expired_domains(dry_run=dry_run) account_tasks.activations_cleanup() # TODO: other background periodical jobs to be placed here logger.info('finished iteration %d at %r', iteration, timezone.now().isoformat()) time.sleep(delay)
def handle(self, dry_run, delay, *args, **options): iteration = 0 while True: iteration += 1 logger.info('# %d', iteration) # billing_tasks.retry_failed_orders() back_tasks.sync_expired_domains(dry_run=dry_run) account_tasks.check_notify_domain_expiring( dry_run=dry_run, min_days_before_expire=0, max_days_before_expire=30, subject='domain_expire_soon', ) account_tasks.check_notify_domain_expiring( dry_run=dry_run, min_days_before_expire=31, max_days_before_expire=60, subject='domain_expiring', ) back_tasks.auto_renew_expiring_domains( dry_run=dry_run, min_days_before_expire=61, max_days_before_expire=90, ) account_tasks.activations_cleanup() # Remove all inactive domains. zdomains.remove_inactive_domains(days=1) # Remove started but not completed orders after a day. billing_tasks.remove_started_orders(older_than_days=365) # TODO: other background periodical jobs to be placed here time.sleep(delay)
def test_check_notify_domain_expiring_when_not_active(): tester = testsupport.prepare_tester_account() tester_domain = testsupport.prepare_tester_domain( domain_name='abcd.ai', tester=tester, domain_epp_id='aaa123', ) tester_domain.expiry_date = timezone.now() + datetime.timedelta( days=45) # expiry_date 45 days from now tester_domain.status = 'inactive' tester_domain.save() outgoing_emails = tasks.check_notify_domain_expiring(dry_run=True) assert len(outgoing_emails) == 0
def test_check_notify_domain_expiring_when_alread_expired(): tester = testsupport.prepare_tester_account() tester_domain = testsupport.prepare_tester_domain( domain_name='abcd.ai', tester=tester, domain_epp_id='aaa123', ) tester_domain.expiry_date = timezone.now() - datetime.timedelta( days=10) # already expired 10 days ago tester_domain.status = 'active' tester_domain.save() outgoing_emails = tasks.check_notify_domain_expiring(dry_run=True) assert len(outgoing_emails) == 0
def test_account_profile_email_notifications_disabled(): tester = testsupport.prepare_tester_account() tester_domain = testsupport.prepare_tester_domain( domain_name='abcd.ai', tester=tester, domain_epp_id='aaa123', ) tester.profile.email_notifications_enabled = False tester.profile.save() tester_domain.expiry_date = timezone.now() + datetime.timedelta( days=45) # expiry_date 45 days from now tester_domain.status = 'active' tester_domain.save() outgoing_emails = tasks.check_notify_domain_expiring(dry_run=False) assert len(outgoing_emails) == 0
def test_not_active(self): tester = testsupport.prepare_tester_account() tester_domain = testsupport.prepare_tester_domain( domain_name='abcd.ai', tester=tester, domain_epp_id='aaa123', ) tester_domain.expiry_date = timezone.now() + datetime.timedelta( days=45) # expiry_date 45 days from now tester_domain.status = 'inactive' tester_domain.save() outgoing_emails = check_notify_domain_expiring( dry_run=True, min_days_before_expire=0, max_days_before_expire=30, subject='domain_expire_soon', ) assert len(outgoing_emails) == 0
def test_notifications_disabled(self): tester = testsupport.prepare_tester_account() tester_domain = testsupport.prepare_tester_domain( domain_name='abcd.ai', tester=tester, domain_epp_id='aaa123', ) tester.profile.email_notifications_enabled = False tester.profile.save() tester_domain.expiry_date = timezone.now() + datetime.timedelta( days=15) # expiry_date 15 days from now tester_domain.status = 'active' tester_domain.save() outgoing_emails = check_notify_domain_expiring( dry_run=False, min_days_before_expire=0, max_days_before_expire=30, subject='domain_expire_soon', ) assert len(outgoing_emails) == 0