Exemple #1
0
 def test_change_owner_and_registrants(self):
     tester1 = testsupport.prepare_tester_account(email='*****@*****.**')
     tester2 = testsupport.prepare_tester_account(email='*****@*****.**')
     tester_domain = testsupport.prepare_tester_domain(domain_name='abc.ai', tester=tester1)
     assert tester_domain.owner == tester1
     assert tester_domain.registrant.owner == tester1
     tester_domain = zdomains.domain_change_owner(domain_object=tester_domain, new_owner=tester2, also_registrants=True, save=True)
     tester_domain.refresh_from_db()
     assert tester_domain.owner == tester2
     assert tester_domain.registrant.owner == tester2
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
Exemple #3
0
 def test_order_incomplete_failed_retried(
         self, mock_domain_check_create_update_renew,
         mock_domain_synchronize_from_backend):
     time_now = datetime.datetime.now()
     tester = testsupport.prepare_tester_account(account_balance=200)
     testsupport.prepare_tester_domain(
         domain_name='test.ai',
         tester=tester,
         domain_status='active',
     )
     testsupport.prepare_tester_order(domain_name='test.ai',
                                      order_type='domain_renew',
                                      status='incomplete',
                                      item_status='failed',
                                      started_at=time_now -
                                      datetime.timedelta(minutes=20))
     assert Order.orders.first().status == 'incomplete'
     assert OrderItem.order_items.first().status == 'failed'
     mock_domain_check_create_update_renew.return_value = True
     mock_domain_synchronize_from_backend.return_value = True
     tasks.retry_failed_orders()
     assert Order.orders.first().status == 'processed'
     assert OrderItem.order_items.first().status == 'processed'
     mock_domain_check_create_update_renew.assert_called_once()
     tester.refresh_from_db()
     assert tester.balance == 100
Exemple #4
0
 def test_order_created_executed_email_sent(self, mock_send, mock_domain_check_create_update_renew, mock_domain_synchronize_from_backend):
     mock_send.return_value = True
     mock_domain_check_create_update_renew.return_value = True
     mock_domain_synchronize_from_backend.return_value = True
     tester = testsupport.prepare_tester_account(account_balance=1000.0)
     tester_domain = testsupport.prepare_tester_domain(
         domain_name='abcd.ai',
         tester=tester,
         domain_epp_id='aaa123',
         domain_status='active',
         expiry_date=timezone.now() + datetime.timedelta(days=89),  # will expire in 89 days
         auto_renew_enabled=True,
     )
     report = tasks.auto_renew_expiring_domains(dry_run=False)
     assert len(report) == 1
     assert report[0][0] == tester_domain.name
     tester.refresh_from_db()
     assert tester.balance == 1000.0 - settings.ZENAIDA_DOMAIN_PRICE
     process_notifications_queue(iterations=1, delay=0.1, iteration_delay=0.1)
     new_notification = Notification.notifications.first()
     assert new_notification.domain_name == 'abcd.ai'
     assert new_notification.status == 'sent'
     assert new_notification.subject == 'domain_renewed'
     tester_orders = orders.list_orders(owner=tester)
     assert tester_orders[0].description == 'abcd.ai renew (automatically)'
Exemple #5
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 test_execute_email_notification_failed(mock_send):
    tester = testsupport.prepare_tester_account()
    new_notification = notifications.start_email_notification_domain_expiring(
        user=tester,
        domain_name='abcd.ai',
        expiry_date='2020-01-01',
    )
    mock_send.side_effect = Exception('some error while sending')
    assert notifications.execute_email_notification(new_notification) is False
def test_execute_email_notification_success(mock_send):
    tester = testsupport.prepare_tester_account()
    new_notification = notifications.start_email_notification_domain_expiring(
        user=tester,
        domain_name='abcd.ai',
        expiry_date='2020-01-01',
    )
    mock_send.return_value = True
    assert notifications.execute_email_notification(new_notification) is True
Exemple #8
0
 def test_glue_record_not_supported(self, mock_messages_error):
     tester = prepare_tester_account()
     contact_admin = prepare_tester_contact(tester=tester)
     profile = prepare_tester_profile(tester=tester)
     prepare_tester_registrant(tester=tester, profile_object=profile)
     response = self.client.post('/domains/create/test.ai/',
                                 data=dict(nameserver1='ns1.test.ai',
                                           contact_admin=contact_admin.id))
     assert response.status_code == 302
     mock_messages_error.assert_called_once()
