Пример #1
0
def test_invalid_syntax_exception():
    """Test invalid syntax exception.

    Test if PHPyPAMInvalidSyntax exception is fired corretly.
    """
    connection_kwargs = server.copy()
    connection_kwargs.update({'app_id': 'faulty data'})

    with pytest.raises(PHPyPAMInvalidSyntax, match='Invalid application id'):
        phpypam.api(**connection_kwargs)
Пример #2
0
def test_invalid_credentials_exception():
    """Test invalid credentials exception.

    Test if ...
    """
    connection_kwargs = server.copy()
    connection_kwargs.update({'username': '******'})
    with pytest.raises(PHPyPAMInvalidCredentials):
        phpypam.api(**connection_kwargs)

    connection_kwargs.update({
        'username': server['username'],
        'password': '******'
    })
    with pytest.raises(PHPyPAMInvalidCredentials):
        phpypam.api(**connection_kwargs)
Пример #3
0
def test_connection_success():
    """Test whether a connection to API can be done."""
    pi = phpypam.api(**server)

    token = pi.get_token()

    assert isinstance(pi, phpypam.api)
    assert len(token) == 24
Пример #4
0
def test_custom_user_agent():
    """Test to set custom user-agent header.

    Test to connect to API with a custom user-agent header set.
    """
    connection_kwargs = server.copy()
    connection_kwargs.update({'user_agent': 'my_test_agent'})

    pi = phpypam.api(**connection_kwargs)

    assert isinstance(pi, phpypam.api)
    assert len(pi.get_token()) == 24
Пример #5
0
def test_entity_not_found_exception(case):
    """Test entity not found exception.

    Test if PHPyPAMEntityNotFound exception is fired corretly for all cases.
    """

    pi = phpypam.api(**connection_params)

    # check whether PHPyPAMEntityNotFoundException is raised
    with pytest.raises(PHPyPAMEntityNotFoundException) as e:
        pi.get_entity(case['controller'], controller_path=case.pop('path', None), params=case.pop('params', None))

        # assert exception message is in all not found outputs
        assert str(e.value) in PHPyPAMException._NOT_FOUND_MESSAGES
Пример #6
0
def pi(*arg, **kwargs):
    """Create a phpypam.api object and return it.

    :return: object phpypam
    :rtype: phpypam.api
    """
    url = kwargs.pop('url', server['url'])
    app_id = kwargs.pop('app_id', server['app_id'])
    username = kwargs.pop('username', server['username'])
    password = kwargs.pop('password', server['password'])
    ssl_verify = kwargs.pop('ssl_verify', server['ssl_verify'])

    return phpypam.api(url=url,
                       app_id=app_id,
                       username=username,
                       password=password,
                       ssl_verify=ssl_verify,
                       **kwargs)