class TestBinaryAndSourcePackageNameVocabulary(TestCaseWithFactory):
    """Test that the ProductVocabulary behaves as expected."""
    layer = DatabaseFunctionalLayer

    def setUp(self):
        super(TestBinaryAndSourcePackageNameVocabulary, self).setUp()
        self.vocabulary = BinaryAndSourcePackageNameVocabulary()
        spn = self.factory.makeSourcePackageName(name='bedbugs')
        self.bspn = Store.of(spn).find(
            BinaryAndSourcePackageName, name=spn.name).one()

    def test_toTerm(self):
        # Binary and source package name terms are composed of name,
        # and the bspn.
        term = self.vocabulary.toTerm(self.bspn)
        self.assertEqual(self.bspn.name, term.title)
        self.assertEqual(self.bspn.name, term.token)
        self.assertEqual(self.bspn, term.value)

    def test_getTermByToken(self):
        # Tokens are case insentive because the name is lowercase.
        term = self.vocabulary.getTermByToken('BedBUGs')
        self.assertEqual(self.bspn, term.value)

    def test_getTermByToken_LookupError(self):
        # getTermByToken() raises a LookupError when no match is found.
        self.assertRaises(
            LookupError,
            self.vocabulary.getTermByToken, 'does-notexist')
 def setUp(self):
     super(TestBinaryAndSourcePackageNameVocabulary, self).setUp()
     self.vocabulary = BinaryAndSourcePackageNameVocabulary()
     spn = self.factory.makeSourcePackageName(name='bedbugs')
     self.bspn = Store.of(spn).find(
         BinaryAndSourcePackageName, name=spn.name).one()