Created
February 6, 2022 00:12
-
-
Save arhyth/3357ba149d47395d771a5e8a989aa292 to your computer and use it in GitHub Desktop.
Debug assertion failure
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
=============================================================================================== FAILURES =============================================================================================== | |
______________________________________________________________________________________ test_validate_cash_in_txn _______________________________________________________________________________________ | |
validate_route_usage_mock = <MagicMock name='validate_route_usage' id='275037264240'>, cancel_mock = <MagicMock name='cancel_cash_in_txn' id='275035140048'> | |
@patch('foobar.apps.transactionx.tasks.inward.cancel_cash_in_txn') | |
@patch('foobar.apps.transactionx.tasks.inward.validate_route_usage') | |
def test_validate_cash_in_txn(validate_route_usage_mock, cancel_mock): | |
with freeze_time('2019-10-10T10:00:00'): | |
routed_txn = CashInTransactionFactory( | |
route_id='888', | |
status=CashInTransaction.STATUS.routed, | |
) | |
with freeze_time('2019-10-10T10:06:00'): | |
validate_cash_in_txn.delay(str(routed_txn.pk),) | |
validate_route_usage_mock.side_effect = InvalidRequestError('http_msg', 'http_content', 400) | |
> validate_route_usage_mock.assert_called_with(ANY, ANY, ANY, ANY) | |
tests/medium/transactionx/tasks/test_inward.py:1094: | |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
self = <MagicMock name='validate_route_usage' id='275037264240'>, args = (<ANY>, <ANY>, <ANY>, <ANY>), kwargs = {}, expected = call(<ANY>, <ANY>, <ANY>, <ANY>) | |
actual = call('888', Decimal('100.000000000000000000'), '2746', outlet_id='paypal'), _error_message = <function NonCallableMock.assert_called_with.<locals>._error_message at 0x400993a0d0> | |
cause = None | |
def assert_called_with(self, /, *args, **kwargs): | |
"""assert that the last call was made with the specified arguments. | |
Raises an AssertionError if the args and keyword args passed in are | |
different to the last call to the mock.""" | |
if self.call_args is None: | |
expected = self._format_mock_call_signature(args, kwargs) | |
actual = 'not called.' | |
error_message = ('expected call not found.\nExpected: %s\nActual: %s' | |
% (expected, actual)) | |
raise AssertionError(error_message) | |
def _error_message(): | |
msg = self._format_mock_failure_message(args, kwargs) | |
return msg | |
expected = self._call_matcher(_Call((args, kwargs), two=True)) | |
actual = self._call_matcher(self.call_args) | |
if actual != expected: | |
cause = expected if isinstance(expected, Exception) else None | |
> raise AssertionError(_error_message()) from cause | |
E AssertionError: expected call not found. | |
E Expected: validate_route_usage(<ANY>, <ANY>, <ANY>, <ANY>) | |
E Actual: validate_route_usage('888', Decimal('100.000000000000000000'), '2746', outlet_id='paypal') | |
/usr/local/lib/python3.9/unittest/mock.py:907: AssertionError | |
----------------------------------------------------------------------------------------- Captured stdout call ----------------------------------------------------------------------------------------- | |
calling `validate_route_usage`... | |
----------------------------------------------------------------------------------------- Captured stderr call ----------------------------------------------------------------------------------------- | |
2019-10-10 10:06:00,000 [E/MainProcess] celery.app.trace: Task foobar.apps.transactionx.tasks.inward.validate_cash_in_txn[68e4f771-e0e8-49a3-9f23-5a9819a95ab5] raised unexpected: TypeError("'NoneType' object is not callable") | |
Traceback (most recent call last): | |
File "/usr/local/lib/python3.9/site-packages/celery/app/trace.py", line 451, in trace_task | |
R = retval = fun(*args, **kwargs) | |
File "/usr/local/lib/python3.9/contextlib.py", line 79, in inner | |
return func(*args, **kwds) | |
File "/app/foobar/apps/transactionx/tasks/inward.py", line 580, in validate_cash_in_txn | |
txn.bump_validation_attempt_count() | |
TypeError: 'NoneType' object is not callable | |
2019-10-10 10:06:00,000 [E] celery.app.trace: Task foobar.apps.transactionx.tasks.inward.validate_cash_in_txn[68e4f771-e0e8-49a3-9f23-5a9819a95ab5] raised unexpected: TypeError("'NoneType' object is not callable") | |
Traceback (most recent call last): | |
File "/usr/local/lib/python3.9/site-packages/celery/app/trace.py", line 451, in trace_task | |
R = retval = fun(*args, **kwargs) | |
File "/usr/local/lib/python3.9/contextlib.py", line 79, in inner | |
return func(*args, **kwds) | |
File "/app/foobar/apps/transactionx/tasks/inward.py", line 580, in validate_cash_in_txn | |
txn.bump_validation_attempt_count() | |
TypeError: 'NoneType' object is not callable | |
------------------------------------------------------------------------------------------ Captured log call ------------------------------------------------------------------------------------------- | |
ERROR celery.app.trace:trace.py:265 Task foobar.apps.transactionx.tasks.inward.validate_cash_in_txn[68e4f771-e0e8-49a3-9f23-5a9819a95ab5] raised unexpected: TypeError("'NoneType' object is not callable") | |
Traceback (most recent call last): | |
File "/usr/local/lib/python3.9/site-packages/celery/app/trace.py", line 451, in trace_task | |
R = retval = fun(*args, **kwargs) | |
File "/usr/local/lib/python3.9/contextlib.py", line 79, in inner | |
return func(*args, **kwds) | |
File "/app/foobar/apps/transactionx/tasks/inward.py", line 580, in validate_cash_in_txn | |
txn.bump_validation_attempt_count() | |
TypeError: 'NoneType' object is not callable |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@app.task | |
@atomic | |
def validate_cash_in_txn(cash_in_txn_id: str) -> None: | |
txn = CITxn.objects \ | |
.select_for_update() \ | |
.get(pk=cash_in_txn_id) | |
if txn.status != CITxn.STATUS.routed: | |
return | |
try: | |
print("calling `validate_route_usage`...") | |
validate_route_usage( | |
txn.foo_id, | |
txn.amt, | |
txn.bar_reference_number, | |
outlet_id=txn.outlet_id, | |
) | |
except (APIError, APIConnectionError, AuthError): | |
logger.exception(f'Validation for txn {cash_in_txn_id} delayed.') | |
return | |
except InvalidRequestError as exc: | |
logger.exception(f'Cannot validate cash in txn {cash_in_txn_id}') | |
reason = txn.error_to_reject_reason( | |
exc.error_code, | |
CITxn.REJECT_REASON.validation_failed, | |
) | |
txn.mark_for_rejection(reason=reason) | |
txn.bump_validation_attempt_count() | |
print(f'saving txn {cash_in_txn_id} ...') | |
txn.save() | |
on_commit( | |
lambda: cancel_cash_in_txn.delay(txn.pk), | |
) | |
return | |
txn.mark_as_validated() | |
txn.bump_validation_attempt_count() | |
txn.save() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from unittest.mock import ( | |
AsyncMock, | |
patch, | |
ANY, | |
) | |
<... other file contents removed> | |
@patch('foobar.apps.transactions.tasks.inward.cancel_cash_in_txn') | |
@patch('foobar.apps.transactions.tasks.inward.validate_route_usage') | |
def test_validate_cash_in_txn(validate_route_usage_mock, cancel_mock): | |
with freeze_time('2019-10-10T10:00:00'): | |
routed_txn = CashInTransactionFactory( | |
route_id='888', | |
status=CashInTransaction.STATUS.routed, | |
) | |
with freeze_time('2019-10-10T10:06:00'): | |
validate_cash_in_txn.delay(str(routed_txn.pk),) | |
validate_route_usage_mock.side_effect = InvalidRequestError('http_msg', 'http_content', 400) | |
validate_route_usage_mock.assert_called_with(ANY, ANY, ANY, ANY) | |
cancel_mock.assert_called_with(ANY) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment