Beispiel #1
0
def test_air_quality_observed(air_quality_observed, orion_client, clean_mongo,
                              crate_translator):
    entity = air_quality_observed
    subscription = {
        "description": "Test subscription",
        "subject": {
            "entities": [{
                "id": entity['id'],
                "type": entity['type']
            }],
            "condition": {
                "attrs": []  # all attributes
            }
        },
        "notification": {
            "http": {
                "url": notify_url
            },
            "attrs": [],  # all attributes
            "metadata": ["dateCreated", "dateModified"]
        }
    }
    orion_client.subscribe(subscription)
    orion_client.insert(entity)

    import time
    time.sleep(3)  # Give time for notification to be processed.

    entities = crate_translator.query()

    # Not exactly one because first insert generates 2 notifications, see...
    # https://fiware-orion.readthedocs.io/en/master/user/walkthrough_apiv2/index.html#subscriptions
    assert len(entities) > 0
Beispiel #2
0
def test_get(orion, clean_mongo, entity):
    r = orion.insert(entity)
    assert r.ok

    r = orion.get('entities')
    loaded_entities = json.loads(r.text)
    assert len(loaded_entities) == 1

    assert loaded_entities[0] == entity
def do_integration(entity, notify_url, orion_client, crate_translator):
    entity_id = entity['id']
    subscription = {
        "description": "Test subscription",
        "subject": {
            "entities": [{
                "id": entity_id,
                "type": "Room"
            }],
            "condition": {
                "attrs": [
                    "temperature",
                ]
            }
        },
        "notification": {
            "http": {
                "url": notify_url
            },
            "attrs": [
                "temperature",
            ],
            "metadata": ["dateCreated", "dateModified"]
        },
        "throttling": 5
    }
    orion_client.subscribe(subscription)
    orion_client.insert(entity)

    import time
    time.sleep(3)  # Give time for notification to be processed.

    entities = crate_translator.query()

    # Not exactly one because first insert generates 2 notifications, see...
    # https://fiware-orion.readthedocs.io/en/master/user/walkthrough_apiv2/index.html#subscriptions
    assert len(entities) > 0

    # Note: How Quantumleap will return entities is still not well defined.
    entities[0].pop(CrateTranslator.TIME_INDEX_NAME)
    entity.pop('pressure')
    entity['temperature'].pop('metadata')

    assert_ngsi_entity_equals(entities[0], entity)
Beispiel #4
0
def do_integration(entity, notify_url, orion_client, crate_translator):
    entity_id = entity['id']
    subscription = {
        "description": "Integration Test subscription",
        "subject": {
            "entities": [{
                "id": entity_id,
                "type": "Room"
            }],
            "condition": {
                "attrs": [
                    "temperature",
                ]
            }
        },
        "notification": {
            "http": {
                "url": notify_url
            },
            "attrs": [
                "temperature",
            ],
            "metadata": ["dateCreated", "dateModified"]
        },
        "throttling": 1,
    }
    orion_client.subscribe(subscription)
    orion_client.insert(entity)

    time.sleep(3)  # Give time for notification to be processed.

    entities = crate_translator.query()

    # Not exactly one because first insert generates 2 notifications, see...
    # https://fiware-orion.readthedocs.io/en/master/user/walkthrough_apiv2/index.html#subscriptions
    assert len(entities) > 0
    # Metadata still not supported
    entity['temperature'].pop('metadata')

    assert entities[0]['id'] == entity['id']
    assert entities[0]['type'] == entity['type']
    assert entities[0]['temperature'] == entity['temperature']
Beispiel #5
0
def test_delete(orion, clean_mongo, entity):
    r = orion.insert(entity)
    assert r.ok

    r = orion.delete(entity['id'])
    print(r.ok)
    print(r.text)

    r = orion.get('entities')
    loaded_entities = json.loads(r.text)
    assert len(loaded_entities) == 0
Beispiel #6
0
def test_update(orion, clean_mongo, entity):
    r = orion.insert(entity)
    assert r.ok

    v = 10 + 30 * random()
    attrs = {'temperature': {'value': v, 'type': 'Float'}}
    r = orion.update(entity['id'], attrs)
    assert r.ok

    r = orion.get('entities')
    assert r.ok

    loaded_entities = json.loads(r.text)
    loaded_v = loaded_entities[0]['temperature']['value']
    assert loaded_v == pytest.approx(v)
Beispiel #7
0
def test_insert(orion, clean_mongo, entity):
    r = orion.insert(entity)
    assert r.ok, r.text