Skip to content
Snippets Groups Projects
Commit 486b5e1c authored by matograine's avatar matograine
Browse files

[test] #282 split patched.py

* create patched directory
* create files matching the silkaj modules
* delete patched.py
* change calls in the tests
parent 5511abd3
No related branches found
No related tags found
No related merge requests found
# This file contains patched functions for testing purposes.
from silkaj.constants import G1_SYMBOL
from silkaj.money import amount_in_current_base
from duniterpy.documents.transaction import InputSource
......@@ -16,42 +13,14 @@ pubkey_list = [
{"pubkey": "7Hr6oUxE6nGZxFG7gVbpMK6oUkNTh5eU686EiCXWCrBF", "uid": "loulou"},
]
#### Patched functions ####
## testing tx.py ##
# mock UDValue
async def ud_value(self):
async def patched_ud_value(self):
return mock_ud_value
# mock is_member
async def is_member(pubkey):
for account in pubkey_list:
if account["pubkey"] == pubkey:
if account["uid"]:
return account
return False
# mock CurrencySymbol().symbol
async def currency_symbol(self):
return G1_SYMBOL
## mock head_block()
async def head_block(self):
mocked_head_block = {
"number": 48000,
"unitbase": 0,
"currency": "g1",
"hash": "0000010D30B1284D34123E036B7BE0A449AE9F2B928A77D7D20E3BDEAC7EE14C",
}
return mocked_head_block
# mock get_sources()
async def get_sources(pubkey):
async def patched_get_sources(pubkey):
"""
Returns transaction sources.
This function does not cover all possibilities : no other unlock conditions than SIG(pubkey).
......
## mock head_block()
async def patched_head_block(self):
mocked_head_block = {
"number": 48000,
"unitbase": 0,
"currency": "g1",
"hash": "0000010D30B1284D34123E036B7BE0A449AE9F2B928A77D7D20E3BDEAC7EE14C",
}
return mocked_head_block
from silkaj.constants import G1_SYMBOL
# mock CurrencySymbol().symbol
async def patched_currency_symbol(self):
return G1_SYMBOL
pubkey_list = [
{"pubkey": "DBM6F5ChMJzpmkUdL5zD9UXKExmZGfQ1AgPDQy4MxSBw", "uid": ""},
{"pubkey": "4szFkvQ5tzzhwcfUtZD32hdoG2ZzhvG3ZtfR61yjnxdw", "uid": ""},
{"pubkey": "BFb5yv8z1fowR6Z8mBXTALy5z7gHfMU976WtXhmRsUMh", "uid": "riri"},
{"pubkey": "C1oAV9FX2y9iz2sdp7kZBFu3EBNAa6UkrrRG3EwouPeH", "uid": "fifi"},
{"pubkey": "7Hr6oUxE6nGZxFG7gVbpMK6oUkNTh5eU686EiCXWCrBF", "uid": "loulou"},
]
# mock is_member
async def patched_is_member(pubkey):
for account in pubkey_list:
if account["pubkey"] == pubkey:
if account["uid"]:
return account
return False
......@@ -2,7 +2,8 @@ import pytest
from silkaj.tui import display_pubkey, display_amount
from silkaj.constants import G1_SYMBOL
import patched
from patched.wot import patched_is_member
from patched.money import mock_ud_value
# display_amount()
......@@ -10,7 +11,7 @@ import patched
"message, amount, currency_symbol", [("Total", 1000, G1_SYMBOL)]
)
def test_display_amount(message, amount, currency_symbol, monkeypatch):
ud_value = patched.mock_ud_value
ud_value = mock_ud_value
amount_UD = round(amount / ud_value, 4)
expected = [
[
......@@ -39,7 +40,7 @@ def test_display_amount(message, amount, currency_symbol, monkeypatch):
)
@pytest.mark.asyncio
async def test_display_pubkey(message, pubkey, id, monkeypatch):
monkeypatch.setattr("silkaj.wot.is_member", patched.is_member)
monkeypatch.setattr("silkaj.wot.is_member", patched_is_member)
expected = [[message + " (pubkey)", pubkey]]
if id:
......
......@@ -7,6 +7,7 @@ from silkaj.tx import (
generate_transaction_document,
get_list_input_for_transaction,
)
from silkaj.tui import display_amount, display_pubkey
from silkaj.money import UDValue
from silkaj.constants import G1_SYMBOL, CENT_MULT_TO_UNIT, MINIMAL_TX_AMOUNT
from duniterpy.documents.transaction import (
......@@ -18,7 +19,10 @@ from duniterpy.documents.transaction import (
)
from duniterpy.documents.block_uid import BlockUID
import patched
from patched.wot import patched_is_member
from patched.money import patched_get_sources, patched_ud_value, mock_ud_value
from patched.tools import patched_currency_symbol
from patched.network_tools import patched_head_block
# truncBase()
......@@ -94,14 +98,14 @@ async def test_transaction_confirmation(
monkeypatch,
):
# patched functions
monkeypatch.setattr("silkaj.wot.is_member", patched.is_member)
monkeypatch.setattr("silkaj.money.UDValue.get_ud_value", patched.ud_value)
monkeypatch.setattr("silkaj.wot.is_member", patched_is_member)
monkeypatch.setattr("silkaj.money.UDValue.get_ud_value", patched_ud_value)
monkeypatch.setattr(
"silkaj.tools.CurrencySymbol.get_symbol", patched.currency_symbol
"silkaj.tools.CurrencySymbol.get_symbol", patched_currency_symbol
)
# creating expected list
ud_value = await UDValue().ud_value
ud_value = mock_ud_value
expected = list()
total_tx_amount = sum(tx_amounts)
# display account situation
......@@ -254,8 +258,8 @@ async def test_transaction_amount(
amounts, amountUDs, outputAddresses, expected, capsys, monkeypatch
):
# patched functions
monkeypatch.setattr("silkaj.money.UDValue.get_ud_value", patched.ud_value)
udvalue = patched.mock_ud_value
monkeypatch.setattr("silkaj.money.UDValue.get_ud_value", patched_ud_value)
udvalue = mock_ud_value
def too_little_amount(amounts, multiplicator):
for amount in amounts:
......@@ -388,7 +392,7 @@ async def test_generate_transaction_document(
monkeypatch,
):
# patch Head_block
monkeypatch.setattr("silkaj.network_tools.HeadBlock.get_head", patched.head_block)
monkeypatch.setattr("silkaj.network_tools.HeadBlock.get_head", patched_head_block)
assert result == await generate_transaction_document(
issuers,
......@@ -434,7 +438,7 @@ async def test_get_list_input_for_transaction(
"""
# patched functions
monkeypatch.setattr("silkaj.money.get_sources", patched.get_sources)
monkeypatch.setattr("silkaj.money.get_sources", patched_get_sources)
# testing error exit
if isinstance(expected, str):
with pytest.raises(SystemExit) as pytest_exit:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment