예제 #1
0
    def invalidate_group_pending_terms(self, mail_task):
        """Invalidate a group where a user has not yet accepted the terms.

        Type is indifferent for this test.
        """
        member = UserFactory.create(vouched=True)
        curator = UserFactory.create(vouched=True)

        group = GroupFactory.create(name='Foo', invalidation_days=5)
        group.curators.add(curator.userprofile)
        group.add_member(curator.userprofile)
        GroupMembership.objects.create(userprofile=member.userprofile, group=group,
                                       status=GroupMembership.PENDING_TERMS,
                                       updated_on=datetime.now() - timedelta(days=10))

        curator_membership = group.groupmembership_set.filter(userprofile=curator.userprofile)
        curator_membership.update(updated_on=datetime.now() - timedelta(days=10))

        eq_(curator_membership[0].status, GroupMembership.MEMBER)

        invalidate_group_membership()

        ok_(group.groupmembership_set.filter(userprofile=member.userprofile,
                                             status=GroupMembership.PENDING_TERMS).exists())
        ok_(group.groupmembership_set.filter(userprofile=curator.userprofile).exists())
        ok_(not mail_task.called)
예제 #2
0
    def test_invalidate_group_accepts_all(self, mock_send_mail):
        member = UserFactory.create(vouched=True)
        curator = UserFactory.create(vouched=True)

        group = GroupFactory.create(name='Foo', invalidation_days=5)
        group.curators.add(curator.userprofile)
        group.add_member(curator.userprofile)
        group.add_member(member.userprofile)

        membership = group.groupmembership_set.filter(userprofile=member.userprofile)
        curator_membership = group.groupmembership_set.filter(userprofile=curator.userprofile)
        membership.update(updated_on=datetime.now() - timedelta(days=10))
        curator_membership.update(updated_on=datetime.now() - timedelta(days=10))

        eq_(membership[0].status, GroupMembership.MEMBER)
        eq_(curator_membership[0].status, GroupMembership.MEMBER)

        invalidate_group_membership()

        ok_(not group.groupmembership_set.filter(userprofile=member.userprofile).exists())
        ok_(group.groupmembership_set.filter(userprofile=curator.userprofile).exists())

        subject = 'Removed from Mozillians group "foo"'
        mock_send_mail.assert_called_once_with(subject, ANY, '*****@*****.**',
                                               [member.email], fail_silently=False)
예제 #3
0
    def test_invalidate_open_group(self, mail_task):
        member = UserFactory.create(vouched=True)
        curator = UserFactory.create(vouched=True)

        # Group of type Group.OPEN
        group = GroupFactory.create(name='Foo', terms='Example terms.', invalidation_days=5,
                                    accepting_new_members=Group.OPEN)
        group.curators.add(curator.userprofile)
        group.add_member(member.userprofile)
        group.add_member(curator.userprofile)

        membership = group.groupmembership_set.filter(userprofile=member.userprofile)
        curator_membership = group.groupmembership_set.filter(userprofile=curator.userprofile)
        membership.update(updated_on=datetime.now() - timedelta(days=10))
        curator_membership.update(updated_on=datetime.now() - timedelta(days=10))

        eq_(membership[0].status, GroupMembership.MEMBER)
        eq_(curator_membership[0].status, GroupMembership.MEMBER)

        invalidate_group_membership()

        ok_(not group.groupmembership_set.filter(userprofile=member.userprofile).exists())
        ok_(group.groupmembership_set.filter(userprofile=curator.userprofile).exists())

        mail_task.delay.assert_called_once_with(group.id, member.id, GroupMembership.MEMBER, None)
예제 #4
0
    def test_invalidate_group_by_request(self, mocked_waffle_switch):
        mocked_waffle_switch.return_value = False
        member = UserFactory.create(vouched=True)
        curator = UserFactory.create(vouched=True)

        group = GroupFactory.create(invalidation_days=5,
                                    accepting_new_members='by_request')
        group.curators.add(curator.userprofile)
        group.add_member(curator.userprofile)
        group.add_member(member.userprofile)

        membership = group.groupmembership_set.filter(
            userprofile=member.userprofile)
        curator_membership = group.groupmembership_set.filter(
            userprofile=curator.userprofile)
        membership.update(updated_on=datetime.now() - timedelta(days=10))
        curator_membership.update(updated_on=datetime.now() -
                                  timedelta(days=10))

        eq_(membership[0].status, GroupMembership.MEMBER)
        eq_(curator_membership[0].status, GroupMembership.MEMBER)

        invalidate_group_membership()

        membership = group.groupmembership_set.get(
            userprofile=member.userprofile)
        curator_membership = group.groupmembership_set.get(
            userprofile=curator.userprofile)
        eq_(membership.status, GroupMembership.PENDING)
        eq_(curator_membership.status, GroupMembership.MEMBER)