def test_process_notifications_queue_with_success(mock_send):
    tester = testsupport.prepare_tester_account()
    new_notification = notifications.start_email_notification_domain_expiring(
        user=tester,
        domain_name='abcd.ai',
        expiry_date='2020-01-01',
    )
    mock_send.return_value = True
    notifications.process_notifications_queue(iterations=1, delay=0.1)
    new_notification.refresh_from_db()
    assert new_notification.status == 'sent'
def test_process_notifications_queue_with_failed(mock_send):
    tester = testsupport.prepare_tester_account()
    new_notification = notifications.start_email_notification_domain_expiring(
        user=tester,
        domain_name='abcd.ai',
        expiry_date='2020-01-01',
    )
    mock_send.side_effect = Exception('some error while sending')
    notifications.process_notifications_queue(iterations=1, delay=0.1)
    new_notification.refresh_from_db()
    assert new_notification.status == 'failed'
Exemple #11
0
 def test_auto_renew_not_started_after_60(self):
     tester = testsupport.prepare_tester_account(account_balance=200.0)
     testsupport.prepare_tester_domain(
         domain_name='abcd.ai',
         tester=tester,
         domain_epp_id='aaa123',
         domain_status='active',
         expiry_date=timezone.now() + datetime.timedelta(days=55),  # will expire in 55 days
         auto_renew_enabled=True,
     )
     report = tasks.auto_renew_expiring_domains(dry_run=True)
     assert len(report) == 0
Exemple #12
0
 def test_owner_profile_automatic_renewal_disabled(self):
     tester = testsupport.prepare_tester_account(account_balance=200.0, automatic_renewal_enabled=False)
     testsupport.prepare_tester_domain(
         domain_name='abcd.ai',
         tester=tester,
         domain_epp_id='aaa123',
         domain_status='active',
         expiry_date=timezone.now() + datetime.timedelta(days=89),  # will expire in 89 days
         auto_renew_enabled=True,
     )
     report = tasks.auto_renew_expiring_domains(dry_run=False)
     assert len(report) == 0
Exemple #13
0
 def test_skip_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=1)  # already expired a day ago
     tester_domain.status = 'inactive'
     tester_domain.save()
     report = tasks.sync_expired_domains(dry_run=False)
     assert len(report) == 0
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
Exemple #16
0
 def test_download_receipt_for_another_user(self, mock_messages_warning):
     test_account = testsupport.prepare_tester_account(
         email='*****@*****.**')
     order = Order.orders.create(
         owner=test_account,
         started_at=datetime.datetime(2019, 3, 23, 13, 34, 0),
         status='processed',
     )
     response = self.client.get(
         f'/billing/orders/receipts/download/{order.id}/')
     assert response.status_code == 302
     assert response.url == '/billing/orders/'
     mock_messages_warning.assert_called_once()
Exemple #17
0
def test_identify_domains_for_auto_renew_can_not_be_renewed():
    tester = testsupport.prepare_tester_account()
    tester_domain = testsupport.prepare_tester_domain(
        domain_name='abcd.ai',
        tester=tester,
        domain_status='inactive',
        auto_renew_enabled=True,
    )
    tester_domain.expiry_date = timezone.now() + datetime.timedelta(
        days=45)  # expiry_date 45 days from now
    tester_domain.status = 'active'
    tester_domain.save()
    domains_to_renew = tasks.identify_domains_for_auto_renew()
    assert domains_to_renew == {}
Exemple #18
0
 def test_ok(self, mock_domain_synchronize_from_backend):
     mock_domain_synchronize_from_backend.return_value = ['ok', ]
     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=1)  # already expired a day ago
     tester_domain.status = 'active'
     tester_domain.save()
     report = tasks.sync_expired_domains(dry_run=False)
     assert len(report) == 1
     assert report[0] == (tester_domain, ['ok', ], )
