mirror of
https://github.com/planetmint/planetmint.git
synced 2025-11-24 22:45:44 +00:00
fixed mock on test case
Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com>
This commit is contained in:
parent
33a1cbb548
commit
48f5133a9d
@ -14,6 +14,7 @@ from ipld import multihash, marshal
|
|||||||
from hashlib import sha3_256
|
from hashlib import sha3_256
|
||||||
|
|
||||||
from transactions.common import crypto
|
from transactions.common import crypto
|
||||||
|
from transactions.common.transaction import Transaction
|
||||||
from transactions.types.assets.create import Create
|
from transactions.types.assets.create import Create
|
||||||
from transactions.types.assets.transfer import Transfer
|
from transactions.types.assets.transfer import Transfer
|
||||||
from transactions.common.transaction_mode_types import (
|
from transactions.common.transaction_mode_types import (
|
||||||
@ -298,7 +299,6 @@ def test_post_invalid_transaction(
|
|||||||
client,
|
client,
|
||||||
exc,
|
exc,
|
||||||
msg,
|
msg,
|
||||||
monkeypatch,
|
|
||||||
):
|
):
|
||||||
from transactions.common import exceptions
|
from transactions.common import exceptions
|
||||||
|
|
||||||
@ -307,28 +307,23 @@ def test_post_invalid_transaction(
|
|||||||
def mock_validation(self_, tx, skip_schema_validation=True):
|
def mock_validation(self_, tx, skip_schema_validation=True):
|
||||||
raise exc_cls(msg)
|
raise exc_cls(msg)
|
||||||
|
|
||||||
TransactionMock = Mock(validate=mock_validation)
|
with patch.object(Transaction, "from_dict", mock_validation):
|
||||||
|
res = client.post(TX_ENDPOINT, data=json.dumps({}))
|
||||||
monkeypatch.setattr(
|
expected_status_code = 400
|
||||||
"transactions.common.transaction.Transaction.from_dict",
|
expected_error_message = "Invalid transaction ({}): {}".format(exc, msg)
|
||||||
lambda tx, skip_schema_validation: TransactionMock,
|
assert res.status_code == expected_status_code
|
||||||
)
|
assert res.json["message"] == "Invalid transaction ({}): {}".format(exc, msg)
|
||||||
res = client.post(TX_ENDPOINT, data=json.dumps({}))
|
assert mock_logger.error.called
|
||||||
expected_status_code = 400
|
assert "HTTP API error: %(status)s - %(method)s:%(path)s - %(message)s" in mock_logger.error.call_args[0]
|
||||||
expected_error_message = "Invalid transaction ({}): {}".format(exc, msg)
|
assert {
|
||||||
assert res.status_code == expected_status_code
|
"message": expected_error_message,
|
||||||
assert res.json["message"] == "Invalid transaction ({}): {}".format(exc, msg)
|
"status": expected_status_code,
|
||||||
assert mock_logger.error.called
|
"method": "POST",
|
||||||
assert "HTTP API error: %(status)s - %(method)s:%(path)s - %(message)s" in mock_logger.error.call_args[0]
|
"path": TX_ENDPOINT,
|
||||||
assert {
|
} in mock_logger.error.call_args[0]
|
||||||
"message": expected_error_message,
|
# TODO put back caplog based asserts once possible
|
||||||
"status": expected_status_code,
|
# assert caplog.records[2].args['status'] == expected_status_code
|
||||||
"method": "POST",
|
# assert caplog.records[2].args['message'] == expected_error_message
|
||||||
"path": TX_ENDPOINT,
|
|
||||||
} in mock_logger.error.call_args[0]
|
|
||||||
# TODO put back caplog based asserts once possible
|
|
||||||
# assert caplog.records[2].args['status'] == expected_status_code
|
|
||||||
# assert caplog.records[2].args['message'] == expected_error_message
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.abci
|
@pytest.mark.abci
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user