From 45392455fac8efbf3af3f98a2d70c88b38f22b4f Mon Sep 17 00:00:00 2001 From: Mark Veidemanis Date: Sat, 19 Mar 2022 15:38:24 +0000 Subject: [PATCH] Fix Agora tests --- handler/sources/agora.py | 9 +++------ handler/tests/test_agora.py | 15 ++++++++------- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/handler/sources/agora.py b/handler/sources/agora.py index a829487..f6db3fc 100644 --- a/handler/sources/agora.py +++ b/handler/sources/agora.py @@ -4,9 +4,7 @@ from twisted.internet.threads import deferToThread # Other library imports from json import loads -from forex_python.converter import CurrencyRates from lib.agoradesk_py import AgoraDesk -from pycoingecko import CoinGeckoAPI # TODO: remove this import and defer to money from time import sleep from pyotp import TOTP from datetime import datetime @@ -28,8 +26,6 @@ class Agora(util.Base): """ super().__init__() 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 self.last_dash = set() @@ -361,7 +357,7 @@ class Agora(util.Base): if not providers: providers = self.markets.get_all_providers() # 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 currency in currencies: cg_asset_name = crypto_map[asset] @@ -626,6 +622,7 @@ class Agora(util.Base): for ad_id, country, currency in repeated: rtrn = self.agora.ad_delete(ad_id) actioned.append(rtrn["success"]) + return all(actioned) @util.handle_exceptions @@ -671,7 +668,7 @@ class Agora(util.Base): profit_usd = total_usd - float(settings.Money.BaseUSD) # 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 profit_usd_in_xmr = float(profit_usd) / xmr_usd["monero"]["usd"] diff --git a/handler/tests/test_agora.py b/handler/tests/test_agora.py index 081af84..cbdaff8 100644 --- a/handler/tests/test_agora.py +++ b/handler/tests/test_agora.py @@ -89,8 +89,8 @@ class TestAgora(TestCase): util.last_online_recent.return_value = True # Override get_price - self.agora.cg.get_price = MagicMock() - self.agora.cg.get_price.return_value = cg_prices + self.agora.money.cg.get_price = MagicMock() + self.agora.money.cg.get_price.return_value = cg_prices self.agora.markets.get_all_providers = MagicMock() 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 # Override get_price - self.agora.cg.get_price = MagicMock() - self.agora.cg.get_price.return_value = cg_prices + self.agora.money.cg.get_price = MagicMock() + self.agora.money.cg.get_price.return_value = cg_prices self.agora.slow_ad_update = MagicMock() self.agora.update_prices() @@ -213,8 +213,8 @@ class TestAgora(TestCase): util.last_online_recent.return_value = True # Override get_price - self.agora.cg.get_price = MagicMock() - self.agora.cg.get_price.return_value = cg_prices + self.agora.money.cg.get_price = MagicMock() + self.agora.money.cg.get_price.return_value = cg_prices 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) 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$ * Set **Company name** to **"PATHOGEN LIMITED"**""" 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** * The post code is **EC1A 2BN** * Set **Company name** to **"PATHOGEN LIMITED"**""" + print("EXPECT", ad_text) self.assertEqual(ad_text, expected) def test_format_payment_details(self):