Beispiel #1
0
def test_add_field_str():
    m = DataModel("id", "type")
    m.add("projectName", "Pixel")
    assert m.json(
    ) == r'{"id": "id", "type": "type", "projectName": {"value": "Pixel", "type": "Text"}}'
Beispiel #2
0
def test_cannot_map_ngsi_type():
    m = DataModel("id", "type")
    with pytest.raises(NgsiException, match=r".*Cannot map.*"):
        m.add("unknown", None)
Beispiel #3
0
def test_add_dict():
    m = DataModel("id", "type")
    m.add("property", {"a": 1, "b": 2})
    assert m.json() == r'{"id": "id", "type": "type", ' \
        r'"property": {"value": {"a": 1, "b": 2}, "type": "Property"}}'
Beispiel #4
0
def test_add_location_from_geojson():
    m = DataModel("id", "type")
    location = Point((-0.5667, 44.8333))
    m.add("location", location)
    assert m.json(
    ) == r'{"id": "id", "type": "type", "location": {"value": {"type": "Point", "coordinates": [-0.5667, 44.8333]}, "type": "geo:json"}}'
Beispiel #5
0
def test_add_location_invalid():
    m = DataModel("id", "type")
    with pytest.raises(NgsiException, match=r".*JSON compliant.*"):
        m.add("location", ('A', -0.5667))
Beispiel #6
0
def test_add_field_date_from_datetime():
    m = DataModel("id", "type")
    d = datetime(2019, 6, 1, 18, 30, 0)
    m.add("dateObserved", d)
    assert m.json(
    ) == r'{"id": "id", "type": "type", "dateObserved": {"value": "2019-06-01T18:30:00", "type": "DateTime"}}'
Beispiel #7
0
def test_add_location_from_tuple():
    m = DataModel("id", "type")
    m.add("location", (44.8333, -0.5667))
    assert m.json(
    ) == r'{"id": "id", "type": "type", "location": {"value": {"type": "Point", "coordinates": [-0.5667, 44.8333]}, "type": "geo:json"}}'
Beispiel #8
0
def test_add_field_date_from_str_old_way():
    m = DataModel("id", "type")
    m.add("dateObserved", "2018-01-01T15:00:00", isdate=True)
    assert m.json(
    ) == r'{"id": "id", "type": "type", "dateObserved": {"value": "2018-01-01T15:00:00", "type": "DateTime"}}'
Beispiel #9
0
def test_add_field_url_from_str_old_way():
    m = DataModel("id", "type")
    m.add("dataProvider", "https://www.fiware.org", isurl=True)
    assert m.json(
    ) == r'{"id": "id", "type": "type", "dataProvider": {"value": "https://www.fiware.org", "type": "URL"}}'
Beispiel #10
0
def test_add_field_bool():
    m = DataModel("id", "type")
    m.add("loading", True)
    assert m.json(
    ) == r'{"id": "id", "type": "type", "loading": {"value": true, "type": "Boolean"}}'
Beispiel #11
0
def test_add_field_float():
    m = DataModel("id", "type")
    m.add("temperature", 37.2)
    assert m.json(
    ) == r'{"id": "id", "type": "type", "temperature": {"value": 37.2, "type": "Float"}}'
Beispiel #12
0
def test_add_field_int():
    m = DataModel("id", "type")
    m.add("temperature", 37)
    assert m.json(
    ) == r'{"id": "id", "type": "type", "temperature": {"value": 37, "type": "Integer"}}'
def build_entity(row: Row) -> DataModel:
    r = row.record
    m = DataModel(id=r["room"], type="Room")
    m.add("temperature", r["temperature"])
    m.add("pressure", r["pressure"])
    return m
Beispiel #14
0
def build_entity(row: Row) -> DataModel:
    id, temperature, pressure = row.record.split(';')
    m = DataModel(id=id, type="Room")
    m.add("temperature", float(temperature))
    m.add("pressure", int(pressure))
    return m