コード例 #1
0
def test_delete_did_numbers_without_login_view(app, auth, client):
    """
    Test delete DID numbers without login (a redirection should be done)
    """

    target_url = get_url(app=app, url="user.delete_did_number", id=1)
    redirect_url = redirect(
        get_url(app=app, url="auth.login", next_url=target_url))
    response = client.delete(target_url)
    assert response.status_code == 302
    assert redirect_url.data == response.data
コード例 #2
0
def test_add_did_numbers_without_login_view(app, client):
    """
    Test add DID numbers without login (a redirection should be done)
    """

    target_url = get_url(app=app, url="user.add_didnumber")
    redirect_url = redirect(
        get_url(app=app, url="auth.login", next_url=target_url))
    response = client.post(target_url)
    assert response.status_code == 302
    assert redirect_url.data == response.data
コード例 #3
0
def test_users_details_without_login_view(app, client):
    """
    Test list users details without login (a redirection should be done)
    """

    target_url = get_url(app=app, url="user.user_details")
    redirect_url = redirect(
        get_url(app=app, url="auth.login", next_url=target_url))
    response = client.get(target_url)
    assert response.status_code == 302
    assert response, redirect_url
コード例 #4
0
def test_edit_volunteers_without_login_view(app, auth, client):
    """
    Test edit volunteers without login (a redirection should be done)
    """

    target_url = get_url(app=app, url="volunteer.edit_volunteer", id=1)
    redirect_url = redirect(
        get_url(app=app, url="auth.login", next_url=target_url))
    response = client.put(target_url)
    assert response.status_code == 302
    assert redirect_url.data == response.data
コード例 #5
0
def test_list_employees_without_login_view(app, client):
    """
    Test list employees without login (a redirection should be done)
    """

    target_url = get_url(app=app, url="user.list_employees")
    redirect_url = redirect(
        get_url(app=app, url="auth.login", next_url=target_url))
    response = client.get(target_url)
    assert response.status_code == 302
    assert redirect_url.data == response.data
コード例 #6
0
def test_include_root_definition(minimal_swagger_dict, minimal_swagger_abspath):
    minimal_swagger_dict['definitions'] = {
        'not_used_model': {
            'type': 'object',
        },
    }
    spec_flattener = _spec_flattener(Spec.from_dict(minimal_swagger_dict, origin_url=get_url(minimal_swagger_abspath)))

    spec_flattener.include_root_definition()

    fragment_uri = '{}#/definitions/not_used_model'.format(get_url(minimal_swagger_abspath))
    assert spec_flattener.known_mappings['definitions'] == {
        urlparse(fragment_uri): minimal_swagger_dict['definitions']['not_used_model'],
    }
コード例 #7
0
def multi_file_multi_directory_spec(request, multi_file_multi_directory_dict,
                                    multi_file_multi_directory_abspath):
    return Spec.from_dict(
        multi_file_multi_directory_dict,
        origin_url=get_url(multi_file_multi_directory_abspath),
        config={'internally_dereference_refs': request.param},
    )
コード例 #8
0
def test_validate_config_fail(
    mock_warnings, minimal_swagger_dict, minimal_swagger_abspath,
    config, expected_different_config, expected_warnings_call,
):
    spec = Spec.from_dict(minimal_swagger_dict, origin_url=get_url(minimal_swagger_abspath), config=config)
    assert (spec.config != dict(CONFIG_DEFAULTS, **config)) is expected_different_config
    mock_warnings.warn.assert_called_once_with(message=expected_warnings_call, category=Warning)
コード例 #9
0
 def new_spec():
     return Spec.from_dict(
         spec_dict=minimal_swagger_dict,
         origin_url=get_url(minimal_swagger_abspath),
         config={
             'internally_dereference_refs': internally_dereference_refs
         },
     )
コード例 #10
0
def test_actions_details_without_login_view(app, client):
    """
    Test list actions details without login (a redirection should be done) - It will be shown
    """

    target_url = get_url(app=app, url="action.list_actions", id=1)
    response = client.get(target_url)
    assert response.status_code == 200
コード例 #11
0
def test_list_volunteers_without_login_view(app, client):
    """
    Test list volunteers without login (a redirection should be done) - List will be shown
    """

    target_url = get_url(app=app, url="volunteer.list_volunteers")
    response = client.get(target_url)
    assert response.status_code == 200
コード例 #12
0
def test_detail_volunteers_without_login_view(app, client):
    """
    Test detail volunteers without login (a redirection should be done) - It will be shown
    """

    target_url = get_url(app=app, url="volunteer.volunteer_detail", id=1)
    response = client.get(target_url)
    assert response.status_code == 200
