forked from deployed/tddworkshop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_exchange.py
57 lines (39 loc) · 1.58 KB
/
test_exchange.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import pytest
from exchange import CurrencyExchanger, UnsupportedExchangeRateError
# example exchange rates for testing
exchange_rates = {
('eur', 'pln'): 4.24,
('pln', 'eur'): 0.25,
('usd', 'pln'): 3.8,
}
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_pln_to_euro():
e = CurrencyExchanger(exchange_rates=exchange_rates)
assert e.exchange(1, input_currency='pln', output_currency='eur') == 0.25
def test_euro_to_pln_with_default_pln():
# TODO: implement
assert False
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_wrong_value():
# TODO: implement
assert False
def test_pln_to_pln():
# TODO: implement
assert False
# TODO: write your own test cases
# uncomment for example test using mock
# remember to import mock :)
# @mock.patch('exchange.OnlineRates.get_data', mock.Mock(return_value={('eur', 'pln'): 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