Пример #1
0
def test_validate_err():
    """An erroneous Thing Description raises error on validation."""

    update_funcs = [
        lambda x: x.update({"properties": [1, 2, 3]}) or x,
        lambda x: x.update({"actions": "hello-interactions"}) or x,
        lambda x: x.update({"events": {
            "overheating": {
                "forms": 0.5
            }
        }}) or x, lambda x: x.update({"events": {
            "Invalid Name": {}
        }}) or x,
        lambda x: x.update({"events": {
            100: {
                "label": "Invalid Name"
            }
        }}) or x
    ]

    for update_func in update_funcs:
        td_err = update_func(copy.deepcopy(TD_EXAMPLE))

        with pytest.raises(InvalidDescription):
            ThingDescription.validate(doc=td_err)
Пример #2
0
def test_validate():
    """Example TD from the W3C Thing Description page validates correctly."""

    ThingDescription.validate(doc=TD_EXAMPLE)
Пример #3
0
def test_empty_thing_valid():
    """An empty Thing initialized by default has a valid JSON-LD serialization."""

    thing = Thing(id=uuid.uuid4().urn)
    json_td = ThingDescription.from_thing(thing)
    ThingDescription.validate(json_td.to_dict())