launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #04664
[Merge] lp:~wallyworld/launchpad/vocab-searchforterms-filter-2 into lp:launchpad
Ian Booth has proposed merging lp:~wallyworld/launchpad/vocab-searchforterms-filter-2 into lp:launchpad with lp:~wallyworld/launchpad/vocab-searchforterms-filter-1 as a prerequisite.
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
Related bugs:
Bug #828447 in Launchpad itself: "Add vocab filtering using named filters"
https://bugs.launchpad.net/launchpad/+bug/828447
For more details, see:
https://code.launchpad.net/~wallyworld/launchpad/vocab-searchforterms-filter-2/+merge/71968
This branch implements the vocab_filter functionality speced out in the previous branch.
The next step will be to wire up the pickers to use this new functionality.
== Implementation ==
Simply provide code for the various filter_terms() methods.
The vocabs which have implemented filters are:
- DistributionOrProductOrProjectGroupVocabulary and it's subclass FeaturedProjectVocabulary
- DistributionOrProductVocabulary
The implemented filters are:
- VocabularyFilterAll
- VocabularyFilterProject
- VocabularyFilterProjectGroup
- VocabularyFilterDistribution
== Tests ==
Add tests to TestDistributionOrProductVocabulary and TestDistributionOrProductOrProjectGroupVocabulary
- test_project_filter()
- test_projectgroup_filter()
- test_projectdistribution_filter()
== Lint ==
Checking for conflicts and issues in changed files.
Linting changed files:
lib/lp/registry/vocabularies.py
lib/lp/registry/tests/test_pillar_vocabularies.py
--
https://code.launchpad.net/~wallyworld/launchpad/vocab-searchforterms-filter-2/+merge/71968
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~wallyworld/launchpad/vocab-searchforterms-filter-2 into lp:launchpad.
=== modified file 'lib/lp/registry/tests/test_pillar_vocabularies.py'
--- lib/lp/registry/tests/test_pillar_vocabularies.py 2011-08-18 00:51:50 +0000
+++ lib/lp/registry/tests/test_pillar_vocabularies.py 2011-08-18 00:51:51 +0000
@@ -62,7 +62,31 @@
[self.project_group, self.product, self.distribution], result)
-class TestDistributionOrProductVocabulary(TestCaseWithFactory):
+class VocabFilterMixin:
+
+ def _test_distribution_filter(self):
+ # Only distributions should be included in the search results.
+ terms = self.vocabulary.searchForTerms('snark', vocab_filter='DISTRO')
+ result = [term.value for term in terms]
+ self.assertEqual([self.distribution], result)
+
+ def _test_project_filter(self):
+ # Only projects should be included in the search results.
+ terms = self.vocabulary.searchForTerms(
+ 'snark', vocab_filter='PROJECT')
+ result = [term.value for term in terms]
+ self.assertEqual([self.product], result)
+
+ def _test_projectgroup_filter(self):
+ # Only project groups should be included in the search results.
+ terms = self.vocabulary.searchForTerms(
+ 'snark', vocab_filter='PROJECTGROUP')
+ result = [term.value for term in terms]
+ self.assertEqual([self.project_group], result)
+
+
+class TestDistributionOrProductVocabulary(TestCaseWithFactory,
+ VocabFilterMixin):
"""Test that the ProductVocabulary behaves as expected."""
layer = DatabaseFunctionalLayer
@@ -82,6 +106,12 @@
self.vocabulary.supportedFilters()
)
+ def test_project_filter(self):
+ self._test_project_filter()
+
+ def test_distribution_filter(self):
+ self._test_distribution_filter()
+
def test_inactive_products_are_excluded(self):
# Inactive product are not in the vocabulary.
with celebrity_logged_in('registry_experts'):
@@ -100,7 +130,8 @@
self.assertFalse(project_group in self.vocabulary)
-class TestDistributionOrProductOrProjectGroupVocabulary(TestCaseWithFactory):
+class TestDistributionOrProductOrProjectGroupVocabulary(TestCaseWithFactory,
+ VocabFilterMixin):
"""Test for DistributionOrProductOrProjectGroupVocabulary."""
layer = DatabaseFunctionalLayer
@@ -122,6 +153,15 @@
self.vocabulary.supportedFilters()
)
+ def test_project_filter(self):
+ self._test_project_filter()
+
+ def test_projectgroup_filter(self):
+ self._test_projectgroup_filter()
+
+ def test_distribution_filter(self):
+ self._test_distribution_filter()
+
def test_contains_all_pillars_active(self):
# All active products, project groups and distributions are included.
self.assertTrue(self.product in self.vocabulary)
=== modified file 'lib/lp/registry/vocabularies.py'
--- lib/lp/registry/vocabularies.py 2011-08-18 00:51:50 +0000
+++ lib/lp/registry/vocabularies.py 2011-08-18 00:51:51 +0000
@@ -1951,6 +1951,10 @@
cls, 'PROJECT', 'Project',
'Display search results associated with projects')
+ @property
+ def filter_terms(self):
+ return [PillarName.product != None]
+
class VocabularyFilterProjectGroup(VocabularyFilter):
# A filter returning just project groups.
@@ -1960,6 +1964,10 @@
cls, 'PROJECTGROUP', 'Project Group',
'Display search results associated with project groups')
+ @property
+ def filter_terms(self):
+ return [PillarName.project != None]
+
class VocabularyFilterDistribution(VocabularyFilter):
# A filter returning just distros.
@@ -1969,6 +1977,10 @@
cls, 'DISTRO', 'Distribution',
'Display search results associated with distributions')
+ @property
+ def filter_terms(self):
+ return [PillarName.distribution != None]
+
class PillarVocabularyBase(NamedSQLObjectHugeVocabulary):
"""Active `IPillar` objects vocabulary."""
@@ -2018,6 +2030,9 @@
if self._filter:
equal_clauses.extend(self._filter)
like_clauses.extend(self._filter)
+ if vocab_filter:
+ equal_clauses.extend(vocab_filter.filter_terms)
+ like_clauses.extend(vocab_filter.filter_terms)
ranked_results = store.execute(
Union(
Select(