Пример #1
0
def test_invalid_link():
    """Test that error is propagated from link marshaler to json marshaler.

    1. Create json marshaler.
    2. Try to marshal invalid link.
    3. Check that error is raised.
    4. Check that error is the same as one that link marshaler raises.
    """
    invalid_link = None
    marshaler = JSONMarshaler()
    with pytest.raises(ValueError) as actual_error_info:
        marshaler.marshal_link(invalid_link)

    with pytest.raises(ValueError) as expected_error_info:
        marshaler.create_link_marshaler(invalid_link).marshal()

    assert actual_error_info.value.args[0] == expected_error_info.value.args[0], (
        "Wrong error is raised"
        )
Пример #2
0
def test_links(links):
    """Test that links are properly marshaled.

    1. Create an entity marshaler.
    2. Replace marshal_link of the marshaler so that it returns fake data.
    3. Marshal links.
    4. Check the marshaled links.
    """
    json_marshaler = JSONMarshaler()
    json_marshaler.marshal_link = links.index

    LinksEntity = namedtuple("LinksEntity", "links")
    marshaler = EntityMarshaler(marshaler=json_marshaler,
                                entity=LinksEntity(links=links))

    actual_data = marshaler.marshal_links()
    assert actual_data == list(range(len(links))), "Wrong links"
def test_links(links):
    """Test that links are properly marshaled.

    1. Create an embedded representation marshaler.
    2. Replace marshal_link of the marshaler so that it returns fake data.
    3. Marshal links.
    4. Check the marshaled links.
    """
    json_marshaler = JSONMarshaler()
    json_marshaler.marshal_link = links.index

    LinksRepresentation = namedtuple("LinksRepresentation", "links")
    marshaler = RepresentationMarshaler(
        marshaler=json_marshaler,
        embedded_representation=LinksRepresentation(links=links),
    )

    actual_data = marshaler.marshal_links()
    assert actual_data == list(range(len(links))), "Wrong links"