Exemple #19
0
 def test_balance_not_enough(self):
     tester = testsupport.prepare_tester_account(account_balance=50.0)
     tester_domain = testsupport.prepare_tester_domain(
         domain_name='abcd.ai',
         tester=tester,
         domain_epp_id='aaa123',
         domain_status='active',
         expiry_date=timezone.now() + datetime.timedelta(days=89),  # will expire in 89 days
         auto_renew_enabled=True,
     )
     report = tasks.auto_renew_expiring_domains(dry_run=False)
     assert len(report) == 1
     assert report[0][0] == tester_domain.name
     assert report[0][1] == tester.email
     assert report[0][2].args[0] == 'not enough funds'
Exemple #20
0
def test_get_oldest_registrant():
    tester = testsupport.prepare_tester_account()
    assert zcontacts.get_oldest_registrant(tester) is None
    first_registrant = testsupport.prepare_tester_registrant(tester, epp_id='id1', create_new=True)
    assert zcontacts.registrant_exists(epp_id='id1') is True
    assert zcontacts.registrant_exists(epp_id='id2') is False
    assert zcontacts.registrant_find(epp_id='id1') == first_registrant
    assert zcontacts.get_oldest_registrant(tester) == first_registrant
    second_registrant = testsupport.prepare_tester_registrant(tester, epp_id='id2', create_new=True)
    assert zcontacts.registrant_exists(epp_id='id2') is True
    assert zcontacts.registrant_find(epp_id='id2') != first_registrant
    assert zcontacts.registrant_find(epp_id='id2') == second_registrant
    assert zcontacts.get_oldest_registrant(tester) == first_registrant
    zcontacts.registrant_delete(epp_id='id1')
    assert zcontacts.get_oldest_registrant(tester) == second_registrant
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
Exemple #22
0
 def test_nameserver_is_not_available(self, mock_ping, mock_gethostbyname):
     mock_ping.return_value = -1
     mock_gethostbyname.side_effect = socket.error('failed')
     tester = prepare_tester_account()
     contact_admin = prepare_tester_contact(tester=tester)
     profile = prepare_tester_profile(tester=tester)
     prepare_tester_registrant(tester=tester, profile_object=profile)
     response = self.client.post('/domains/create/test.ai/',
                                 data=dict(nameserver1='dns1.kuwaitnet.net',
                                           contact_admin=contact_admin.id))
     assert response.status_code == 200
     assert response.context['errors'] == [
         'List of nameservers that are not valid or not reachable at this '
         'moment: <br>dns1.kuwaitnet.net <br>Please try again later or '
         'specify valid and available nameservers.'
     ]
Exemple #23
0
 def test_execute_order_failed(self, mock_execute_order):
     mock_execute_order.return_value = 'failed'
     tester = testsupport.prepare_tester_account(account_balance=200.0)
     tester_domain = testsupport.prepare_tester_domain(
         domain_name='abcd.ai',
         tester=tester,
         domain_epp_id='aaa123',
         domain_status='active',
         expiry_date=timezone.now() + datetime.timedelta(days=89),  # will expire in 89 days
         auto_renew_enabled=True,
     )
     report = tasks.auto_renew_expiring_domains(dry_run=False)
     assert len(report) == 1
     assert report[0][0] == tester_domain.name
     assert report[0][1] == tester.email
     assert report[0][2].args[0] == 'renew order status is failed'
def test_start_email_notification_domain_expiring():
    tester = testsupport.prepare_tester_account()
    new_notification = notifications.start_email_notification_domain_expiring(
        user=tester,
        domain_name='abcd.ai',
        expiry_date='2020-01-01',
    )
    assert new_notification.account == tester
    assert new_notification.recipient == '*****@*****.**'
    assert new_notification.status == 'started'
    assert new_notification.type == 'email'
    assert new_notification.subject == 'domain_expiring'
    assert new_notification.domain_name == 'abcd.ai'
    assert new_notification.details == {
        'expiry_date': '2020-01-01',
    }
Exemple #25
0
 def test_download_invoice_for_another_user(self, mock_messages_warning):
     test_account = testsupport.prepare_tester_account(
         email='*****@*****.**')
     payment = Payment.payments.create(
         owner=test_account,
         started_at=datetime.datetime(2019, 3, 23, 13, 34, 0),
         finished_at=datetime.datetime(2019, 3, 23, 13, 34, 5),
         transaction_id='abcd',
         amount=100.0,
         status='processed',
     )
     response = self.client.get(
         f'/billing/payment/invoice/download/{payment.transaction_id}/')
     assert response.status_code == 302
     assert response.url == '/billing/payments/'
     mock_messages_warning.assert_called_once()
