currency.py
1.19 KB
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
from tests.client import TestClient
from floraconcierge.mapping.model.shop import Currency
class TestCurrency(TestClient):
# def test_round(self):
# self.assertEqual(Currency.round(0.12541, 2), 0.12)
# self.assertEqual(Currency.round(0.12641, 2), 0.12)
# self.assertEqual(Currency.round(0.11641, 2), 0.11)
def test_format(self):
curr = self.client.call('shop/currency', {'id': 'usd'})
self.assertIsInstance(curr, Currency)
self.assertIn('0.12', curr.convert(0.12))
self.assertIn('5.12', curr.convert(5.12))
self.assertIn('0.11', curr.convert(0.11641))
def test_convert_value(self):
curr = self.client.call('shop/currency', {'id': 'usd'})
self.assertIsInstance(curr, Currency)
self.assertNotEqual(0.11, curr.convert(0.11641))
self.assertEqual(0.11, curr.convert_float(0.11641))
def test_conversion(self):
curr = self.client.call('shop/currency', {'id': 'rub'})
# disable rounding
curr.rounding = 0
self.assertIsInstance(curr, Currency)
self.assertGreater(curr.convert_float(0.5), 1)
self.assertGreaterEqual(curr.convert_float(0.5), 0.5 * float(curr.usdvalue))