69 lines
3.2 KiB
Python
69 lines
3.2 KiB
Python
from unittest import TestCase
|
|
from tests.common import fake_public_ads, expected_to_update
|
|
from markets import Markets
|
|
from sources.agora import Agora
|
|
import settings
|
|
|
|
|
|
class TestMarkets(TestCase):
|
|
def setUp(self):
|
|
self.markets = Markets()
|
|
self.agora = Agora()
|
|
|
|
def test_autoprice(self):
|
|
ads = [
|
|
["2b6dba4d-c9db-48f2-adba-4dc9dba8f2a0", "Xpoterlolipop", "182.80", "REVOLUT", "XMR", "USD", 1.18],
|
|
["57e3e8d6-45fe-40da-a3e8-d645fe20da46", "SecureMole", "183.26", "REVOLUT", "XMR", "USD", 1.19],
|
|
["87af6467-be02-476e-af64-67be02676e9a", "topmonero", "183.42", "REVOLUT", "XMR", "USD", 1.19],
|
|
["65b452e3-a29f-4233-b452-e3a29fe23369", "topmonero", "183.42", "REVOLUT", "XMR", "USD", 1.19],
|
|
["d2c6645c-6d56-4094-8664-5c6d5640941b", "topmonero", "183.42", "REVOLUT", "XMR", "USD", 1.19],
|
|
]
|
|
currency = "EUR"
|
|
margin = self.markets.autoprice(ads, currency)
|
|
expected_margin = 1.18
|
|
self.assertEqual(margin, expected_margin)
|
|
|
|
def test_get_new_ad_equation(self):
|
|
to_update = self.markets.get_new_ad_equations(fake_public_ads)
|
|
self.assertCountEqual(to_update, expected_to_update)
|
|
|
|
res_xmr = self.markets.get_new_ad_equations(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)
|
|
|
|
res_btc = self.markets.get_new_ad_equations(fake_public_ads, ["BTC"])
|
|
expected_btc_to_update = [x for x in expected_to_update if x[2] == "BTC"]
|
|
self.assertCountEqual(res_btc, expected_btc_to_update)
|
|
|
|
res_both = self.markets.get_new_ad_equations(fake_public_ads, ["XMR", "BTC"])
|
|
self.assertCountEqual(res_both, expected_to_update)
|
|
|
|
def test_format_ad(self):
|
|
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"}
|
|
payment_details_text = self.markets.format_payment_details("GBP", payment_details)
|
|
ad_text = self.markets.format_ad("XMR", "GBP", payment_details_text)
|
|
expected = """* Set **Country of recipient's bank** to **"United Kingdom"**
|
|
* Company name: **PATHOGEN LIMITED**
|
|
* Sort code: **02-03-04**
|
|
* Account number: **0023-0045**
|
|
* Please send in **GBP**
|
|
* 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"**"""
|
|
self.assertEqual(ad_text, expected)
|
|
|
|
def test_format_payment_details(self):
|
|
payment_details = {"sort_code": "02-03-04", "account_number": "0023-0045"}
|
|
payment_details_text = self.markets.format_payment_details("GBP", payment_details)
|
|
|
|
expected = """* Company name: **PATHOGEN LIMITED**
|
|
* Sort code: **02-03-04**
|
|
* Account number: **0023-0045**
|
|
* Please send in **GBP**
|
|
* If you are asked for address information, please use **24 Holborn Viaduct, London, England, EC1A 2BN**
|
|
* The post code is **EC1A 2BN**"""
|
|
self.assertEqual(payment_details_text, expected)
|