Skip to content
Snippets Groups Projects
Commit d362f165 authored by Moul's avatar Moul
Browse files

[test] #396: Refactor test_generate_and_send_transaction()

By checking send_document() is called
Remove exit check
parent 56258c93
No related branches found
No related tags found
No related merge requests found
......@@ -1093,7 +1093,7 @@ def test_send_transaction(
@pytest.mark.parametrize(
"key, issuers, tx_amounts, listinput_and_amount, outputAddresses, Comment, OutputbackChange, client_return",
"key, issuers, tx_amounts, listinput_and_amount, outputAddresses, Comment, OutputbackChange",
[
# right tx : 1 amount for 1 receiver
(
......@@ -1132,7 +1132,6 @@ def test_send_transaction(
("DBM6F5ChMJzpmkUdL5zD9UXKExmZGfQ1AgPDQy4MxSBw",),
"",
None,
True,
),
# right tx : 2 amounts for 2 receivers
(
......@@ -1175,7 +1174,6 @@ def test_send_transaction(
),
"Test comment",
None,
True,
),
# Wrong tx : 3 amounts for 1 receiver
(
......@@ -1216,7 +1214,6 @@ def test_send_transaction(
("DBM6F5ChMJzpmkUdL5zD9UXKExmZGfQ1AgPDQy4MxSBw",),
"",
"DBM6F5ChMJzpmkUdL5zD9UXKExmZGfQ1AgPDQy4MxSBw",
False,
),
],
)
......@@ -1228,11 +1225,11 @@ def test_generate_and_send_transaction(
outputAddresses,
Comment,
OutputbackChange,
client_return,
monkeypatch,
capsys,
):
"""
# create FakeReturn and patched_ClientInstance classes to patch ClientInstance() class
class FakeReturn:
def __init__(self):
......@@ -1247,16 +1244,16 @@ def test_generate_and_send_transaction(
class patched_ClientInstance:
def __init__(self):
self.client = FakeReturn()
"""
# mock functions
tx.generate_transaction_document = Mock()
network_tools.send_document = Mock()
# patched functions
monkeypatch.setattr(blockchain_tools.HeadBlock, "get_head", patched_head_block)
monkeypatch.setattr(network_tools, "ClientInstance", patched_ClientInstance)
# monkeypatch.setattr(network_tools, "ClientInstance", patched_ClientInstance)
# write the test function
def function_testing():
tx.generate_and_send_transaction(
key,
issuers,
......@@ -1266,8 +1263,6 @@ def test_generate_and_send_transaction(
Comment,
OutputbackChange,
)
if client_return != 200:
assert pytest.raises(SystemExit).type == SystemExit
display = capsys.readouterr().out
if listinput_and_amount[2]:
......@@ -1277,9 +1272,7 @@ def test_generate_and_send_transaction(
assert display.find(" - From: {0}".format(issuers)) != -1
for tx_amount, outputAddress in zip(tx_amounts, outputAddresses):
assert display.find(
" - To: {0}\n - Amount: {1}".format(
outputAddress, tx_amount / 100
)
" - To: {0}\n - Amount: {1}".format(outputAddress, tx_amount / 100)
)
tx.generate_transaction_document.assert_called_once_with(
......@@ -1290,19 +1283,7 @@ def test_generate_and_send_transaction(
Comment,
OutputbackChange,
)
if client_return == 200:
assert display.find("Transaction successfully sent.") != -1
else:
assert display.find("Error while publishing transaction:") != -1
### test function and catch SystemExit if needed ###
if client_return == 200:
function_testing()
else:
with pytest.raises(SystemExit) as pytest_exit:
function_testing()
assert pytest_exit.type == SystemExit
network_tools.send_document.assert_called_once()
# test check_transaction_values()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment