class TestBranchVocabulary(TestCaseWithFactory): """Test that the BranchVocabulary behaves as expected.""" layer = DatabaseFunctionalLayer def setUp(self): super(TestBranchVocabulary, self).setUp() self._createBranches() self.vocab = BranchVocabulary(context=None) def _createBranches(self): widget = self.factory.makeProduct(name='widget') sprocket = self.factory.makeProduct(name='sprocket') scotty = self.factory.makePerson(name='scotty') self.factory.makeProductBranch(owner=scotty, product=widget, name='fizzbuzz') self.factory.makeProductBranch(owner=scotty, product=widget, name='mountain') self.factory.makeProductBranch(owner=scotty, product=sprocket, name='fizzbuzz') def test_fizzbuzzBranches(self): """Return branches that match the string 'fizzbuzz'.""" results = self.vocab.searchForTerms('fizzbuzz') expected = [u'~scotty/sprocket/fizzbuzz', u'~scotty/widget/fizzbuzz'] branch_names = sorted([branch.token for branch in results]) self.assertEqual(expected, branch_names) def test_singleQueryResult(self): # If there is a single search result that matches, use that # as the result. term = self.vocab.getTermByToken('mountain') self.assertEqual('~scotty/widget/mountain', term.value.unique_name) def test_multipleQueryResult(self): # If there are more than one search result, a LookupError is still # raised. self.assertRaises(LookupError, self.vocab.getTermByToken, 'fizzbuzz')
class TestBranchVocabulary(TestCaseWithFactory): """Test that the BranchVocabulary behaves as expected.""" layer = DatabaseFunctionalLayer def setUp(self): super(TestBranchVocabulary, self).setUp() self._createBranches() self.vocab = BranchVocabulary(context=None) def _createBranches(self): widget = self.factory.makeProduct(name='widget') sprocket = self.factory.makeProduct(name='sprocket') scotty = self.factory.makePerson(name='scotty') self.factory.makeProductBranch( owner=scotty, product=widget, name='fizzbuzz') self.factory.makeProductBranch( owner=scotty, product=widget, name='mountain') self.factory.makeProductBranch( owner=scotty, product=sprocket, name='fizzbuzz') def test_fizzbuzzBranches(self): """Return branches that match the string 'fizzbuzz'.""" results = self.vocab.searchForTerms('fizzbuzz') expected = [ u'~scotty/sprocket/fizzbuzz', u'~scotty/widget/fizzbuzz'] branch_names = sorted([branch.token for branch in results]) self.assertEqual(expected, branch_names) def test_singleQueryResult(self): # If there is a single search result that matches, use that # as the result. term = self.vocab.getTermByToken('mountain') self.assertEqual('~scotty/widget/mountain', term.value.unique_name) def test_multipleQueryResult(self): # If there are more than one search result, a LookupError is still # raised. self.assertRaises(LookupError, self.vocab.getTermByToken, 'fizzbuzz')