def test_wrong_value(): e = CurrencyExchanger(exchange_rates={('eur', 'pln'): 'asd'}) with pytest.raises(UnsupportedExchangeRateError): e.exchange(1, 'eur', 'pln') e = CurrencyExchanger(exchange_rates={('eur', 'pln'): 4.24}) with pytest.raises(UnsupportedExchangeRateError): e.exchange('1', 'eur', 'pln') with pytest.raises(UnsupportedExchangeRateError): e.exchange(-1, 'eur', 'pln')
def test_euro_to_pln_with_default_dummy_backend(): e = CurrencyExchanger(currency_provider_class=DummyCurrencyProvider) assert e.exchange(1, 'eur', 'pln') == 4.24 assert e.exchange(2, 'eur', 'pln') == 8.48 assert e.exchange(1, 'pln', 'eur') == 0.25
def test_euro_to_pln(): e = CurrencyExchanger(exchange_rates=exchange_rates) assert e.exchange(value=1, input_currency="eur", output_currency="pln") == 4.24 assert e.exchange(2, "eur", "pln") == 8.48
def test_unsupported_exchange_rates(): e = CurrencyExchanger(exchange_rates={("eur", "pln"): 4.24}) assert e.exchange(1, "eur", "pln") == 4.24 with pytest.raises(UnsupportedExchangeRateError): e.exchange(1, "pln", "usd")
def test_pln_to_euro(): e = CurrencyExchanger(exchange_rates=exchange_rates) assert e.exchange(1, input_currency="pln", output_currency="eur") == 0.25
def test_unsupported_exchange_rates(): e = CurrencyExchanger(exchange_rates={('eur', 'pln'): 4.24}) assert e.exchange(1, 'eur', 'pln') == 4.24 with pytest.raises(UnsupportedExchangeRateError): assert e.exchange(1, 'pln', 'usd') == 4.24
def test_euro_to_pln_with_default_pln(): e = CurrencyExchanger(exchange_rates=exchange_rates, default_currency='pln') assert e.exchange(1, 'eur') == 4.24 assert e.exchange(2, 'eur') == 8.48
def test_exchanger_with_not_existing_data(): e = CurrencyExchanger(exchange_rates=exchange_rates, currency_provider_class=DummyCurrencyProvider) assert e.exchange(1, 'usd', 'pln') == 3.8 with pytest.raises(ExchangeException): assert e.exchange(1, 'pln', 'usd') == 4.24
def test_eur_to_pln_with_data_from_external_api(): online_rates = OnlineRates(src='https://currency-api.appspot.com/api/eur/pln.json').get_data() assert ('eur', 'pln') in online_rates e = CurrencyExchanger(exchange_rates=online_rates) assert e.exchange(1, 'eur', 'pln') == 4.24 assert e.exchange(2, 'eur', 'pln') == 8.48
def test_pln_to_pln(): e = CurrencyExchanger(exchange_rates={('eur', 'pln'): 4.24}) assert e.exchange(1, 'pln', 'pln') == 1
def test_lack_of_default_and_output_currency(): e = CurrencyExchanger(exchange_rates={('eur', 'pln'): 4.24}) with pytest.raises(UnsupportedExchangeRateError): e.exchange(1, 'eur')
def test_euro_to_pln_with_default_pln(): e = CurrencyExchanger(exchange_rates={('eur', 'pln'): 4.24}, default_currency='pln') assert e.exchange(1, 'eur') == 4.24 assert e.exchange(1, 'pln') == 1
def test_exchanger_with_not_existing_data(): e = CurrencyExchanger(exchange_rates=exchange_rates) assert e.exchange(1, 'usd', 'pln') == 3.8 with pytest.raises(AttributeError): assert e.exchange(1, 'pln', 'usd') == 4.24
def test_euro_to_pln(): e = CurrencyExchanger(exchange_rates=exchange_rates, currency_provider_class=DummyCurrencyProvider) assert e.exchange(1, 'eur', 'pln') == 4.24 assert e.exchange(2, 'eur', 'pln') == 8.48 assert e.exchange(1, 'pln', 'eur') == 0.25
def test_euro_to_pln(): e = CurrencyExchanger(exchange_rates=exchange_rates) assert e.exchange(value=1, input_currency='eur', output_currency='pln') == 4.24 assert e.exchange(2, 'eur', 'pln') == 8.48
def test_euro_to_pln_with_default_pln(): e = CurrencyExchanger(exchange_rates=exchange_rates, default_currency='pln', currency_provider_class=DummyCurrencyProvider) assert e.exchange(1, 'eur') == 4.24 assert e.exchange(2, 'eur') == 8.48
def test_pln_to_euro(): e = CurrencyExchanger(exchange_rates=exchange_rates) assert e.exchange(1, input_currency='pln', output_currency='eur') == 0.25
def test_with_real_backend(): e = CurrencyExchanger(currency_provider_class=CurrencyProvider) print '>>>>>>>', e.exchange(1, 'eur', 'pln')
def test_euro_to_pln(): e = CurrencyExchanger(exchange_rates=exchange_rates) assert e.exchange(1, 'eur', 'pln') == 4.24 assert e.exchange(2, 'eur', 'pln') == 8.48 assert e.exchange(1, 'pln', 'eur') == 0.25