~launchpad-pqm/launchpad/devel

« back to all changes in this revision

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

  • Committer: Launchpad Patch Queue Manager
  • Date: 2010-09-02 21:26:51 UTC
  • mfrom: (11475.2.5 bug-154587)
  • Revision ID: launchpad@pqm.canonical.com-20100902212651-t6wgayawe9c3cm1y
[r=michael.nelson][ui=none][bug=154587] Catch
        CyclicalTeamMembershipError when accepting invitations and
        report error.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright 2010 Canonical Ltd.  This software is licensed under the
 
2
# GNU Affero General Public License version 3 (see the file LICENSE).
 
3
 
 
4
"""Test team membership changes."""
 
5
 
 
6
from __future__ import with_statement
 
7
 
 
8
__metaclass__ = type
 
9
 
 
10
from canonical.testing import DatabaseFunctionalLayer
 
11
from lp.registry.interfaces.teammembership import CyclicalTeamMembershipError
 
12
from lp.testing import (
 
13
    person_logged_in,
 
14
    TestCaseWithFactory,
 
15
    )
 
16
 
 
17
 
 
18
class CircularMemberAdditionTestCase(TestCaseWithFactory):
 
19
    layer = DatabaseFunctionalLayer
 
20
 
 
21
    def setUp(self):
 
22
        super(CircularMemberAdditionTestCase, self).setUp()
 
23
        self.a_team = self.factory.makeTeam(name="a")
 
24
        self.b_team = self.factory.makeTeam(name="b")
 
25
 
 
26
    def test_circular_invite(self):
 
27
        """Two teams can invite each other without horrifying results."""
 
28
        # Make the criss-cross invitations.
 
29
        with person_logged_in(self.a_team.teamowner):
 
30
            self.a_team.addMember(self.b_team, self.a_team.teamowner)
 
31
        with person_logged_in(self.b_team.teamowner):
 
32
            self.b_team.addMember(self.a_team, self.b_team.teamowner)
 
33
 
 
34
        # A-team accepts B's kind invitation.
 
35
        with person_logged_in(self.a_team.teamowner):
 
36
            self.a_team.acceptInvitationToBeMemberOf(
 
37
                self.b_team, None)
 
38
        # B-team accepts A's kind invitation.
 
39
        with person_logged_in(self.b_team.teamowner):
 
40
            self.assertRaises(
 
41
                CyclicalTeamMembershipError,
 
42
                self.b_team.acceptInvitationToBeMemberOf,
 
43
                self.a_team, None)