示例#1
0
def test_invalid_action():
    """Test that error is propagated from action parser to json parser.

    1. Create json parser.
    2. Try to parse an action from invalid data.
    3. Check that error is raised.
    4. Check that error is the same as one that action parser raises.
    """
    invalid_action_data = object()
    parser = JSONParser()
    with pytest.raises(ValueError) as actual_error_info:
        parser.parse_action(invalid_action_data)

    with pytest.raises(ValueError) as expected_error_info:
        parser.create_action_parser(invalid_action_data).parse()

    assert actual_error_info.value.args[0] == expected_error_info.value.args[
        0], ("Wrong error is raised")
示例#2
0
def test_actions(actions_data):
    """Test that actions are properly parsed.

    1. Create json parser.
    2. Replace parse_action method of the parser so that it returns fake data.
    3. Create an entity parser with the parser.
    4. Parse fields.
    5. Check the parsed fields.
    """
    json_parser = JSONParser()
    json_parser.parse_action = actions_data.index

    parser = EntityParser(data={"actions": actions_data}, parser=json_parser)
    actual_actions = parser.parse_actions()
    assert actual_actions == tuple(range(len(actions_data))), "Wrong actions"