Exemple #26
0
def test_contact_create():
    tester = testsupport.prepare_tester_account(email='*****@*****.**')
    tester_contact = zcontacts.contact_create(
        epp_id='abcd',
        owner=tester,
        person_name='Tester Tester',
        organization_name='TestingCorp',
        address_street='TestStreet',
        address_city='TestCity',
        address_province='TestProvince',
        address_postal_code='TestPostalCode',
        address_country='AI',
        contact_voice='1234567890',
        contact_fax='1234567890',
        contact_email='*****@*****.**',
    )
    assert tester_contact.owner.email == '*****@*****.**'
Exemple #27
0
def test_sync_expired_domains_dry_run():
    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=1)  # already expired a day ago
    tester_domain.status = 'active'
    tester_domain.save()
    report = tasks.sync_expired_domains(dry_run=True)
    assert len(report) == 1
    assert report[0] == (
        tester_domain,
        [],
    )
Exemple #28
0
def test_domain_update():
    if os.environ.get('E2E', '0') != '1':
        return pytest.skip('skip E2E')  # @UndefinedVariable
    tester = testsupport.prepare_tester_account()
    tester_domain = testsupport.prepare_tester_domain(
        domain_name='test.%s' % settings.ZENAIDA_SUPPORTED_ZONES[0],
        domain_epp_id=rpc_client.make_epp_id(tester.email),
        tester=tester,
    )
    scenario = []
    cs = domain_contacts_synchronizer.DomainContactsSynchronizer(
        update_domain=True,
        log_events=True,
        log_transitions=True,
        raise_errors=True,
    )
    cs.add_state_changed_callback(
        cb=lambda oldstate, newstate, event, *args, **kwargs: scenario.append((
            oldstate,
            newstate,
            event,
        )),
    )
    cs.event('run', target_domain=tester_domain)
    outputs = list(cs.outputs)
    del cs
    assert scenario == [
        ('AT_STARTUP', 'SYNC_CONTACTS', 'run'),
        ('SYNC_CONTACTS', 'DOMAIN_INFO?', 'all-contacts-in-sync'),
        ('DOMAIN_INFO?', 'DOMAIN_UPDATE', 'response'),
        ('DOMAIN_UPDATE', 'DONE', 'response'),
    ]
    assert len(outputs) == 5
    assert outputs[0][0] == 'admin'
    assert outputs[0][1]['epp']['response']['resData']['creData'][
        'id'] == tester_domain.contact_admin.epp_id
    assert outputs[1][0] == 'billing'
    assert outputs[1][1]['epp']['response']['resData']['creData'][
        'id'] == tester_domain.contact_billing.epp_id
    assert outputs[2][0] == 'registrant'
    assert outputs[2][1]['epp']['response']['resData']['creData'][
        'id'] == tester_domain.registrant.epp_id
    assert outputs[3][0] == 'tech'
    assert outputs[3][1]['epp']['response']['resData']['creData'][
        'id'] == tester_domain.contact_tech.epp_id
Exemple #29
0
 def test_owner_profile_email_notifications_disabled(self, mock_send, mock_domain_check_create_update_renew, mock_domain_synchronize_from_backend):
     mock_send.return_value = True
     mock_domain_check_create_update_renew.return_value = True
     mock_domain_synchronize_from_backend.return_value = True
     tester = testsupport.prepare_tester_account(account_balance=200.0, email_notifications_enabled=False)
     testsupport.prepare_tester_domain(
         domain_name='abcd.ai',
         tester=tester,
         domain_epp_id='aaa123',
         domain_status='active',
         expiry_date=timezone.now() + datetime.timedelta(days=89),  # will expire in 89 days
         auto_renew_enabled=True,
     )
     report = tasks.auto_renew_expiring_domains(dry_run=False)
     assert len(report) == 1
     assert report[0][0] == 'abcd.ai'
     assert report[0][1] == tester.email
     assert report[0][2].args[0] == 'email notifications are disabled'
Exemple #30
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