class TestForgivingSimpleVocabulary(TestCase):
    """Tests for ForgivingSimpleVocabulary."""
    def setUp(self):
        super(TestForgivingSimpleVocabulary, self).setUp()
        self.term_1 = SimpleTerm('term-1', 'term-1', 'My first term')
        self.term_2 = SimpleTerm('term-2', 'term-2', 'My second term')
        self.vocabulary = ForgivingSimpleVocabulary(
            terms=[self.term_1, self.term_2], default_term=self.term_2)

    def test_normal_lookup(self):
        """Lookups for proper values succeed."""
        self.assertIs(self.vocabulary.getTerm('term-1'), self.term_1)

    def test_errant_lookup(self):
        """Lookups for invalid values return the default."""
        self.assertIs(self.vocabulary.getTerm('does-not-exist'), self.term_2)
class TestForgivingSimpleVocabulary(TestCase):
    """Tests for ForgivingSimpleVocabulary."""

    def setUp(self):
        super(TestForgivingSimpleVocabulary, self).setUp()
        self.term_1 = SimpleTerm('term-1', 'term-1', 'My first term')
        self.term_2 = SimpleTerm('term-2', 'term-2', 'My second term')
        self.vocabulary = ForgivingSimpleVocabulary(
            terms=[self.term_1, self.term_2], default_term=self.term_2)

    def test_normal_lookup(self):
        """Lookups for proper values succeed."""
        self.assertIs(self.vocabulary.getTerm('term-1'), self.term_1)

    def test_errant_lookup(self):
        """Lookups for invalid values return the default."""
        self.assertIs(self.vocabulary.getTerm('does-not-exist'), self.term_2)
    def __call__(self, context):
        file_extensions = ('po', 'pot')
        all_files = SimpleTerm('all', 'all', 'All files')
        terms = [all_files]
        for extension in file_extensions:
            title = 'Only %s files' % extension
            terms.append(SimpleTerm(extension, extension, title))

        # We use a ForgivingSimpleVocabulary because we don't care if a user
        # provides an invalid value.  If they do we just ignore it and show
        # them all files.
        return ForgivingSimpleVocabulary(terms, default_term=all_files)
 def setUp(self):
     super(TestForgivingSimpleVocabulary, self).setUp()
     self.term_1 = SimpleTerm('term-1', 'term-1', 'My first term')
     self.term_2 = SimpleTerm('term-2', 'term-2', 'My second term')
     self.vocabulary = ForgivingSimpleVocabulary(
         terms=[self.term_1, self.term_2], default_term=self.term_2)
 def setUp(self):
     super(TestForgivingSimpleVocabulary, self).setUp()
     self.term_1 = SimpleTerm('term-1', 'term-1', 'My first term')
     self.term_2 = SimpleTerm('term-2', 'term-2', 'My second term')
     self.vocabulary = ForgivingSimpleVocabulary(
         terms=[self.term_1, self.term_2], default_term=self.term_2)