Ejemplo n.º 1
0
def test_missing_title():
    """Test that ValueError is raised if an action does not have title attribute.

    1. Create an action marshaler for an object without title attibute.
    2. Try to call marshal_title method.
    3. Check that ValueError is raised.
    4. Check the error message.
    """
    marshaler = ActionMarshaler(marshaler=JSONMarshaler(), action=object())
    with pytest.raises(ValueError) as error_info:
        marshaler.marshal_title()

    assert error_info.value.args[
        0] == "Failed to get action's title", "Wrong error"
Ejemplo n.º 2
0
def test_marshal():
    """Test that action data is properly marshaled.

    1. Create an action.
    2. Create an action marshaler for the action.
    3. Replace marshaler methods so that they return predefined data.
    4. Marshal the action.
    5. Check the marshaled data.
    """
    marshaler = ActionMarshaler(
        marshaler=JSONMarshaler(),
        action=Action(name="action", target="/target"),
    )
    marshaler.marshal_name = lambda: "marshal_name"
    marshaler.marshal_classes = lambda: "marshal_classes"
    marshaler.marshal_method = lambda: "marshal_method"
    marshaler.marshal_target = lambda: "marshal_target"
    marshaler.marshal_title = lambda: "marshal_title"
    marshaler.marshal_media_type = lambda: "marshal_media_type"
    marshaler.marshal_fields = lambda: "marshal_fields"

    actual_data = marshaler.marshal()
    expected_data = {
        "name": "marshal_name",
        "class": "marshal_classes",
        "method": "marshal_method",
        "href": "marshal_target",
        "title": "marshal_title",
        "type": "marshal_media_type",
        "fields": "marshal_fields",
    }
    assert actual_data == expected_data, "Action is not properly marshaled"
Ejemplo n.º 3
0
def test_title(title, expected_title):
    """Test that title is properly marshaled.

    1. Create an action marshaler for an object with specific title.
    2. Marshal action's title.
    3. Check the marshaled title.
    """
    TitleAction = namedtuple("TitleAction", "title")
    marshaler = ActionMarshaler(marshaler=JSONMarshaler(),
                                action=TitleAction(title=title))

    actual_title = marshaler.marshal_title()
    assert actual_title == expected_title, "Wrong title"