'Invalidate a group where a user has not yet been accepted by a curator.
Type is indifferent for this test.'

@patch('mozillians.groups.models.email_membership_change')
def test_invalidate_group_pending_membership(self, mail_task):

    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, 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).exists())
    ok_(group.groupmembership_set.filter(userprofile=curator.userprofile).exists())
    ok_((not mail_task.called))
