def test_invalid_dictionary(properties):
    """Check that ValueError is raised if properties can't be converted to a dictionary.

    1. Call adjust_properties with object, that can't be converted to dictionary.
    2. Check that ValueError is raised.
    3. Check error message.
    """
    with pytest.raises(ValueError) as error_info:
        adjust_properties(properties)

    assert error_info.value.args[0] == "Can't create dictionary from properties", (
        "Wrong error message"
        )
def test_invalid_values(invalid_value):
    """Check that ValueError is raised if one of the properties has invalid value.

    1. Create a dictionary with 1 key. Its value is invalid.
    2. Pass the dictionary to adjust_properties.
    3. Check that ValueError is raised.
    4. Check error message.
    """
    property_name = "invalid_property"
    with pytest.raises(ValueError) as error_info:
        adjust_properties({property_name: invalid_value})

    expected_message = "Unsupported value for property '{name}'".format(name=property_name)
    assert error_info.value.args[0] == expected_message, "Wrong error message"
Beispiel #3
0
    def __init__(self,
                 title=None,
                 classes=(),
                 properties=(),
                 entities=(),
                 links=(),
                 actions=()):
        # pylint: disable=too-many-arguments
        super(Entity, self).__init__(classes=classes, title=title)

        self._properties = common.adjust_properties(properties)

        if any(not isinstance(link, Link) for link in links):
            raise ValueError("Some of the links are of incompatible type")
        self._links = tuple(links)

        if any(not isinstance(action, Action) for action in actions):
            raise ValueError("Some of the actions are of incompatible type")

        if len(set(action.name for action in actions)) != len(actions):
            raise ValueError("Some of the actions have the same name")

        self._actions = tuple(actions)

        if any(not isinstance(entity, (EmbeddedLink, EmbeddedRepresentation)) for entity in entities):  # pylint: disable=line-too-long
            raise ValueError("Some of the entities are of incompatible type")
        self._entities = tuple(entities)
def test_valid_values(actual_value, expected_value):
    """Check that valid values are properly converted.

    1. Create a dictionary with 1 property and value of different types.
    2. Pass the dictionary to adjust_properties.
    3. Check the converted value.
    """
    property_name = "key"
    properties = {property_name: actual_value}
    adjusted_value = adjust_properties(properties)[property_name]
    assert type(adjusted_value) == type(expected_value), "Wrong type"   # pylint: disable=unidiomatic-typecheck
    assert adjusted_value == expected_value, "Wrong value"
def test_string_keys():
    """Check that all keys are converted to strings.

    1. Create a list with property items  with keys of different types.
    2. Pass the dictionary to adjust_properties.
    3. Check keys of the returned dictionary.
    """
    properties = [
        ("plain string", "string value"),
        (1, "integer value"),
        (("tuple", ), "tuple value"),
        ]
    assert set(adjust_properties(properties).keys()) == set(("plain string", "1", "('tuple',)")), (
        "Wrong convertion"
        )