예제 #5
0
    def test_invalidate_group_accepts_all(self, mocked_waffle_switch):
        mocked_waffle_switch.return_value = False
        member = UserFactory.create(vouched=True)
        curator = UserFactory.create(vouched=True)

        group = GroupFactory.create(invalidation_days=5)
        group.curators.add(curator.userprofile)
        group.add_member(curator.userprofile)
        group.add_member(member.userprofile)

        membership = group.groupmembership_set.filter(
            userprofile=member.userprofile)
        curator_membership = group.groupmembership_set.filter(
            userprofile=curator.userprofile)
        membership.update(updated_on=datetime.now() - timedelta(days=10))
        curator_membership.update(updated_on=datetime.now() -
                                  timedelta(days=10))

        eq_(membership[0].status, GroupMembership.MEMBER)
        eq_(curator_membership[0].status, GroupMembership.MEMBER)

        invalidate_group_membership()

        ok_(not group.groupmembership_set.filter(
            userprofile=member.userprofile).exists())
        ok_(
            group.groupmembership_set.filter(
                userprofile=curator.userprofile).exists())
예제 #6
0
    def invalidate_group_pending_terms(self, mail_task):
        """Invalidate a group where a user has not yet accepted the terms.

        Type is indifferent for this test.
        """
        member = UserFactory.create(vouched=True)
        curator = UserFactory.create(vouched=True)

        group = GroupFactory.create(name='Foo', invalidation_days=5)
        group.curators.add(curator.userprofile)
        group.add_member(curator.userprofile)
        GroupMembership.objects.create(userprofile=member.userprofile,
                                       group=group,
                                       status=GroupMembership.PENDING_TERMS,
                                       updated_on=datetime.now() -
                                       timedelta(days=10))

        curator_membership = group.groupmembership_set.filter(
            userprofile=curator.userprofile)
        curator_membership.update(updated_on=datetime.now() -
                                  timedelta(days=10))

        eq_(curator_membership[0].status, GroupMembership.MEMBER)

        invalidate_group_membership()

        ok_(
            group.groupmembership_set.filter(
                userprofile=member.userprofile,
                status=GroupMembership.PENDING_TERMS).exists())
        ok_(
            group.groupmembership_set.filter(
                userprofile=curator.userprofile).exists())
        ok_(not mail_task.called)
예제 #7
0
    def test_invalidate_group_with_terms(self, mocked_waffle_switch):
        mocked_waffle_switch.return_value = False
        member = UserFactory.create(vouched=True)
        curator = UserFactory.create(vouched=True)

        group = GroupFactory.create(terms='Example terms.',
                                    invalidation_days=5)
        group.curators.add(curator.userprofile)
        group.add_member(member.userprofile)
        group.add_member(curator.userprofile)

        membership = group.groupmembership_set.filter(
            userprofile=member.userprofile)
        curator_membership = group.groupmembership_set.filter(
            userprofile=curator.userprofile)
        membership.update(updated_on=datetime.now() - timedelta(days=10))
        curator_membership.update(updated_on=datetime.now() -
                                  timedelta(days=10))

        eq_(membership[0].status, GroupMembership.MEMBER)
        eq_(curator_membership[0].status, GroupMembership.MEMBER)

        invalidate_group_membership()

        membership = group.groupmembership_set.get(
            userprofile=member.userprofile)
        curator_membership = group.groupmembership_set.get(
            userprofile=curator.userprofile)
        eq_(membership.status, GroupMembership.PENDING_TERMS)
        eq_(curator_membership.status, GroupMembership.MEMBER)
예제 #8
0
    def invalidate_closed_group(self, mail_task):
        member = UserFactory.create(vouched=True)
        curator = UserFactory.create(vouched=True)

        group = GroupFactory.create(name='Foo', invalidation_days=5,
                                    accepting_new_members=Group.CLOSED)
        group.curators.add(curator.userprofile)
        group.add_member(curator.userprofile)
        group.add_member(member.userprofile)

        membership = group.groupmembership_set.filter(userprofile=member.userprofile)
        curator_membership = group.groupmembership_set.filter(userprofile=curator.userprofile)
        membership.update(updated_on=datetime.now() - timedelta(days=10))
        curator_membership.update(updated_on=datetime.now() - timedelta(days=10))

        eq_(membership[0].status, GroupMembership.MEMBER)
        eq_(curator_membership[0].status, GroupMembership.MEMBER)

        invalidate_group_membership()

        ok_(group.groupmembership_set.filter(userprofile=member.userprofile,
                                             status=GroupMembership.PENDING).exists())
        ok_(group.groupmembership_set.filter(userprofile=curator.userprofile).exists())

        mail_task.delay.assert_called_once_with(group.id, member.id, GroupMembership.MEMBER,
                                                GroupMembership.PENDING)
