Skip to content
Snippets Groups Projects
Commit 9323f9d1 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
Delete patched_ClientInstance() which won't be used in the future
parent 31f7dfd4
No related branches found
No related tags found
No related merge requests found
...@@ -1094,7 +1094,7 @@ def test_send_transaction( ...@@ -1094,7 +1094,7 @@ def test_send_transaction(
@pytest.mark.parametrize( @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 # right tx : 1 amount for 1 receiver
( (
...@@ -1133,7 +1133,6 @@ def test_send_transaction( ...@@ -1133,7 +1133,6 @@ def test_send_transaction(
("DBM6F5ChMJzpmkUdL5zD9UXKExmZGfQ1AgPDQy4MxSBw",), ("DBM6F5ChMJzpmkUdL5zD9UXKExmZGfQ1AgPDQy4MxSBw",),
"", "",
None, None,
True,
), ),
# right tx : 2 amounts for 2 receivers # right tx : 2 amounts for 2 receivers
( (
...@@ -1176,7 +1175,6 @@ def test_send_transaction( ...@@ -1176,7 +1175,6 @@ def test_send_transaction(
), ),
"Test comment", "Test comment",
None, None,
True,
), ),
# Wrong tx : 3 amounts for 1 receiver # Wrong tx : 3 amounts for 1 receiver
( (
...@@ -1217,7 +1215,6 @@ def test_send_transaction( ...@@ -1217,7 +1215,6 @@ def test_send_transaction(
("DBM6F5ChMJzpmkUdL5zD9UXKExmZGfQ1AgPDQy4MxSBw",), ("DBM6F5ChMJzpmkUdL5zD9UXKExmZGfQ1AgPDQy4MxSBw",),
"", "",
"DBM6F5ChMJzpmkUdL5zD9UXKExmZGfQ1AgPDQy4MxSBw", "DBM6F5ChMJzpmkUdL5zD9UXKExmZGfQ1AgPDQy4MxSBw",
False,
), ),
], ],
) )
...@@ -1229,35 +1226,17 @@ def test_generate_and_send_transaction( ...@@ -1229,35 +1226,17 @@ def test_generate_and_send_transaction(
outputAddresses, outputAddresses,
Comment, Comment,
OutputbackChange, OutputbackChange,
client_return,
monkeypatch, monkeypatch,
capsys, capsys,
): ):
# create FakeReturn and patched_ClientInstance classes to patch ClientInstance() class
class FakeReturn:
def __init__(self):
self.status = client_return
def __call__(self, *args, **kwargs):
return self
def text(self):
return "Tests for Silkaj : Fake Return !"
class patched_ClientInstance:
def __init__(self):
self.client = FakeReturn()
# mock functions # mock functions
tx.generate_transaction_document = Mock() tx.generate_transaction_document = Mock()
network_tools.send_document = Mock()
# patched functions # patched functions
monkeypatch.setattr(blockchain_tools.HeadBlock, "get_head", patched_head_block) 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( tx.generate_and_send_transaction(
key, key,
issuers, issuers,
...@@ -1267,8 +1246,6 @@ def test_generate_and_send_transaction( ...@@ -1267,8 +1246,6 @@ def test_generate_and_send_transaction(
Comment, Comment,
OutputbackChange, OutputbackChange,
) )
if client_return != 200:
assert pytest.raises(SystemExit).type == SystemExit
display = capsys.readouterr().out display = capsys.readouterr().out
if listinput_and_amount[2]: if listinput_and_amount[2]:
...@@ -1278,9 +1255,7 @@ def test_generate_and_send_transaction( ...@@ -1278,9 +1255,7 @@ def test_generate_and_send_transaction(
assert display.find(" - From: {0}".format(issuers)) != -1 assert display.find(" - From: {0}".format(issuers)) != -1
for tx_amount, outputAddress in zip(tx_amounts, outputAddresses): for tx_amount, outputAddress in zip(tx_amounts, outputAddresses):
assert display.find( assert display.find(
" - To: {0}\n - Amount: {1}".format( " - To: {0}\n - Amount: {1}".format(outputAddress, tx_amount / 100)
outputAddress, tx_amount / 100
)
) )
tx.generate_transaction_document.assert_called_once_with( tx.generate_transaction_document.assert_called_once_with(
...@@ -1291,19 +1266,7 @@ def test_generate_and_send_transaction( ...@@ -1291,19 +1266,7 @@ def test_generate_and_send_transaction(
Comment, Comment,
OutputbackChange, OutputbackChange,
) )
network_tools.send_document.assert_called_once()
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
# test check_transaction_values() # 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