Refactor transactions into readable code

This commit is contained in:
2022-04-10 15:54:59 +01:00
parent 9151ab3ba6
commit b14a07b3b2
2 changed files with 177 additions and 85 deletions

View File

@@ -45,6 +45,7 @@ class TestTransactions(TestCase):
# Mock the rates
self.transactions.money = MagicMock()
self.transactions.money.to_usd = self.mock_to_usd
self.transactions.money.get_rates_all = MagicMock()
self.transactions.money.get_rates_all.return_value = {"GBP": 0.8}
@@ -119,6 +120,17 @@ class TestTransactions(TestCase):
if trade["id"] == string:
return trade["reference"]
def mock_to_usd(self, amount, currency):
if currency == "GBP":
return amount * 1.3
elif currency == "USD":
return amount
# fuck it who cares
elif currency == "SEK":
return 100
elif currency == "EUR":
return 10
def test_transaction(self):
self.transactions.transaction(self.test_data)
self.transactions.release_funds.assert_called_once_with("uuid1", "TEST-1")
@@ -154,7 +166,7 @@ class TestTransactions(TestCase):
def test_transaction_no_reference_pass(self):
no_reference_pass = self.data_custom(1, "GBP", "none")
no_reference_pass["meta"]["provider_reference"] = "none"
no_reference_pass["meta"]["provider_reference"] = "THIS_ONE_FAILS"
self.return_trades = [1]
self.transactions.transaction(no_reference_pass)