##
## test_interfaces.py
## Login : <uli@pu.smp.net>
## Started on  Tue Jan 25 17:09:46 2011 Uli Fouquet
## $Id$
## 
## Copyright (C) 2011 Uli Fouquet
## 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
##
"""
Test components defined in interface module.
"""
import unittest
from zc.sourcefactory.browser.source import FactoredTerms
from zope.browser.interfaces import ITerms
from zope.component import getMultiAdapter
from zope.interface.verify import verifyClass, verifyObject
from zope.publisher.browser import TestRequest
from waeup.sirp.applicants import interfaces
from waeup.sirp.applicants.vocabularies import (
    APPLICATION_TYPES, application_types_vocab, GenderSource,
    )

class ApplicationCategoriesTestCase(unittest.TestCase):

    def setUp(self):
        self.vocab = application_types_vocab
        return

    def test_vocabulary_len(self):
        self.assertEqual(len(self.vocab), 10)
        return

    def test_vocabulary_items(self):
        self.assertTrue('pude' in self.vocab)
        return

    def test_term_attributes(self):
        # Check that each vocab entry provided value, token, and title.
        term = self.vocab.getTermByToken('pude')
        self.assertEqual(term.token, 'pude')
        self.assertEqual(term.value, 'pude')
        self.assertEqual(term.title, 'Post UDE Screening')
        return

class InterfacesTest(unittest.TestCase):

    def setUp(self):
        self.source = GenderSource()
        self.request = TestRequest()
        self.terms = FactoredTerms(self.source, self.request)
        return

    def tearDown(self):
        pass

    def test_GenderSource_list(self):
        result = list(self.source)
        self.assertEqual(result, ['m', 'f'])

    def test_GenderSource_term_male(self):
        term = self.terms.getTerm('m')
        assert term.title == 'Male'
        assert term.token == 'm'
        assert term.value == 'm'

    def test_GenderSource_term_female(self):
        term = self.terms.getTerm('f')
        assert term.title == 'Female'
        assert term.token == 'f'
        assert term.value == 'f'

    def test_GernderSource_term_invalid(self):
        term_inv = self.terms.getTerm('Invalid')
        assert term_inv.title is None
        assert term_inv.token == 'i'

def suite():
    suite = unittest.TestSuite()
    for testcase in [
            ApplicationCategoriesTestCase,
            InterfacesTest,
            ]:
        suite.addTests(unittest.TestLoader().loadTestsFromTestCase(testcase))
    return suite

test_suite = suite


