コード例 #1
0
ファイル: test_params.py プロジェクト: selenol/selenol-python
def test_get_request_id(mock_service, mock_message):
    """Test get_request_id method."""
    # request_id does not exist.
    with raises(KeyError):
        del mock_message['request_id']
        selenol_message = SelenolMessage(mock_message)
        get_request_id()(mock_service, selenol_message)

    # request_id exists.
    request_id = 43
    mock_message['request_id'] = request_id
    selenol_message = SelenolMessage(mock_message)
    assert get_request_id()(mock_service, selenol_message) == request_id
コード例 #2
0
    def factory(session, content):
        """Message factory.

        :param session: Message session.
        :param content: Message content.
        """
        return SelenolMessage({
            'content': {
                'session': session,
                'content': content,
            },
            'request_id': 0,
        })
コード例 #3
0
def test_selenol_message(mock_message):
    """Test SelenolMessage class."""
    message_without_session = copy.deepcopy(mock_message)
    del message_without_session['content']['session']
    selenol_message_without_session = SelenolMessage(message_without_session)
    assert isinstance(selenol_message_without_session.session,
                      SelenolDictionary)
    assert isinstance(selenol_message_without_session.session,
                      SelenolDictionary)

    message_without_content = copy.deepcopy(mock_message)
    del message_without_content['content']['content']
    selenol_message_without_content = SelenolMessage(message_without_content)
    assert isinstance(selenol_message_without_content.content,
                      SelenolDictionary)

    try:
        message_without_request_id = copy.deepcopy(mock_message)
        del message_without_request_id['request_id']
        SelenolMessage(message_without_request_id)
        assert False, "Request ID is a mandatory field"
    except KeyError as ex:
        assert ex.args[0] == 'request_id'
コード例 #4
0
ファイル: test_params.py プロジェクト: selenol/selenol-python
def test_get_value_from_session(mock_service, mock_message):
    """Test get_value_from_session function."""
    selenol_message = SelenolMessage(mock_message)

    # It has access to session.
    assert get_value_from_session(['keys'])(mock_service,
                                            selenol_message) == 'values'

    # But it does not have access to content.
    try:
        assert get_value_from_session(['keyc'])(mock_service,
                                                selenol_message) == 'valuec'
    except SelenolMissingSessionArgumentException as ex:
        assert ex.argument == 'keyc'
コード例 #5
0
ファイル: test_params.py プロジェクト: selenol/selenol-python
def test_get_object_from_session(mock_service, mock_message):
    """Test get_object_from_content method."""
    selenol_message = SelenolMessage(mock_message)

    # Value exists.
    mock_message['content']['session']['foo'] = 43
    assert get_object_from_session(int, ['foo'])(mock_service,
                                                 selenol_message) == 43

    # Value does not exist in the database
    try:
        mock_message['content']['session']['foo'] = False
        get_object_from_session(int, ['foo'])(mock_service, selenol_message)
        assert False, 'The object doesnt exist, it throw an exception'
    except SelenolInvalidArgumentException as ex:
        assert ex.argument == ['foo']
        assert not ex.value
コード例 #6
0
ファイル: test_params.py プロジェクト: selenol/selenol-python
def test_selenol_params(mock_service, mock_message):
    """Test selenol_params decorator."""
    selenol_message = SelenolMessage(mock_message)

    def on_request_mock(service, four, three):
        """Function to test the defined parameters."""
        assert service == mock_service
        assert four == 4
        assert three == 3

    def four_function(service, message):
        """Test if the service and message are correct."""
        assert service == mock_service
        assert message == selenol_message
        return 4

    selenol_params(four=four_function,
                   three=lambda service, message: 3)(on_request_mock)(
                       mock_service, selenol_message)
コード例 #7
0
ファイル: test_params.py プロジェクト: selenol/selenol-python
def test_get_value(mock_message):
    """Test get_value method."""
    selenol_message = SelenolMessage(mock_message)

    # Value exists.
    assert _get_value(selenol_message.content, ['keyc']) == 'valuec'

    # Value does not exist.
    try:
        _get_value(selenol_message.content, ['no'])
        assert False, 'The value does not exist.'
    except SelenolMissingArgumentException as ex:
        assert ex.argument == 'no'

    # Empty path.
    with raises(KeyError):
        _get_value(selenol_message.content, [])

    # Complex path.
    mock_message['content']['content']['test'] = [{'b': 43}]
    assert _get_value(selenol_message.content, ['test', 0, 'b']) == 43