Fix all tests

This commit is contained in:
Mark Veidemanis 2022-05-24 08:38:37 +01:00
parent 3b58d178a4
commit 50213a1ac2
Signed by: m
GPG Key ID: 5ACFCEED46C0904F
9 changed files with 788 additions and 6290 deletions

View File

@ -679,7 +679,6 @@ class AgoraDesk:
add_to_api_method += f"/{payment_method}"
params = self._generic_search_parameters(amount, page)
return self._api_call(
api_method=f"{direction}-{main_currency}-online/" f"{exchange_currency}{add_to_api_method}",
query_values=params,
@ -688,11 +687,11 @@ class AgoraDesk:
@staticmethod
def _generic_search_parameters(amount, page):
params = None
if amount and not page:
if amount and page is not None:
params = {"amount": f"{amount}"}
elif amount and page:
elif amount and page is not None:
params = {"amount": f"{amount}", "page": f"{page}"}
elif not amount and page:
elif not amount and page is not None:
params = {"page": f"{page}"}
return params

View File

@ -120,12 +120,12 @@ class Markets(util.Base):
except KeyError:
# self.log.error("Error getting public ads for currency {currency}", currency=currency)
if currency == "GBP":
self.log.error("Error getting public ads for currency USD, aborting")
self.log.error("Error getting public ads for currency GBP, aborting")
break
continue
# Filter asset
public_ads_filtered = [ad for ad in public_ads_currency if ad[4] == asset]
# Filter provider
public_ads_filtered = [ad for ad in public_ads_filtered if ad[3] == provider]
our_ads = [ad for ad in public_ads_filtered if ad[1] == username]
@ -143,7 +143,7 @@ class Markets(util.Base):
asset = ad[4]
our_margin = ad[5]
if new_margin != our_margin:
to_update.append([ad_id, new_formula, asset, currency, False])
to_update.append([str(ad_id), new_formula, asset, currency, False])
return to_update

View File

@ -344,7 +344,7 @@ class Local(util.Base):
# Check if this person was seen recently
if not util.last_online_recent(date_last_seen):
continue
ad_id = ad["data"]["ad_id"]
ad_id = str(ad["data"]["ad_id"])
username = ad["data"]["profile"]["username"]
temp_price = ad["data"]["temp_price"]
if ad["data"]["currency"] != currency:

File diff suppressed because it is too large Load Diff

View File

@ -1,9 +1,10 @@
from unittest import TestCase
from unittest.mock import MagicMock, patch
# from twisted.internet.defer import inlineCallbacks
from twisted.internet.defer import inlineCallbacks
from json import loads
from copy import deepcopy
import logging
from tests.common import fake_public_ads, cg_prices, expected_to_update
import sources.agora
@ -24,6 +25,7 @@ class TestAgora(TestCase):
super().__init__(*args, *kwargs)
def setUp(self):
logging.disable(logging.CRITICAL)
self.markets = lib.markets.Markets()
self.agora = sources.agora.Agora()
self.money = lib.money.Money()
@ -55,6 +57,8 @@ class TestAgora(TestCase):
"ZAR",
]
self.agora.sinks = MagicMock()
self.agora.es = MagicMock()
self.agora.es.index = MagicMock()
self.agora.sinks.currencies = self.markets.sinks.currencies
self.all_providers = [
@ -110,6 +114,7 @@ class TestAgora(TestCase):
page = str(query_values["page"])
return self.test_return_data[(asset, currency, page)]
@inlineCallbacks
def test_get_all_public_ads(self):
# Override enum_public_ads
self.agora.api._api_call = self.mock_enum_public_ads_api_call
@ -123,7 +128,7 @@ class TestAgora(TestCase):
self.agora.markets.get_all_providers = MagicMock()
self.agora.markets.get_all_providers.return_value = self.all_providers
public_ads = self.agora.get_all_public_ads()
public_ads = yield self.agora.get_all_public_ads()
self.assertDictEqual(public_ads, fake_public_ads)
for currency, ads in public_ads.items():
@ -148,8 +153,11 @@ class TestAgora(TestCase):
self.assertNotEqual(asset1, asset2)
self.assertNotEqual(asset3, asset4)
@inlineCallbacks
def test_update_prices(self):
# Override the providers
settings.settings.Agora.MinMargin = 1.17
settings.settings.Agora.MaxMargin = 1.3
settings.settings.Agora.ProviderList = '["REVOLUT", "NATIONAL_BANK"]'
# Override enum_public_ads
@ -162,17 +170,18 @@ class TestAgora(TestCase):
self.agora.money.cg.get_price.return_value = cg_prices
self.agora.slow_ad_update = MagicMock()
self.agora.update_prices()
yield self.agora.update_prices()
call_args = self.agora.slow_ad_update.call_args_list[0][0][0]
self.assertCountEqual(call_args, expected_to_update)
@inlineCallbacks
def test_enum_public_ads(self):
# Override enum_public_ads
self.agora.api._api_call = self.mock_enum_public_ads_api_call
util.last_online_recent = MagicMock()
util.last_online_recent.return_value = True
enum_ads_return = self.agora.enum_public_ads("XMR", "USD", self.all_providers)
enum_ads_return = yield self.agora.enum_public_ads("XMR", "USD", self.all_providers)
# Ensure there are no duplicates
enum_ads_return_ids = [(x[0], x[1], x[2], x[3], x[4], x[5]) for x in enum_ads_return]

View File

@ -1,9 +1,10 @@
from unittest import TestCase
from unittest.mock import MagicMock, patch
# from twisted.internet.defer import inlineCallbacks
from twisted.internet.defer import inlineCallbacks
from json import loads
from copy import deepcopy
import logging
from tests.common import fake_public_ads_lbtc, cg_prices, expected_to_update_lbtc
import sources.localbitcoins
@ -25,6 +26,7 @@ class TestLBTC(TestCase):
super().__init__(*args, *kwargs)
def setUp(self):
logging.disable(logging.CRITICAL)
self.markets = lib.markets.Markets()
self.lbtc = sources.localbitcoins.LBTC()
self.money = lib.money.Money()
@ -38,6 +40,8 @@ class TestLBTC(TestCase):
"GBP",
]
self.lbtc.sinks = MagicMock()
self.lbtc.es = MagicMock()
self.lbtc.es.index = MagicMock()
self.lbtc.sinks.currencies = self.markets.sinks.currencies
self.all_providers = [
@ -67,7 +71,7 @@ class TestLBTC(TestCase):
self.lbtc.markets.get_all_providers = MagicMock()
self.lbtc.markets.get_all_providers.return_value = self.all_providers
public_ads = self.lbtc.get_all_public_ads()
public_ads = yield self.lbtc.get_all_public_ads()
self.assertDictEqual(public_ads, fake_public_ads_lbtc)
for currency, ads in public_ads.items():
@ -93,7 +97,10 @@ class TestLBTC(TestCase):
# self.assertNotEqual(asset1, asset2)
# self.assertNotEqual(asset3, asset4)
@inlineCallbacks
def test_update_prices(self):
settings.settings.LocalBitcoins.MinMargin = 1.10
settings.settings.LocalBitcoins.MaxMargin = 1.3
settings.settings.LocalBitcoins.Username = "Harrey"
# Override the providers
settings.settings.LocalBitcoins.ProviderList = '["national-bank-transfer"]'
@ -108,17 +115,18 @@ class TestLBTC(TestCase):
self.lbtc.money.cg.get_price.return_value = cg_prices
self.lbtc.slow_ad_update = MagicMock()
self.lbtc.update_prices()
yield self.lbtc.update_prices()
call_args = self.lbtc.slow_ad_update.call_args_list[0][0][0]
self.assertCountEqual(call_args, expected_to_update_lbtc)
@inlineCallbacks
def test_enum_public_ads(self):
# Override enum_public_ads
self.lbtc.api._api_call = self.mock_enum_public_ads_api_call
util.last_online_recent = MagicMock()
util.last_online_recent.return_value = True
enum_ads_return = self.lbtc.enum_public_ads("BTC", "GBP", self.all_providers)
enum_ads_return = yield self.lbtc.enum_public_ads("BTC", "GBP", self.all_providers)
# Ensure there are no duplicates
enum_ads_return_ids = [(x[0], x[1], x[2], x[3], x[4], x[5]) for x in enum_ads_return]

View File

@ -4,10 +4,12 @@ from tests.common import fake_public_ads, expected_to_update
import lib.markets
from sources.agora import Agora
import settings
import logging
class TestMarkets(TestCase):
def setUp(self):
logging.disable(logging.CRITICAL)
self.markets = lib.markets.Markets()
self.agora = Agora()
self.markets.sinks = MagicMock()
@ -41,7 +43,7 @@ class TestMarkets(TestCase):
"2b6dba4d-c9db-48f2-adba-4dc9dba8f2a0",
"Xpoterlolipop",
"182.80",
"REVOLUT",
"NATIONAL_BANK",
"XMR",
"USD",
1.18,
@ -50,7 +52,7 @@ class TestMarkets(TestCase):
"57e3e8d6-45fe-40da-a3e8-d645fe20da46",
"SecureMole",
"183.26",
"REVOLUT",
"NATIONAL_BANK",
"XMR",
"USD",
1.19,
@ -59,7 +61,7 @@ class TestMarkets(TestCase):
"87af6467-be02-476e-af64-67be02676e9a",
"topmonero",
"183.42",
"REVOLUT",
"NATIONAL_BANK",
"XMR",
"USD",
1.19,
@ -68,7 +70,7 @@ class TestMarkets(TestCase):
"65b452e3-a29f-4233-b452-e3a29fe23369",
"topmonero",
"183.42",
"REVOLUT",
"NATIONAL_BANK",
"XMR",
"USD",
1.19,
@ -77,7 +79,7 @@ class TestMarkets(TestCase):
"d2c6645c-6d56-4094-8664-5c6d5640941b",
"topmonero",
"183.42",
"REVOLUT",
"NATIONAL_BANK",
"XMR",
"USD",
1.19,
@ -89,9 +91,12 @@ class TestMarkets(TestCase):
self.assertEqual(margin, expected_margin)
def test_get_new_ad_equation(self):
self.maxDiff = None
settings.settings.Agora.MinMargin = 1.17
settings.settings.Agora.MaxMargin = 1.3
# 437 should be 1.3 but is 1.21
to_update = self.markets.get_new_ad_equations("agora", fake_public_ads)
self.assertCountEqual(to_update, expected_to_update)
res_xmr = self.markets.get_new_ad_equations("agora", fake_public_ads, ["XMR"])
expected_xmr_to_update = [x for x in expected_to_update if x[2] == "XMR"]
self.assertCountEqual(res_xmr, expected_xmr_to_update)

View File

@ -1,9 +1,11 @@
from unittest import TestCase
import lib.money
import logging
class TestMoney(TestCase):
def setUp(self):
logging.disable(logging.CRITICAL)
self.money = lib.money.Money()
def test_lookup_rates(self):

View File

@ -1,6 +1,7 @@
from unittest import TestCase
from unittest.mock import MagicMock
from copy import deepcopy
import logging
import lib.transactions
import lib.money
@ -9,6 +10,7 @@ import lib.antifraud
class TestTransactions(TestCase):
def setUp(self):
logging.disable(logging.CRITICAL)
self.transactions = lib.transactions.Transactions()
self.test_data = {
"timestamp": "2022-03-14T19:34:13.501Z",
@ -43,7 +45,7 @@ class TestTransactions(TestCase):
self.transactions.ux = MagicMock()
self.transactions.ux.notify = MagicMock()
self.transactions.ux.notify.notify_complete_trade = MagicMock()
self.transactions.antifraud = lib.antifraud.AntiFraud
self.transactions.antifraud = lib.antifraud.AntiFraud()
# Mock the rates
self.transactions.money = MagicMock()
@ -174,7 +176,6 @@ class TestTransactions(TestCase):
no_reference_pass = self.data_custom(1, "GBP", "none")
no_reference_pass["meta"]["provider_reference"] = "THIS_ONE_FAILS"
self.return_trades = [1]
self.transactions.transaction(no_reference_pass)
self.transactions.release_funds.assert_called_with("uuid1", "TEST-1")