Fix Agora tests

master
Mark Veidemanis 3 years ago
parent f9c57e60bf
commit 45392455fa
Signed by: m
GPG Key ID: 5ACFCEED46C0904F

@ -4,9 +4,7 @@ from twisted.internet.threads import deferToThread
# Other library imports # Other library imports
from json import loads from json import loads
from forex_python.converter import CurrencyRates
from lib.agoradesk_py import AgoraDesk from lib.agoradesk_py import AgoraDesk
from pycoingecko import CoinGeckoAPI # TODO: remove this import and defer to money
from time import sleep from time import sleep
from pyotp import TOTP from pyotp import TOTP
from datetime import datetime from datetime import datetime
@ -28,8 +26,6 @@ class Agora(util.Base):
""" """
super().__init__() super().__init__()
self.agora = AgoraDesk(settings.Agora.Token) self.agora = AgoraDesk(settings.Agora.Token)
self.cr = CurrencyRates() # TODO: remove this and defer to money
self.cg = CoinGeckoAPI() # TODO: remove this and defer to money
# Cache for detecting new trades # Cache for detecting new trades
self.last_dash = set() self.last_dash = set()
@ -361,7 +357,7 @@ class Agora(util.Base):
if not providers: if not providers:
providers = self.markets.get_all_providers() providers = self.markets.get_all_providers()
# We want to get the ads for each of these currencies and return the result # We want to get the ads for each of these currencies and return the result
rates = self.cg.get_price(ids=["monero", "bitcoin"], vs_currencies=currencies) rates = self.money.cg.get_price(ids=["monero", "bitcoin"], vs_currencies=currencies)
for asset in assets: for asset in assets:
for currency in currencies: for currency in currencies:
cg_asset_name = crypto_map[asset] cg_asset_name = crypto_map[asset]
@ -626,6 +622,7 @@ class Agora(util.Base):
for ad_id, country, currency in repeated: for ad_id, country, currency in repeated:
rtrn = self.agora.ad_delete(ad_id) rtrn = self.agora.ad_delete(ad_id)
actioned.append(rtrn["success"]) actioned.append(rtrn["success"])
return all(actioned) return all(actioned)
@util.handle_exceptions @util.handle_exceptions
@ -671,7 +668,7 @@ class Agora(util.Base):
profit_usd = total_usd - float(settings.Money.BaseUSD) profit_usd = total_usd - float(settings.Money.BaseUSD)
# Get the XMR -> USD exchange rate # Get the XMR -> USD exchange rate
xmr_usd = self.cg.get_price(ids="monero", vs_currencies=["USD"]) xmr_usd = self.money.cg.get_price(ids="monero", vs_currencies=["USD"])
# Convert the USD total to XMR # Convert the USD total to XMR
profit_usd_in_xmr = float(profit_usd) / xmr_usd["monero"]["usd"] profit_usd_in_xmr = float(profit_usd) / xmr_usd["monero"]["usd"]

@ -89,8 +89,8 @@ class TestAgora(TestCase):
util.last_online_recent.return_value = True util.last_online_recent.return_value = True
# Override get_price # Override get_price
self.agora.cg.get_price = MagicMock() self.agora.money.cg.get_price = MagicMock()
self.agora.cg.get_price.return_value = cg_prices self.agora.money.cg.get_price.return_value = cg_prices
self.agora.markets.get_all_providers = MagicMock() self.agora.markets.get_all_providers = MagicMock()
self.agora.markets.get_all_providers.return_value = self.all_providers self.agora.markets.get_all_providers.return_value = self.all_providers
@ -130,8 +130,8 @@ class TestAgora(TestCase):
util.last_online_recent.return_value = True util.last_online_recent.return_value = True
# Override get_price # Override get_price
self.agora.cg.get_price = MagicMock() self.agora.money.cg.get_price = MagicMock()
self.agora.cg.get_price.return_value = cg_prices self.agora.money.cg.get_price.return_value = cg_prices
self.agora.slow_ad_update = MagicMock() self.agora.slow_ad_update = MagicMock()
self.agora.update_prices() self.agora.update_prices()
@ -213,8 +213,8 @@ class TestAgora(TestCase):
util.last_online_recent.return_value = True util.last_online_recent.return_value = True
# Override get_price # Override get_price
self.agora.cg.get_price = MagicMock() self.agora.money.cg.get_price = MagicMock()
self.agora.cg.get_price.return_value = cg_prices self.agora.money.cg.get_price.return_value = cg_prices
enum_ads_return = self.agora.enum_public_ads("XMR", "EUR", self.all_providers) enum_ads_return = self.agora.enum_public_ads("XMR", "EUR", self.all_providers)
@ -231,7 +231,7 @@ class TestAgora(TestCase):
self.assertCountEqual(lookup_rates_return, expected_return) self.assertCountEqual(lookup_rates_return, expected_return)
def test_format_ad(self): def test_format_ad(self):
settings.settings.Agora.Ad = """* Set **Country of recipient's bank** to **"United Kingdom"** settings.settings.Platform.Ad = """* Set **Country of recipient's bank** to **"United Kingdom"**
$PAYMENT$ $PAYMENT$
* Set **Company name** to **"PATHOGEN LIMITED"**""" * Set **Company name** to **"PATHOGEN LIMITED"**"""
payment_details = {"sort_code": "02-03-04", "account_number": "0023-0045"} payment_details = {"sort_code": "02-03-04", "account_number": "0023-0045"}
@ -245,6 +245,7 @@ $PAYMENT$
* If you are asked for address information, please use **24 Holborn Viaduct, London, England, EC1A 2BN** * If you are asked for address information, please use **24 Holborn Viaduct, London, England, EC1A 2BN**
* The post code is **EC1A 2BN** * The post code is **EC1A 2BN**
* Set **Company name** to **"PATHOGEN LIMITED"**""" * Set **Company name** to **"PATHOGEN LIMITED"**"""
print("EXPECT", ad_text)
self.assertEqual(ad_text, expected) self.assertEqual(ad_text, expected)
def test_format_payment_details(self): def test_format_payment_details(self):

Loading…
Cancel
Save