예제 #9
0
    def invalidate_closed_group(self, mail_task):
        member = UserFactory.create(vouched=True)
        curator = UserFactory.create(vouched=True)

        group = GroupFactory.create(name='Foo',
                                    invalidation_days=5,
                                    accepting_new_members=Group.CLOSED)
        group.curators.add(curator.userprofile)
        group.add_member(curator.userprofile)
        group.add_member(member.userprofile)

        membership = group.groupmembership_set.filter(
            userprofile=member.userprofile)
        curator_membership = group.groupmembership_set.filter(
            userprofile=curator.userprofile)
        membership.update(updated_on=datetime.now() - timedelta(days=10))
        curator_membership.update(updated_on=datetime.now() -
                                  timedelta(days=10))

        eq_(membership[0].status, GroupMembership.MEMBER)
        eq_(curator_membership[0].status, GroupMembership.MEMBER)

        invalidate_group_membership()

        ok_(
            group.groupmembership_set.filter(
                userprofile=member.userprofile,
                status=GroupMembership.PENDING).exists())
        ok_(
            group.groupmembership_set.filter(
                userprofile=curator.userprofile).exists())

        mail_task.delay.assert_called_once_with(group.id, member.id,
                                                GroupMembership.MEMBER,
                                                GroupMembership.PENDING)
예제 #10
0
    def test_invalidate_open_group(self, mail_task):
        member = UserFactory.create(vouched=True)
        curator = UserFactory.create(vouched=True)

        # Group of type Group.OPEN
        group = GroupFactory.create(name='Foo',
                                    terms='Example terms.',
                                    invalidation_days=5,
                                    accepting_new_members=Group.OPEN)
        group.curators.add(curator.userprofile)
        group.add_member(member.userprofile)
        group.add_member(curator.userprofile)

        membership = group.groupmembership_set.filter(
            userprofile=member.userprofile)
        curator_membership = group.groupmembership_set.filter(
            userprofile=curator.userprofile)
        membership.update(updated_on=datetime.now() - timedelta(days=10))
        curator_membership.update(updated_on=datetime.now() -
                                  timedelta(days=10))

        eq_(membership[0].status, GroupMembership.MEMBER)
        eq_(curator_membership[0].status, GroupMembership.MEMBER)

        invalidate_group_membership()

        ok_(not group.groupmembership_set.filter(
            userprofile=member.userprofile).exists())
        ok_(
            group.groupmembership_set.filter(
                userprofile=curator.userprofile).exists())

        mail_task.delay.assert_called_once_with(group.id, member.id,
                                                GroupMembership.MEMBER, None)
예제 #11
0
 def test_invalidate_group_accepts_all(self):
     group = GroupFactory.create(invalidation_days=5)
     user = UserFactory.create()
     group.add_member(user.userprofile)
     membership = group.groupmembership_set.filter(userprofile=user.userprofile)
     membership.update(updated_on=datetime.now() - timedelta(days=10))
     eq_(membership[0].status, GroupMembership.MEMBER)
     invalidate_group_membership()
     ok_(not group.groupmembership_set.filter(userprofile=user.userprofile).exists())
예제 #12
0
 def test_invalidate_group_by_request(self):
     group = GroupFactory.create(invalidation_days=5, accepting_new_members='by_request')
     user = UserFactory.create()
     group.add_member(user.userprofile)
     membership = group.groupmembership_set.filter(userprofile=user.userprofile)
     membership.update(updated_on=datetime.now() - timedelta(days=10))
     eq_(membership[0].status, GroupMembership.MEMBER)
     invalidate_group_membership()
     membership = group.groupmembership_set.get(userprofile=user.userprofile)
     eq_(membership.status, GroupMembership.PENDING)
예제 #13
0
 def test_invalidate_group_with_terms(self):
     group = GroupFactory.create(terms='Example terms.', invalidation_days=5)
     user = UserFactory.create()
     group.add_member(user.userprofile)
     membership = group.groupmembership_set.filter(userprofile=user.userprofile)
     membership.update(updated_on=datetime.now() - timedelta(days=10))
     eq_(membership[0].status, GroupMembership.MEMBER)
     invalidate_group_membership()
     membership = group.groupmembership_set.get(userprofile=user.userprofile)
     eq_(membership.status, GroupMembership.PENDING_TERMS)
예제 #14
0
 def test_invalidate_group_accepts_all(self):
     group = GroupFactory.create(invalidation_days=5)
     user = UserFactory.create()
     group.add_member(user.userprofile)
     membership = group.groupmembership_set.filter(
         userprofile=user.userprofile)
     membership.update(updated_on=datetime.now() - timedelta(days=10))
     eq_(membership[0].status, GroupMembership.MEMBER)
     invalidate_group_membership()
     ok_(not group.groupmembership_set.filter(
         userprofile=user.userprofile).exists())
