-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUnitTests.py
60 lines (46 loc) · 2.35 KB
/
UnitTests.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
58
59
60
#!/usr/bin/env python3
import unittest
from Converter import Converter
from BaseCurrencies import BaseCurrencies
class TestBaseCurrenciesMethods(unittest.TestCase):
def test_getCurrencyCodes_containsKeyValuePairs(self):
base_currencies = BaseCurrencies()
currency_codes = base_currencies.getCurrencyRateDictionary()
self.assertGreater(len(currency_codes), 0,
msg="Currencies have not been read correctly")
class TestConverterMethods(unittest.TestCase):
def test_getConvertedValue_isPositive(self):
converter = Converter()
self.assertGreater(converter.getConvertedValue(1, 'EUR', 'USD'), 0,
msg="Value to be converted must be higher than 0")
def test_getConvertedValue_isConvertable(self):
converter = Converter()
expected_value = 3.14
rate_one = converter.getConvertedValue(expected_value, 'EUR', 'USD')
rate_two = converter.getConvertedValue(rate_one, 'USD', 'EUR')
self.assertEqual(expected_value, rate_two,
msg="Re-converting value is not valid")
def test_getConvertedValue_invalidCurrentCurrency(self):
converter = Converter()
with self.assertRaises(ValueError):
converter.getConvertedValue(1, 'LISA', 'EUR')
with self.assertRaises(ValueError):
converter.getConvertedValue(1, 'EUR', 'MARIE')
with self.assertRaises(ValueError):
converter.getConvertedValue(1, 'LISA', 'MARIE')
def test_getConvertedValue_invalidValue(self):
converter = Converter()
self.assertIsNone(converter.getConvertedValue('INVALID', 'EUR', 'USD'),
msg="Value to be converted is not valid")
self.assertIsNone(converter.getConvertedValue(False, 'EUR', 'USD'),
msg="Value to be converted is not valid")
def test_getConvertedValue_invalidParameter(self):
converter = Converter()
with self.assertRaises(TypeError, msg="A parameter is missing"):
converter.getConvertedValue('EUR', 'USD')
with self.assertRaises(TypeError, msg="A parameter is missing"):
converter.getConvertedValue(1, 'USD')
with self.assertRaises(TypeError, msg="A parameter is missing"):
converter.getConvertedValue()
if __name__ == '__main__':
unittest.main()