Exemplo n.º 1
0
def test_duplicate_registration_denied(client, TwoChallengeSets):
    user = UserFactory()
    assert not RegistrationRequest.objects.filter(
        user=user, challenge=TwoChallengeSets.ChallengeSet1.challenge
    ).exists()
    rr = RegistrationRequestFactory(
        user=user, challenge=TwoChallengeSets.ChallengeSet1.challenge
    )
    assert RegistrationRequest.objects.filter(
        user=user, challenge=TwoChallengeSets.ChallengeSet1.challenge
    ).exists()
    response = get_view_for_user(
        viewname="participants:registration-create",
        client=client,
        method=client.post,
        challenge=TwoChallengeSets.ChallengeSet1.challenge,
        user=user,
    )
    assert response.status_code == 200
    assert rr.status_to_string() in response.rendered_content
    # Creating a request in another challenge should work
    assert not RegistrationRequest.objects.filter(
        user=user, challenge=TwoChallengeSets.ChallengeSet2.challenge
    ).exists()
    response = get_view_for_user(
        viewname="participants:registration-create",
        client=client,
        method=client.post,
        challenge=TwoChallengeSets.ChallengeSet2.challenge,
        user=user,
    )
    assert response.status_code == 302
    assert RegistrationRequest.objects.filter(
        user=user, challenge=TwoChallengeSets.ChallengeSet2.challenge
    ).exists()
Exemplo n.º 2
0
def test_duplicate_registration_denied(client, TwoChallengeSets):
    user = UserFactory()
    assert not RegistrationRequest.objects.filter(
        user=user,
        challenge=TwoChallengeSets.ChallengeSet1.challenge).exists()
    rr = RegistrationRequestFactory(
        user=user, challenge=TwoChallengeSets.ChallengeSet1.challenge)
    assert RegistrationRequest.objects.filter(
        user=user,
        challenge=TwoChallengeSets.ChallengeSet1.challenge).exists()
    response = get_view_for_user(
        viewname="participants:registration-create",
        client=client,
        method=client.post,
        challenge=TwoChallengeSets.ChallengeSet1.challenge,
        user=user,
    )
    assert response.status_code == 200
    assert rr.status_to_string() in response.rendered_content
    # Creating a request in another challenge should work
    assert not RegistrationRequest.objects.filter(
        user=user,
        challenge=TwoChallengeSets.ChallengeSet2.challenge).exists()
    response = get_view_for_user(
        viewname="participants:registration-create",
        client=client,
        method=client.post,
        challenge=TwoChallengeSets.ChallengeSet2.challenge,
        user=user,
    )
    assert response.status_code == 302
    assert RegistrationRequest.objects.filter(
        user=user,
        challenge=TwoChallengeSets.ChallengeSet2.challenge).exists()
Exemplo n.º 3
0
 def _register(self, user, challenge):
     """
     Register user for the given challenge, follow actual signup as closely
     as possible.
     """
     request = RegistrationRequestFactory(challenge=challenge, user=user)
     request.status = request.ACCEPTED
     request.save()
     assert challenge.is_participant(user)
Exemplo n.º 4
0
def test_registration_list_is_filtered(client, TwoChallengeSets):
    r1 = RegistrationRequestFactory(
        challenge=TwoChallengeSets.ChallengeSet1.challenge)
    r2 = RegistrationRequestFactory(
        challenge=TwoChallengeSets.ChallengeSet2.challenge)
    response = get_view_for_user(
        viewname="participants:registration-list",
        challenge=TwoChallengeSets.ChallengeSet1.challenge,
        client=client,
        user=TwoChallengeSets.admin12,
    )
    assert r1.user.username in response.rendered_content
    assert r2.user.username not in response.rendered_content
Exemplo n.º 5
0
def test_registration_no_review_workflow(challenge_set):
    user = UserFactory()
    challenge_set.challenge.access_request_handling = (
        AccessRequestHandlingOptions.ACCEPT_ALL)
    challenge_set.challenge.save()
    RegistrationRequestFactory(challenge=challenge_set.challenge, user=user)
    assert challenge_set.challenge.is_participant(user)
Exemplo n.º 6
0
 def _register(self, user, project):
     """ Register user for the given project, follow actual signup as
     closely as possible.
     """
     RegistrationRequestFactory(challenge=project, user=user)
     self.assertTrue(
         project.is_participant(user),
         "After registering as user %s , user does not "
         " appear to be registered." % (user.username),
     )
Exemplo n.º 7
0
def test_registration_request_list(view, client, TwoChallengeSets):
    reverse_kwargs = {}
    if view in ("participants:registration-update", ):
        rr = RegistrationRequestFactory(
            challenge=TwoChallengeSets.ChallengeSet1.challenge)
        reverse_kwargs.update({"pk": rr.pk})
    validate_admin_only_view(
        viewname=view,
        two_challenge_set=TwoChallengeSets,
        client=client,
        reverse_kwargs=reverse_kwargs,
    )
