# $Id$
#
# Copyright (C) 2014 Uli Fouquet & Henrik Bettermann
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
import unittest
from zope.i18nmessageid.message import Message as i18nMessage
from zope.interface.verify import verifyObject
from zope.schema.interfaces import IVocabularyTokenized, ITerm
from waeup.ikoba.payments.paypal_currencies import (
    CURRENCIES, CURRENCIES_VOCAB,
    )


class CurrencyTests(unittest.TestCase):

    def test_currencies_is_dict(self):
        # CURRENCIES is available
        assert isinstance(CURRENCIES, dict)

    def test_currencies_contains_i18n_messages(self):
        # the CURRENCIES values are i18n messages
        assert 'USD' in CURRENCIES.keys()
        assert isinstance(CURRENCIES['USD'][0], i18nMessage)

    def test_currencies_contain_domestic_infos(self):
        # there is info about currencies valid domestic only avail.
        CURRENCIES['USD'][1] is False
        # there is info about whether the currency support decimals
        CURRENCIES['USD'][2] is True


class CurrenciesVocabTests(unittest.TestCase):

    def test_currencies_vocab_tokenized(self):
        # we can get a currencies source suitable for forms etc.
        verifyObject(IVocabularyTokenized, CURRENCIES_VOCAB)

    def test_currencies_vocab_i18nized(self):
        # vocab titles are i18nized
        result = CURRENCIES_VOCAB.getTerm('USD')
        assert ITerm.providedBy(result)
        self.assertEqual(result.title, u'United States dollar')
        assert isinstance(result.title, i18nMessage)

    def test_currencies_vocab_tokens_are_string(self):
        # vocab tokens are simple strings
        result = CURRENCIES_VOCAB.getTerm('USD')
        assert ITerm.providedBy(result)
        assert result.token == 'USD'
        assert result.value == 'USD'
