def validate_member_owner_or_admin_view(*, two_challenge_set, client: Client, **kwargs): """ Assert that a view is only accessible to administrators or participants of that particular challenge """ # No user assert_viewname_redirect( redirect_url=settings.LOGIN_URL, challenge=two_challenge_set.ChallengeSet1.challenge, client=client, **kwargs) tests = [ (403, two_challenge_set.ChallengeSet1.non_participant), (200, two_challenge_set.ChallengeSet1.participant), (200, two_challenge_set.ChallengeSet1.participant1), (200, two_challenge_set.ChallengeSet1.creator), (200, two_challenge_set.ChallengeSet1.admin), (403, two_challenge_set.ChallengeSet2.non_participant), (403, two_challenge_set.ChallengeSet2.participant), (403, two_challenge_set.ChallengeSet2.participant1), (403, two_challenge_set.ChallengeSet2.creator), (403, two_challenge_set.ChallengeSet2.admin), (200, two_challenge_set.admin12), (403, two_challenge_set.participant12), (200, two_challenge_set.admin1participant2), ] for test in tests: assert_viewname_status( code=test[0], challenge=two_challenge_set.ChallengeSet1.challenge, client=client, user=test[1], **kwargs)
def validate_member_owner_or_admin_view( *, two_challenge_set, client: Client, **kwargs ): """ Assert that a view is only accessible to administrators or participants of that particular challenge """ # No user assert_viewname_redirect( redirect_url=settings.LOGIN_URL, challenge=two_challenge_set.ChallengeSet1.challenge, client=client, **kwargs, ) tests = [ (403, two_challenge_set.ChallengeSet1.non_participant), (200, two_challenge_set.ChallengeSet1.participant), (200, two_challenge_set.ChallengeSet1.participant1), (200, two_challenge_set.ChallengeSet1.creator), (200, two_challenge_set.ChallengeSet1.admin), (403, two_challenge_set.ChallengeSet2.non_participant), (403, two_challenge_set.ChallengeSet2.participant), (403, two_challenge_set.ChallengeSet2.participant1), (403, two_challenge_set.ChallengeSet2.creator), (403, two_challenge_set.ChallengeSet2.admin), (200, two_challenge_set.admin12), (403, two_challenge_set.participant12), (200, two_challenge_set.admin1participant2), ] for test in tests: assert_viewname_status( code=test[0], challenge=two_challenge_set.ChallengeSet1.challenge, client=client, user=test[1], **kwargs, )
def test_api_docs_generation(client, schema, content_type): response = assert_viewname_status( code=200, url=reverse(f"api:{schema}"), client=client, HTTP_ACCEPT=content_type, ) assert len(response.data["paths"]) > 0 check_answer_type_schema_from_response(response)
def test_api_docs_generation(client, schema, schema_format): kwargs = dict(format=schema_format) if schema == "schema-json" else None response = assert_viewname_status(code=200, url=reverse(f"api:{schema}", kwargs=kwargs), client=client) if schema_format is not None: assert len(response.data["paths"]) > 0 check_answer_type_schema_from_response(response) check_response_schema_formatting(response) else: assert len(response.content) > 0