Example #1
0
def test_invalid_action():
    """Test that error is propagated from action marshaler to json marshaler.

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

    with pytest.raises(ValueError) as expected_error_info:
        marshaler.create_action_marshaler(invalid_action).marshal()

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

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

    ActionsEntity = namedtuple("ActionsEntity", "actions")
    marshaler = EntityMarshaler(marshaler=json_marshaler,
                                entity=ActionsEntity(actions=actions))

    actual_data = marshaler.marshal_actions()
    assert actual_data == list(range(len(actions))), "Wrong actions"