Ejemplo n.º 1
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
Ejemplo n.º 2
0
 def test_order_failed_to_incomplete(self):
     time_now = datetime.datetime.now()
     testsupport.prepare_tester_order(domain_name='test.ai',
                                      order_type='domain_renew',
                                      status='failed',
                                      item_status='executing',
                                      started_at=time_now -
                                      datetime.timedelta(minutes=20))
     assert Order.orders.first().status == 'failed'
     tasks.retry_failed_orders()
     assert Order.orders.first().status == 'incomplete'
Ejemplo n.º 3
0
    def test_remove_started_orders_older_than_1_day(self, mock_log_debug):
        time_now = datetime.datetime.now()
        testsupport.prepare_tester_order(domain_name='test.ai',
                                         status='started',
                                         started_at=time_now -
                                         datetime.timedelta(days=2))
        assert Order.orders.all().count() == 1

        tasks.remove_started_orders(1)
        assert Order.orders.all().count() == 0
        mock_log_debug.assert_called_once()
Ejemplo n.º 4
0
 def test_order_created_recently(self):
     time_now = datetime.datetime.now()
     testsupport.prepare_tester_order(domain_name='test.ai',
                                      order_type='domain_register',
                                      status='failed',
                                      item_status='failed',
                                      started_at=time_now -
                                      datetime.timedelta(minutes=4))
     assert Order.orders.first().status == 'failed'
     tasks.retry_failed_orders()
     assert Order.orders.first().status == 'failed'
Ejemplo n.º 5
0
    def test_financial_result_for_specific_month_successful(self):
        testsupport.prepare_tester_order(domain_name='test.ai',
                                         status='processed',
                                         finished_at=datetime.datetime(
                                             2019, 1, 1, 1, 0, 0),
                                         owner=self.account)
        response = self.client.post('/board/financial-report/',
                                    data=dict(year=2019, month=1))

        assert response.status_code == 200
        assert response.context['total_payment_by_users'] == 100.0
        assert response.context['total_registered_users'] == 1
        assert len(response.context['object_list']) == 1
Ejemplo n.º 6
0
    def test_financial_result_access_denied_for_normal_user(
            self, mock_messages_error):
        self.account.is_staff = False
        self.account.save()
        testsupport.prepare_tester_order(domain_name='test3.ai',
                                         status='processed',
                                         finished_at=datetime.datetime(
                                             2019, 1, 1, 1, 0, 0),
                                         owner=self.account)

        response = self.client.post('/board/financial-report/',
                                    data=dict(year=2019))

        assert response.status_code == 302
        assert response.url == '/'
        mock_messages_error.assert_called_once()
Ejemplo n.º 7
0
    def test_cancel_order_for_non_existing_domain(self):
        order = testsupport.prepare_tester_order(domain_name='test.ai')
        assert Order.orders.all().count() == 1
        assert Domain.domains.all().count() == 0

        self.client.post(f'/billing/order/cancel/{order.id}/')
        assert Order.orders.all().count() == 0
        assert Domain.domains.all().count() == 0