source: main/waeup.ikoba/trunk/src/waeup/ikoba/payments/tests/test_currencies.py @ 17497

Last change on this file since 17497 was 12752, checked in by Henrik Bettermann, 10 years ago

propset

  • Property svn:keywords set to Id
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.