##
## test_interfaces.py
## Login : <uli@pu.smp.net>
## Started on  Mon Aug 23 01:59:52 2010 Uli Fouquet
## $Id$
## 
## Copyright (C) 2010 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
##
"""Tests for jambtable interfaces.
"""
import unittest
from zc.sourcefactory.browser.source import FactoredTerms
from zope.browser.interfaces import ITerms
from zope.component import getMultiAdapter
from zope.publisher.browser import TestRequest
from waeup.sirp.jambtables.interfaces import GenderSource

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 test_suite():
    suite = unittest.TestSuite()
    for testcase in [
        InterfacesTest,
        ]:
        suite.addTest(unittest.TestLoader().loadTestsFromTestCase(
                testcase
                )
        )
    return suite