def test_join_page_links(client, ChallengeSet):
    tests = [
        (ChallengeSet.non_participant, 'Click here to join'),
        (ChallengeSet.participant, 'You are already participating'),
    ]
    for test in tests:
        response = get_view_for_user(
            viewname='participants:registration-create',
            client=client,
            user=test[0],
            challenge=ChallengeSet.challenge,
        )
        assert test[1] in response.rendered_content
        rr = RegistrationRequestFactory(user=test[0],
                                        challenge=ChallengeSet.challenge)
        response = get_view_for_user(
            viewname='participants:registration-create',
            client=client,
            user=test[0],
            challenge=ChallengeSet.challenge,
        )
        assert rr.status_to_string() in response.rendered_content
Exemplo n.º 9
0
def test_join_page_links(client, ChallengeSet):
    tests = [
        (ChallengeSet.non_participant, "Click here to join"),
        (ChallengeSet.participant, "You are already participating"),
    ]
    for test in tests:
        response = get_view_for_user(
            viewname="participants:registration-create",
            client=client,
            user=test[0],
            challenge=ChallengeSet.challenge,
        )
        assert test[1] in response.rendered_content
        rr = RegistrationRequestFactory(
            user=test[0], challenge=ChallengeSet.challenge
        )
        response = get_view_for_user(
            viewname="participants:registration-create",
            client=client,
            user=test[0],
            challenge=ChallengeSet.challenge,
        )
        assert rr.status_to_string() in response.rendered_content
Exemplo n.º 10
0
def test_registration_updated_email(new_state, client, challenge_set):
    rr = RegistrationRequestFactory(challenge=challenge_set.challenge)
    response = get_view_for_user(
        viewname="participants:registration-update",
        client=client,
        method=client.post,
        user=challenge_set.admin,
        challenge=challenge_set.challenge,
        reverse_kwargs={"pk": rr.pk},
        data={"status": new_state},
    )
    assert response.status_code == 302
    email = mail.outbox[-1]
    assert rr.user.email in email.to
    if new_state == RegistrationRequest.ACCEPTED:
        assert "request accepted" in email.subject.lower()
    else:
        assert "request rejected" in email.subject.lower()
    assert challenge_set.challenge.short_name in email.body
def test_registration_updated_email(new_state, client, ChallengeSet):
    rr = RegistrationRequestFactory(challenge=ChallengeSet.challenge)
    response = get_view_for_user(
        viewname='participants:registration-update',
        client=client,
        method=client.post,
        user=ChallengeSet.admin,
        challenge=ChallengeSet.challenge,
        reverse_kwargs={'pk': rr.pk},
        data={'status': new_state},
    )
    assert response.status_code == 302
    email = mail.outbox[-1]
    assert rr.user.email in email.to
    if new_state == RegistrationRequest.ACCEPTED:
        assert 'request accepted' in email.subject
    else:
        assert 'request rejected' in email.subject
    assert ChallengeSet.challenge.short_name in email.body
Exemplo n.º 12
0
def test_registration_review_workflow(choice, expected, client, challenge_set):
    user = UserFactory()
    challenge_set.challenge.require_participant_review = True
    challenge_set.challenge.save()
    rr = RegistrationRequestFactory(challenge=challenge_set.challenge,
                                    user=user)
    assert not challenge_set.challenge.is_participant(user)
    assert rr.status == RegistrationRequest.PENDING
    response = get_view_for_user(
        client=client,
        method=client.post,
        viewname="participants:registration-update",
        challenge=challenge_set.challenge,
        user=challenge_set.admin,
        reverse_kwargs={"pk": rr.pk},
        data={"status": choice},
    )
    assert response.status_code == 302
    assert challenge_set.challenge.is_participant(user) == expected
    assert RegistrationRequest.objects.get(pk=rr.pk).status == choice
Exemplo n.º 13
0
def test_registration_admin_changed_mind(client, challenge_set):
    user = UserFactory()
    challenge_set.challenge.require_participant_review = False
    challenge_set.challenge.save()
    rr = RegistrationRequestFactory(challenge=challenge_set.challenge,
                                    user=user)
    assert challenge_set.challenge.is_participant(user)
    assert rr.status == RegistrationRequest.ACCEPTED
    response = get_view_for_user(
        client=client,
        method=client.post,
        viewname="participants:registration-update",
        challenge=challenge_set.challenge,
        user=challenge_set.admin,
        reverse_kwargs={"pk": rr.pk},
        data={"status": RegistrationRequest.REJECTED},
    )
    assert response.status_code == 302
    assert not challenge_set.challenge.is_participant(user)
    assert (RegistrationRequest.objects.get(
        pk=rr.pk).status == RegistrationRequest.REJECTED)
Exemplo n.º 14
0
def test_registration_no_review_workflow(challenge_set):
    user = UserFactory()
    challenge_set.challenge.require_participant_review = False
    challenge_set.challenge.save()
    RegistrationRequestFactory(challenge=challenge_set.challenge, user=user)
    assert challenge_set.challenge.is_participant(user)