def test_get_arbitrary_rate_converting_to_base_currency_correct_call(): db = FakeDatabase(dict()) get_base_rate_ = MagicMock() with patch('cx.common.rates.get_base_rate', new=get_base_rate_): get_arbitrary_rate(db=db, date=date(2018, 5, 11), from_="USD", to="EUR") get_base_rate_.assert_called_with(db=db, date=date(2018, 5, 11), to="USD")
def test_get_arbitrary_rate_validate_target_currency(): db = FakeDatabase(dict()) target_currency = MagicMock() validate_currency_ = MagicMock() with patch('cx.common.rates.validate_currency', new=validate_currency_): try: get_arbitrary_rate(db=db, date=date(2018, 5, 11), to=target_currency, from_="EUR") except: pass validate_currency_.assert_any_call(target_currency)
def test_get_arbitrary_rate_converting_from_base_currency_correct_value(): db = FakeDatabase(dict()) get_base_rate_ = MagicMock() get_base_rate_.return_value = MagicMock() with patch('cx.common.rates.get_base_rate', new=get_base_rate_): assert get_arbitrary_rate(db=db, date=date(2018, 5, 11), from_="EUR", to="USD") == get_base_rate_.return_value
def test_get_arbitrary_rate_converting_arbitrary_currency_correct_value( currency, rate): db = FakeDatabase(dict()) get_base_rate_ = MagicMock() get_base_rate_.side_effect = lambda db, date, to: rate if to == currency else 2 with patch('cx.common.rates.get_base_rate', new=get_base_rate_): assert get_arbitrary_rate(db=db, date=date(2018, 5, 11), from_="USD", to=currency) == pytest.approx(rate / 2)
def test_get_arbitrary_rate_identical_currencies(): db = FakeDatabase(dict()) assert get_arbitrary_rate(db=db, date=date(2018, 5, 11), from_="USD", to="USD") == 1.0
def get(self, date, from_, to): return {"rate": get_arbitrary_rate(db, parse_date(date), from_, to)}