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)
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)
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)
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)
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())
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)
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)
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)
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)
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)
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())
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)
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)
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())
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)
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)
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())
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)
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)