예제 #1
0
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')
예제 #2
0
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
예제 #3
0
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
예제 #4
0
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")
예제 #5
0
def test_pln_to_euro():
    e = CurrencyExchanger(exchange_rates=exchange_rates)
    assert e.exchange(1, input_currency="pln", output_currency="eur") == 0.25
예제 #6
0
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
예제 #7
0
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
예제 #8
0
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
예제 #9
0
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
예제 #10
0
def test_pln_to_pln():
    e = CurrencyExchanger(exchange_rates={('eur', 'pln'): 4.24})
    assert e.exchange(1, 'pln', 'pln') == 1
예제 #11
0
def test_lack_of_default_and_output_currency():
    e = CurrencyExchanger(exchange_rates={('eur', 'pln'): 4.24})
    with pytest.raises(UnsupportedExchangeRateError):
        e.exchange(1, 'eur')
예제 #12
0
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
예제 #13
0
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
예제 #14
0
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
예제 #15
0
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
예제 #16
0
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
예제 #17
0
def test_pln_to_euro():
    e = CurrencyExchanger(exchange_rates=exchange_rates)
    assert e.exchange(1, input_currency='pln', output_currency='eur') == 0.25
예제 #18
0
def test_with_real_backend():
    e = CurrencyExchanger(currency_provider_class=CurrencyProvider)
    print '>>>>>>>', e.exchange(1, 'eur', 'pln')
예제 #19
0
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