~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/registry/tests/test_person_vocabularies.py

Merged replication into pending-db-changes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
from lp.registry.interfaces.person import (
22
22
    PersonVisibility,
23
23
    TeamSubscriptionPolicy,
 
24
    CLOSED_TEAM_POLICY,
 
25
    OPEN_TEAM_POLICY,
24
26
    )
25
27
from lp.registry.interfaces.karma import IKarmaCacheManager
26
28
from lp.registry.vocabularies import ValidPersonOrTeamVocabulary
51
53
        return removeSecurityProxy(vocabulary).search(text, vocab_filter)
52
54
 
53
55
 
54
 
class TestValidPersonOrTeamVocabulary(VocabularyTestBase,
55
 
                                      TestCaseWithFactory):
56
 
    """Test that the ValidPersonOrTeamVocabulary behaves as expected.
57
 
 
58
 
    Most tests are in lib/lp/registry/doc/vocabularies.txt.
59
 
    """
60
 
 
61
 
    layer = LaunchpadZopelessLayer
62
 
    vocabulary_name = 'ValidPersonOrTeam'
 
56
class ValidPersonOrTeamVocabularyMixin(VocabularyTestBase):
 
57
    """Common tests for the ValidPersonOrTeam vocabulary derivatives."""
63
58
 
64
59
    def test_supported_filters(self):
65
60
        # The vocab supports the correct filters.
156
151
            name="fredteam", email="fredteam@foo.com")
157
152
        self._person_filter_tests(person)
158
153
 
159
 
    def _team_filter_tests(self, team):
 
154
    def _team_filter_tests(self, teams):
160
155
        results = self.searchVocabulary(None, '', 'TEAM')
161
156
        for personorteam in results:
162
157
            self.assertTrue(personorteam.is_team)
163
158
        results = self.searchVocabulary(None, u'fred', 'TEAM')
164
 
        self.assertEqual([team], list(results))
 
159
        self.assertContentEqual(teams, list(results))
 
160
 
 
161
 
 
162
class TestValidPersonOrTeamVocabulary(ValidPersonOrTeamVocabularyMixin,
 
163
                                      TestCaseWithFactory):
 
164
    """Test that the ValidPersonOrTeamVocabulary behaves as expected.
 
165
 
 
166
    Most tests are in lib/lp/registry/doc/vocabularies.txt.
 
167
    """
 
168
 
 
169
    layer = LaunchpadZopelessLayer
 
170
    vocabulary_name = 'ValidPersonOrTeam'
165
171
 
166
172
    def test_team_filter(self):
167
173
        # Test that the team filter only returns teams.
169
175
            name="fredperson", email="fredperson@foo.com")
170
176
        team = self.factory.makeTeam(
171
177
            name="fredteam", email="fredteam@foo.com")
172
 
        self._team_filter_tests(team)
173
 
        self._team_filter_tests(team)
 
178
        self._team_filter_tests([team])
174
179
 
175
180
 
176
181
class TestValidPersonOrTeamPreloading(VocabularyTestBase,
209
214
        self.assertThat(recorder, HasQueryCount(Equals(0)))
210
215
 
211
216
 
 
217
class TestValidPersonOrClosedTeamVocabulary(ValidPersonOrTeamVocabularyMixin,
 
218
                                            TestCaseWithFactory):
 
219
    """Test that the ValidPersonOrClosedTeamVocabulary behaves as expected."""
 
220
 
 
221
    layer = LaunchpadZopelessLayer
 
222
    vocabulary_name = 'ValidPillarOwner'
 
223
 
 
224
    def test_team_filter(self):
 
225
        # Test that the team filter only returns closed teams.
 
226
        self.factory.makePerson(
 
227
            name="fredperson", email="fredperson@foo.com")
 
228
        for policy in OPEN_TEAM_POLICY:
 
229
            self.factory.makeTeam(
 
230
                name="fred%s" % policy.name.lower(),
 
231
                email="team_%s@foo.com" % policy.name,
 
232
                subscription_policy=policy)
 
233
        closed_teams = []
 
234
        for policy in CLOSED_TEAM_POLICY:
 
235
            closed_teams.append(self.factory.makeTeam(
 
236
                name="fred%s" % policy.name.lower(),
 
237
                email="team_%s@foo.com" % policy.name,
 
238
                subscription_policy=policy))
 
239
        self._team_filter_tests(closed_teams)
 
240
 
 
241
 
212
242
class TeamMemberVocabularyTestBase(VocabularyTestBase):
213
243
 
214
244
    def test_open_team_cannot_be_a_member_of_a_closed_team(self):