source: main/waeup.ikoba/branches/uli-payments/src/waeup/ikoba/payments/tests/test_currencies.py @ 12697

Last change on this file since 12697 was 12311, checked in by uli, 10 years ago

Merge changes from uli-paypal back into trunk.

File size: 1.9 KB
Line 
1import unittest
2from zope.i18nmessageid.message import Message as i18nMessage
3from zope.interface.verify import verifyObject
4from zope.schema.interfaces import IVocabularyTokenized, ITerm
5from waeup.ikoba.payments.currencies import (
6    get_decimal_units, ISO_4217_CURRENCIES, ISO_4217_CURRENCIES_VOCAB,
7    )
8
9
10class CurrenciesTests(unittest.TestCase):
11
12    def test_get_decimal_units(self):
13        # we can get the number of decimals for a currency code
14        assert get_decimal_units('USD') == 2
15        assert get_decimal_units('JPY') == 0
16
17    def test_iso_currencies_no_linebreak(self):
18        # sanity check: make sure we didn't compile linebreaks
19        for key, value in ISO_4217_CURRENCIES.items():
20            assert '\n' not in key
21            assert '\n' not in value[0]
22            assert '\n' not in value[1]
23
24    def test_iso_currencies_types(self):
25        # sanity check: make sure we have the correct types in all tuples
26        for key, value in ISO_4217_CURRENCIES.items():
27            assert isinstance(value[1], i18nMessage)
28            assert isinstance(value[2], int)
29            assert isinstance(value[3], str)
30
31    def test_currencies_vocab_tokenized(self):
32        # we can get ISO currencies as a source suitable for forms etc.
33        verifyObject(IVocabularyTokenized, ISO_4217_CURRENCIES_VOCAB)
34
35    def test_currencies_vocab_i18nized(self):
36        # vocab titles are i18nized
37        result = ISO_4217_CURRENCIES_VOCAB.getTerm('USD')
38        assert ITerm.providedBy(result)
39        self.assertEqual(result.title, u'US Dollar')
40        assert isinstance(result.title, i18nMessage)
41
42    def test_currencies_vocab_tokens_are_string(self):
43        # vocab tokens are simple strings
44        result = ISO_4217_CURRENCIES_VOCAB.getTerm('USD')
45        assert ITerm.providedBy(result)
46        assert result.token == result.value
47        assert result.value == 'USD'
48        assert isinstance(result.token, str)
49        assert isinstance(result.value, str)
Note: See TracBrowser for help on using the repository browser.