Begin transactions tests
This commit is contained in:
parent
2e83516b19
commit
3fd656e1df
|
@ -0,0 +1,198 @@
|
|||
from unittest import TestCase
|
||||
from unittest.mock import MagicMock
|
||||
from copy import deepcopy
|
||||
|
||||
import transactions
|
||||
|
||||
|
||||
class TestTransactions(TestCase):
|
||||
def setUp(self):
|
||||
self.transactions = transactions.Transactions()
|
||||
self.test_data = {
|
||||
"event": "TransactionCreated",
|
||||
"timestamp": "2022-02-24T20:26:15.232342Z",
|
||||
"data": {
|
||||
"id": "6217e9e7-43e1-a809-8500-0a5b0170e6e4",
|
||||
"type": "transfer",
|
||||
"state": "completed",
|
||||
"request_id": "8a15213e-a7d2-4738-bfb5-b1d037b75a57",
|
||||
"created_at": "2022-02-24T20:26:15.238218Z",
|
||||
"updated_at": "2022-02-24T20:26:15.238218Z",
|
||||
"completed_at": "2022-02-24T20:26:15.238453Z",
|
||||
"reference": "TEST-1",
|
||||
"legs": [
|
||||
{
|
||||
"leg_id": "80b35daf-409c-41be-8755-15982b7633a6",
|
||||
"account_id": "7185593b-d9ad-4456-920e-d9db109a5172",
|
||||
"counterparty": {"account_type": "revolut"},
|
||||
"amount": 1,
|
||||
"currency": "GBP",
|
||||
"description": "From Mark Veidemanis",
|
||||
"balance": 3832.3,
|
||||
}
|
||||
],
|
||||
},
|
||||
}
|
||||
|
||||
# Mock redis calls
|
||||
transactions.r.hgetall = self.mock_hgetall
|
||||
transactions.r.hmset = self.mock_hmset
|
||||
transactions.r.keys = self.mock_keys
|
||||
transactions.r.get = self.mock_get
|
||||
|
||||
self.transactions.irc = MagicMock()
|
||||
self.transactions.irc.sendmsg = MagicMock()
|
||||
self.transactions.release_funds = MagicMock()
|
||||
self.transactions.notify = MagicMock()
|
||||
self.transactions.notify.notify_complete_trade = MagicMock()
|
||||
|
||||
self.trade_1 = {
|
||||
"id": "uuid1",
|
||||
"buyer": "test_buyer_1",
|
||||
"currency": "GBP",
|
||||
"amount": "1",
|
||||
"amount_xmr": "0.3",
|
||||
"reference": "TEST-1",
|
||||
}
|
||||
|
||||
self.trade_2 = {
|
||||
"id": "uuid2",
|
||||
"buyer": "test_buyer_2",
|
||||
"currency": "GBP",
|
||||
"amount": "1",
|
||||
"amount_xmr": "0.3",
|
||||
"reference": "TEST-2",
|
||||
}
|
||||
|
||||
@property
|
||||
def test_data_copy(self):
|
||||
return deepcopy(self.test_data)
|
||||
|
||||
def mock_hgetall(self, string):
|
||||
if string == "trade.TEST-1":
|
||||
return self.trade_1
|
||||
elif string == "trade.TEST-2":
|
||||
return self.trade_2
|
||||
|
||||
def mock_hmset(self, string, data):
|
||||
print("HMSET", string, data)
|
||||
|
||||
def mock_keys(self, string):
|
||||
return ["uuid1", "uuid2"]
|
||||
|
||||
def mock_get(self, string):
|
||||
if string == "uuid1":
|
||||
return "TEST-1"
|
||||
elif string == "uuid2":
|
||||
return "TEST-2"
|
||||
|
||||
def test_transaction(self):
|
||||
self.transactions.transaction(self.test_data)
|
||||
self.transactions.release_funds.assert_called_once_with("uuid1", "TEST-1")
|
||||
|
||||
self.transactions.release_funds = MagicMock()
|
||||
ref_2 = self.test_data_copy
|
||||
ref_2["data"]["reference"] = "TEST-2"
|
||||
self.transactions.transaction(ref_2)
|
||||
self.transactions.release_funds.assert_called_once_with("uuid2", "TEST-2")
|
||||
|
||||
def test_transaction_invalid(self):
|
||||
invalid_data = self.test_data_copy
|
||||
invalid_data["data"]["reference"] = "sss"
|
||||
invalid_data["data"]["amount"] = 2000
|
||||
invalid_data["data"]["currency"] = "SEK"
|
||||
self.transactions.transaction(invalid_data)
|
||||
self.transactions.release_funds.assert_not_called()
|
||||
|
||||
def test_transaction_malformed(self):
|
||||
pass
|
||||
|
||||
def test_transaction_no_reference_fail(self):
|
||||
pass
|
||||
|
||||
def test_transaction_no_reference_pass(self):
|
||||
pass
|
||||
|
||||
def test_transaction_no_reference_exceeds_max(self):
|
||||
pass
|
||||
|
||||
def test_transaction_wrong_currency(self):
|
||||
pass
|
||||
|
||||
def test_transaction_wrong_amount(self):
|
||||
pass
|
||||
|
||||
def test_transaction_pending(self):
|
||||
pass
|
||||
|
||||
def test_transaction_too_low(self):
|
||||
pass
|
||||
|
||||
def test_transaction_too_high(self):
|
||||
pass
|
||||
|
||||
# def test_transaction_pending_then_completed(self):
|
||||
# pass
|
||||
|
||||
def test_transaction_store_incomplete_trade(self):
|
||||
pass
|
||||
|
||||
def test_transaction_release_incomplete_trade(self):
|
||||
pass
|
||||
|
||||
def test_transaction_card_payment(self):
|
||||
pass
|
||||
|
||||
def test_transaction_negative_amount(self):
|
||||
pass
|
||||
|
||||
def test_release_funds(self):
|
||||
pass
|
||||
|
||||
def test_new_trade(self):
|
||||
pass
|
||||
|
||||
def test_find_trade(self):
|
||||
pass
|
||||
|
||||
def test_get_refs(self):
|
||||
pass
|
||||
|
||||
def test_get_ref_map(self):
|
||||
pass
|
||||
|
||||
def test_get_ref(self):
|
||||
pass
|
||||
|
||||
def test_del_ref(self):
|
||||
pass
|
||||
|
||||
def test_cleanup(self):
|
||||
pass
|
||||
|
||||
def test_tx_to_ref(self):
|
||||
pass
|
||||
|
||||
def test_ref_to_tx(self):
|
||||
pass
|
||||
|
||||
def test_get_total_usd(self):
|
||||
pass
|
||||
|
||||
def test_get_total(self):
|
||||
pass
|
||||
|
||||
def test_write_to_es(self):
|
||||
pass
|
||||
|
||||
def test_get_remaining(self):
|
||||
pass
|
||||
|
||||
def test_get_open_trades_usd(self):
|
||||
pass
|
||||
|
||||
def test_get_total_remaining(self):
|
||||
pass
|
||||
|
||||
def get_total_with_trades(self):
|
||||
pass
|
Loading…
Reference in New Issue