コード例 #13
0
def test_list_actions_without_login_view(app, client):
    """
    Test list actions without login - List will be shown
    """

    target_url = get_url(app=app, url="action.list_actions")
    response = client.get(target_url)
    assert response.status_code == 200
コード例 #14
0
def test_list_employees_with_login_admin_view(app, auth, client):
    """
    Test list employees with login and the user has access permission (is an admin user)
    """

    target_url = get_url(app=app, url="user.list_employees")
    auth.login(a_dict=dict(email="*****@*****.**", password="******"))
    response = client.get(target_url)
    assert response.status_code == 200
コード例 #15
0
def test_detail_volunteers_with_login_view(app, auth, client):
    """
    Test detail volunteers with login -  - It will be shown
    """

    target_url = get_url(app=app, url="volunteer.volunteer_detail", id=1)
    auth.login(dict(email="*****@*****.**", password="******"))
    response = client.get(target_url)
    assert response.status_code == 200
コード例 #16
0
def test_users_details_with_login_view(app, auth, client):
    """
    Test list users details with login (non-admin user)
    """

    target_url = get_url(app=app, url="user.user_details")
    auth.login(a_dict=dict(email="*****@*****.**", password="******"))
    response = client.get(target_url)
    assert response.status_code == 200
コード例 #17
0
def test_delete_volunteers_with_login_non_admin_view(app, auth, client):
    """
    Test delete volunteers with login but with no access permission (non-admin user)
    """

    target_url = get_url(app=app, url="volunteer.delete_volunteer", id=1)
    auth.login(dict(email="*****@*****.**", password="******"))
    response = client.delete(target_url)
    assert response.status_code == 403
コード例 #18
0
def test_users_details_with_login_admin_view(app, auth, client):
    """
    Test list users_details with login and the user is an admin
    """

    target_url = get_url(app=app, url="user.edit_users", id=1)
    auth.login(a_dict=dict(email="*****@*****.**", password="******"))
    response = client.get(target_url)
    assert response.status_code == 200
コード例 #19
0
def test_detail_did_number_that_does_not_exist_view(app, auth, client):
    """
    Test detail DID number that does not exist
    """

    target_url = get_url(app=app, url="user.didnumber_detail", id=1000000)
    auth.login(dict(email="*****@*****.**", password="******"))
    response = client.get(target_url)
    assert response.status_code == 404
コード例 #20
0
def test_delete_did_numbers_with_login_admin_view(app, auth, client):
    """
    Test delete DID numbers with login and the user has access permission (is an admin user)
    """

    target_url = get_url(app=app, url="user.delete_did_number", id=1)
    auth.login(dict(email="*****@*****.**", password="******"))
    response = client.delete(target_url)
    assert response.status_code == 200
コード例 #21
0
def test_detail_did_numbers_with_login_view(app, auth, client):
    """
    Test detail DID numbers with login
    """

    target_url = get_url(app=app, url="user.didnumber_detail", id=1)
    auth.login(dict(email="*****@*****.**", password="******"))
    response = client.get(target_url)
    assert response.status_code == 200
コード例 #22
0
def test_actions_details_with_login_admin_view(app, auth, client):
    """
    Test list actions_details with login and the user has access permission (is an admin user) - It will be shown
    """

    target_url = get_url(app=app, url="action.list_actions", id=1)
    auth.login(a_dict=dict(email="*****@*****.**", password="******"))
    response = client.get(target_url)
    assert response.status_code == 200
コード例 #23
0
def test_action_detail_does_not_exist_view(app, auth, client):
    """
    Test list action detail whose doesn't exist
    """

    target_url = get_url(app=app, url="action.action_detail", id=10000000)
    auth.login(a_dict=dict(email="*****@*****.**", password="******"))
    response = client.get(target_url)
    assert response.status_code == 404
コード例 #24
0
def test_delete_volunteer_that_does_not_exist_view(app, auth, client):
    """
    Test delete volunteer that does not exist
    """

    target_url = get_url(app=app, url="volunteer.delete_volunteer", id=1000)
    auth.login(dict(email="*****@*****.**", password="******"))
    response = client.delete(target_url)
    assert response.status_code == 404
コード例 #25
0
def test_list_actions_with_login_non_admin_view(app, auth, client):
    """
    Test list actions with login but with no access permission (non-admin user) - List will be shown
    """

    target_url = get_url(app=app, url="action.list_actions")
    auth.login(a_dict=dict(email="*****@*****.**", password="******"))
    response = client.get(target_url)
    assert response.status_code == 200