예제 #15
0
 def test_invalidate_group_by_request(self):
     group = GroupFactory.create(invalidation_days=5,
                                 accepting_new_members='by_request')
     user = UserFactory.create()
     group.add_member(user.userprofile)
     membership = group.groupmembership_set.filter(
         userprofile=user.userprofile)
     membership.update(updated_on=datetime.now() - timedelta(days=10))
     eq_(membership[0].status, GroupMembership.MEMBER)
     invalidate_group_membership()
     membership = group.groupmembership_set.get(
         userprofile=user.userprofile)
     eq_(membership.status, GroupMembership.PENDING)
예제 #16
0
 def test_invalidate_group_with_terms(self):
     group = GroupFactory.create(terms='Example terms.',
                                 invalidation_days=5)
     user = UserFactory.create()
     group.add_member(user.userprofile)
     membership = group.groupmembership_set.filter(
         userprofile=user.userprofile)
     membership.update(updated_on=datetime.now() - timedelta(days=10))
     eq_(membership[0].status, GroupMembership.MEMBER)
     invalidate_group_membership()
     membership = group.groupmembership_set.get(
         userprofile=user.userprofile)
     eq_(membership.status, GroupMembership.PENDING_TERMS)
예제 #17
0
    def test_invalidate_group_accepts_all(self, mocked_waffle_switch):
        mocked_waffle_switch.return_value = False
        member = UserFactory.create(vouched=True)
        curator = UserFactory.create(vouched=True)

        group = GroupFactory.create(invalidation_days=5)
        group.curators.add(curator.userprofile)
        group.add_member(curator.userprofile)
        group.add_member(member.userprofile)

        membership = group.groupmembership_set.filter(userprofile=member.userprofile)
        curator_membership = group.groupmembership_set.filter(userprofile=curator.userprofile)
        membership.update(updated_on=datetime.now() - timedelta(days=10))
        curator_membership.update(updated_on=datetime.now() - timedelta(days=10))

        eq_(membership[0].status, GroupMembership.MEMBER)
        eq_(curator_membership[0].status, GroupMembership.MEMBER)

        invalidate_group_membership()

        ok_(not group.groupmembership_set.filter(userprofile=member.userprofile).exists())
        ok_(group.groupmembership_set.filter(userprofile=curator.userprofile).exists())
예제 #18
0
    def test_invalidate_group_with_terms(self, mocked_waffle_switch):
        mocked_waffle_switch.return_value = False
        member = UserFactory.create(vouched=True)
        curator = UserFactory.create(vouched=True)

        group = GroupFactory.create(terms='Example terms.', invalidation_days=5)
        group.curators.add(curator.userprofile)
        group.add_member(member.userprofile)
        group.add_member(curator.userprofile)

        membership = group.groupmembership_set.filter(userprofile=member.userprofile)
        curator_membership = group.groupmembership_set.filter(userprofile=curator.userprofile)
        membership.update(updated_on=datetime.now() - timedelta(days=10))
        curator_membership.update(updated_on=datetime.now() - timedelta(days=10))

        eq_(membership[0].status, GroupMembership.MEMBER)
        eq_(curator_membership[0].status, GroupMembership.MEMBER)

        invalidate_group_membership()

        membership = group.groupmembership_set.get(userprofile=member.userprofile)
        curator_membership = group.groupmembership_set.get(userprofile=curator.userprofile)
        eq_(membership.status, GroupMembership.PENDING_TERMS)
        eq_(curator_membership.status, GroupMembership.MEMBER)
예제 #19
0
    def test_invalidate_group_by_request(self, mocked_waffle_switch):
        mocked_waffle_switch.return_value = False
        member = UserFactory.create(vouched=True)
        curator = UserFactory.create(vouched=True)

        group = GroupFactory.create(invalidation_days=5, accepting_new_members='by_request')
        group.curators.add(curator.userprofile)
        group.add_member(curator.userprofile)
        group.add_member(member.userprofile)

        membership = group.groupmembership_set.filter(userprofile=member.userprofile)
        curator_membership = group.groupmembership_set.filter(userprofile=curator.userprofile)
        membership.update(updated_on=datetime.now() - timedelta(days=10))
        curator_membership.update(updated_on=datetime.now() - timedelta(days=10))

        eq_(membership[0].status, GroupMembership.MEMBER)
        eq_(curator_membership[0].status, GroupMembership.MEMBER)

        invalidate_group_membership()

        membership = group.groupmembership_set.get(userprofile=member.userprofile)
        curator_membership = group.groupmembership_set.get(userprofile=curator.userprofile)
        eq_(membership.status, GroupMembership.PENDING)
        eq_(curator_membership.status, GroupMembership.MEMBER)