def test_atol_create_receipt_stopped_on_unrecoverable_error(celery_worker): responses.add(responses.POST, ATOL_BASE_URL + '/getToken', status=200, json={ 'code': 0, 'token': 'foobar' }) responses.add(responses.POST, ATOL_BASE_URL + '/ATOL-ProdTest-1/sell', status=400, json={'error': { 'code': 3 }}) receipt = Receipt.objects.create(user_email='*****@*****.**', purchase_price=999) with mock.patch.object(atol_create_receipt, 'retry', wraps=atol_create_receipt.retry) as task_mock: atol_create_receipt.delay(receipt.id) assert len(task_mock.mock_calls) == 0 receipt.refresh_from_db() assert receipt.status == 'failed'
def test_atol_create_failing_receipt_progressive_countdown(celery_worker): responses.add(responses.POST, ATOL_BASE_URL + '/getToken', status=200, json={ 'code': 0, 'token': 'foobar' }) responses.add(responses.POST, ATOL_BASE_URL + '/ATOL-ProdTest-1/sell', status=500) receipt = Receipt.objects.create(user_email='*****@*****.**', purchase_price=999) with mock.patch.object(atol_create_receipt, 'retry', wraps=atol_create_receipt.retry) as task_mock: atol_create_receipt.delay(receipt.id) assert len(task_mock.mock_calls) == 5 assert [call[1]['countdown'] for call in task_mock.call_args_list ] == [60, 120, 420, 1200, 3240] receipt.refresh_from_db() assert receipt.status == 'failed'
def test_atol_create_receipt_check_receipt_status(celery_worker): receipt = Receipt.objects.create(status='failed') with mock.patch.object(AtolAPI, 'sell', wraps=AtolAPI.sell) as sell_mock: atol_create_receipt.delay(receipt.id) assert len(sell_mock.mock_calls) == 0