Esempio n. 1
0
def test_invalid_link():
    """Test that error is propagated from link parser to json parser.

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

    with pytest.raises(ValueError) as expected_error_info:
        parser.create_link_parser(invalid_link_data).parse()

    assert actual_error_info.value.args[0] == expected_error_info.value.args[
        0], ("Wrong error is raised")
Esempio n. 2
0
def test_links(links_data):
    """Test that links are properly parsed.

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

    parser = EmbeddedRepresentationParser(data={"links": links_data},
                                          parser=json_parser)
    actual_links = parser.parse_links()
    assert actual_links == tuple(range(len(links_data))), "Wrong links"