class TestPillarVocabularyBase(TestCaseWithFactory): """Test that the PillarVocabularyBase behaves as expected.""" layer = DatabaseFunctionalLayer def setUp(self): super(TestPillarVocabularyBase, self).setUp() self.vocabulary = PillarVocabularyBase() self.product = self.factory.makeProduct(name='orchid-snark') self.distribution = self.factory.makeDistribution(name='zebra-snark') self.project_group = self.factory.makeProject(name='apple-snark') def test_supported_filters(self): # The vocab supports the correct filters. self.assertEqual([ PillarVocabularyBase.ALL_FILTER], self.vocabulary.supportedFilters() ) def test_Product_toTerm(self): # Product terms are composed of title, name, and the object. term = self.vocabulary.toTerm(self.product) self.assertEqual(self.product.title, term.title) self.assertEqual(self.product.name, term.token) self.assertEqual(self.product, term.value) def test_ProjectGroup_toTerm(self): # ProductGroup terms are composed of title, name, and the object. term = self.vocabulary.toTerm(self.project_group) self.assertEqual(self.project_group.title, term.title) self.assertEqual(self.project_group.name, term.token) self.assertEqual(self.project_group, term.value) def test_getTermByToken(self): # Tokens are case insentive because the product name is lowercase. term = self.vocabulary.getTermByToken('ORCHID-SNARK') self.assertEqual(self.product, 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 test_ordering(self): # Results are ordered by rank, with exact matches first. terms = self.vocabulary.searchForTerms('snark') result = [term.value for term in terms] self.assertEqual( [self.project_group, self.product, self.distribution], result)
class TestPillarVocabularyBase(TestCaseWithFactory): """Test that the PillarVocabularyBase behaves as expected.""" layer = DatabaseFunctionalLayer def setUp(self): super(TestPillarVocabularyBase, self).setUp() self.vocabulary = PillarVocabularyBase() self.product = self.factory.makeProduct(name="orchid-snark") self.distribution = self.factory.makeDistribution(name="zebra-snark") self.project_group = self.factory.makeProject(name="apple-snark") def test_supported_filters(self): # The vocab supports the correct filters. self.assertEqual([PillarVocabularyBase.ALL_FILTER], self.vocabulary.supportedFilters()) def test_Product_toTerm(self): # Product terms are composed of title, name, and the object. term = self.vocabulary.toTerm(self.product) self.assertEqual(self.product.title, term.title) self.assertEqual(self.product.name, term.token) self.assertEqual(self.product, term.value) def test_ProjectGroup_toTerm(self): # ProductGroup terms are composed of title, name, and the object. term = self.vocabulary.toTerm(self.project_group) self.assertEqual(self.project_group.title, term.title) self.assertEqual(self.project_group.name, term.token) self.assertEqual(self.project_group, term.value) def test_getTermByToken(self): # Tokens are case insentive because the product name is lowercase. term = self.vocabulary.getTermByToken("ORCHID-SNARK") self.assertEqual(self.product, 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 test_ordering(self): # Results are ordered by rank, with exact matches first. terms = self.vocabulary.searchForTerms("snark") result = [term.value for term in terms] self.assertEqual([self.project_group, self.product, self.distribution], result)
def setUp(self): super(TestPillarVocabularyBase, self).setUp() self.vocabulary = PillarVocabularyBase() self.product = self.factory.makeProduct(name="orchid-snark") self.distribution = self.factory.makeDistribution(name="zebra-snark") self.project_group = self.factory.makeProject(name="apple-snark")
def setUp(self): super(TestPillarVocabularyBase, self).setUp() self.vocabulary = PillarVocabularyBase() self.product = self.factory.makeProduct(name='orchid-snark') self.distribution = self.factory.makeDistribution(name='zebra-snark') self.project_group = self.factory.makeProject(name='apple-snark')