コード例 #26
0
def test_equality_of_different_instances_returns_True_if_the_specs_are_the_same(
    petPetstoreResource,
    petstore_dict,
    petstore_abspath,
):
    other_petstore_spec = Spec.from_dict(petstore_dict,
                                         origin_url=get_url(petstore_abspath))
    other_petPetstoreResource = other_petstore_spec.resources['pet']
    assert petPetstoreResource.is_equal(other_petPetstoreResource)
コード例 #27
0
def test_ensure_spec_is_pickleable(petstore_dict, petstore_abspath, internally_dereference_refs, validate_swagger_spec):
    spec = Spec.from_dict(
        spec_dict=petstore_dict,
        origin_url=get_url(petstore_abspath),
        config={
            'validate_swagger_spec': validate_swagger_spec,
            'internally_dereference_refs': internally_dereference_refs,
        },
    )
    assert spec.is_equal(loads(dumps(spec)))
コード例 #28
0
def test_equality_of_different_instances_returns_False_if_attributes_are_not_matching(
    petstore_spec,
    petstore_dict,
    petstore_abspath,
    attribute_value,
):
    other_petstore_spec_instance = Spec.from_dict(
        petstore_dict, origin_url=get_url(petstore_abspath))
    setattr(other_petstore_spec_instance, 'a-new-attribute', attribute_value)
    assert not petstore_spec.is_equal(other_petstore_spec_instance)
コード例 #29
0
def test_employees_details_with_login_non_admin_view(app, auth, client):
    """
    Test list employees details with login but with no access permission (non-admin user)
    """

    target_url = get_url(app=app, url="user.list_employees", id=1)
    auth.login(a_dict=dict(email="*****@*****.**", password="******"))
    response = client.get(target_url)
    assert response.status_code == 403
    assert b"The current user is not an admin" in response.data
コード例 #30
0
def test_include_discriminated_models(minimal_swagger_dict, minimal_swagger_abspath):
    minimal_swagger_dict['definitions'] = {
        'base': {
            'type': 'object',
            'properties': {
                'discriminator_field': {'type': 'string'},
            },
            'discriminator': 'discriminator_field',
            'required': ['discriminator_field'],
        },
        'not_used_extend_base': {
            'allOf': [
                {'$ref': '#/definitions/base'},
                {
                    'properties': {
                        'text': {'type': 'string'},
                    },
                },
            ],
        },
    }
    spec_flattener = _spec_flattener(Spec.from_dict(minimal_swagger_dict, origin_url=get_url(minimal_swagger_abspath)))

    base_fragment_uri = '{}#/definitions/base'.format(get_url(minimal_swagger_abspath))
    spec_flattener.known_mappings['definitions'] = {
        urlparse(base_fragment_uri): minimal_swagger_dict['definitions']['base'],
    }

    spec_flattener.include_discriminated_models()

    not_used_extend_base_fragment_uri = '{}#/definitions/not_used_extend_base'.format(get_url(minimal_swagger_abspath))

    assert spec_flattener.known_mappings['definitions'] == {
        urlparse(base_fragment_uri): minimal_swagger_dict['definitions']['base'],
        urlparse(not_used_extend_base_fragment_uri): {
            'allOf': [
                mock.ANY,  # not checking the exact content as it contains a marshaled reference and x-scope
                minimal_swagger_dict['definitions']['not_used_extend_base']['allOf'][1],
            ],
            'x-model': 'not_used_extend_base',
        },
    }
コード例 #31
0
def test_equality_of_different_instances_returns_True_if_the_specs_are_the_same(
    getPetByIdPetstoreOperation,
    petstore_dict,
    petstore_abspath,
):
    other_petstore_spec = Spec.from_dict(petstore_dict,
                                         origin_url=get_url(petstore_abspath))
    other_getPetByIdPetstoreOperation = other_petstore_spec.resources[
        'pet'].operations['getPetById']
    assert getPetByIdPetstoreOperation.is_equal(
        other_getPetByIdPetstoreOperation)
コード例 #32
0
def test_unmarshal_schema_object_allOf(composition_dict, composition_abspath):
    composition_spec = Spec.from_dict(composition_dict, origin_url=get_url(composition_abspath))
    pongClone_spec = composition_spec.spec_dict['definitions']['pongClone']
    pongClone = composition_spec.definitions['pongClone']

    result = unmarshal_schema_object(
        composition_spec,
        pongClone_spec,
        {
            'additionalFeature': 'Badges',
            'gameSystem': 'NES',
            'pang': 'value',
            'releaseDate': 'October',
        },
    )
    assert isinstance(result, pongClone)
コード例 #33
0
def test_validate_config_succeed(minimal_swagger_dict, minimal_swagger_abspath, config):
    spec = Spec.from_dict(minimal_swagger_dict, origin_url=get_url(minimal_swagger_abspath), config=config)
    assert spec.config == dict(CONFIG_DEFAULTS, **config)