コード例 #1
0
def test_no_value_with_type_for_attributes(service, notification):
    # entity with one Null value and no type
    notification['data'][0] = {
        'id': 'Hall1',
        'type': 'Hall',
        'odour': {
            'type': 'Text',
            'value': 'Good',
            'metadata': {}
        },
        'temperature': {
            'type': 'Number',
            'metadata': {}
        },
        'pressure': {
            'type': 'Number',
            'value': '26',
            'metadata': {}
        },
    }
    url = '{}'.format(notify_url)
    get_url = "{}/entities/Hall1/attrs/temperature/value".format(QL_URL)
    url_new = '{}'.format(get_url)
    r = requests.post(url,
                      data=json.dumps(notification),
                      headers=notify_header(service))
    assert r.status_code == 200
    # Give time for notification to be processed
    time.sleep(SLEEP_TIME)
    res_get = requests.get(url_new, headers=query_header(service))
    assert res_get.status_code == 200
    assert res_get.json()['values'][0] == None
    delete_entity_type(service, notification['data'][0]['type'])
コード例 #2
0
def test_json_ld_date_observed(service, notification):
    # example json-ld entity with custom index property
    notification['data'][0] = {
        "id": "urn:ngsi-ld:Device:filling001",
        "type": "FillingSensor",
        "dateObserved": {
            "type": "Property",
            "value": {
                "@type": "DateTime",
                "@value": "2018-08-07T12:00:00Z"
            }
        },
        "filling": {
            "type": "Property",
            "value": 0.94,
            "unitCode": "C62",
            "observedAt": "2021-01-28T12:33:20.000Z",
            "modifiedAt": "2021-01-28T12:33:22.000Z"
        }
    }
    get_url = "{}/entities/urn:ngsi-ld:Device:filling001".format(QL_URL)
    url_new = '{}'.format(get_url)
    h = notify_header(service)
    h['Fiware-TimeIndex-Attribute'] = 'dateObserved'

    insert_data(notification, h, service)

    res_get = requests.get(url_new, headers=query_header(service))
    assert res_get.status_code == 200
    expected_value = [
        notification['data'][0]['dateObserved']['value']['@value']
    ]
    assert_equal_time_index_arrays([res_get.json()['index'][0]],
                                   expected_value)
    delete_entity_type(service, notification['data'][0]['type'])
コード例 #3
0
def check_time_index(service, input_index, expected_index=None):
    expected_index = expected_index or input_index

    n0 = get_notification('Room', 'Room0', 0, input_index[0])
    n1 = get_notification('Room', 'Room0', 1, input_index[1])
    n2 = get_notification('Room', 'Room0', 2, input_index[2])

    send_notifications(service='', notifications=[n0, n1, n2])
    time.sleep(1)

    # Query
    r = requests.get(query_1T1E1A(), params={'type': 'Room'})
    assert r.status_code == 200, r.text
    obtained = r.json()

    # Check Response
    expected = {
        'entityId': 'Room0',
        'entityType': 'Room',
        'attrName': 'temperature',
        'index': expected_index,
        'values': [0, 1, 2]
    }
    assert_1T1E1A_response(obtained, expected)
    delete_entity_type('', 'Room')
コード例 #4
0
def test_issue_537(service, notification):
    # entity with one Null value and no type
    notification['data'][0] = {
        "id": "six",
        "type": "Thing",
        "serialNumber": {
            "type": "Text",
            "value":
            "type as Moosbllord, new value name doesthismatter2 and random values in an array",
            "metadata": {}
        },
        "doesthismatter2": {
            "type": "Moosbllord",
            "value": ["oglera8978sdfasd", "fdasfa6786sdf"],
            "metadata": {}
        }
    }
    url = '{}'.format(notify_url)
    get_url = "{}/entities/six/attrs/doesthismatter2/value".format(QL_URL)
    url_new = '{}'.format(get_url)
    insert_data(notification, notify_header(service), service)

    res_get = requests.get(url_new, headers=query_header(service))
    assert res_get.status_code == 200
    assert res_get.json()['values'][0] == ["oglera8978sdfasd", "fdasfa6786sdf"]
    delete_entity_type(service, notification['data'][0]['type'])
コード例 #5
0
def test_valid_no_modified(notification, service):
    notification['data'][0]['temperature']['metadata'].pop('dateModified')
    insert_data(notification, notify_header(service), service)

    r = requests.get(query_url(), params=None, headers=query_header(service))
    assert r.status_code == 200, r.text
    delete_entity_type(service, 'Room')
コード例 #6
0
def test_invalid_no_value(notification, service):
    notification['data'][0]['temperature'].pop('value')
    r = requests.post('{}'.format(notify_url),
                      data=json.dumps(notification),
                      headers=notify_header(service))
    assert r.status_code == 200
    delete_entity_type(service, 'Room')
コード例 #7
0
def test_no_value_no_type_for_attributes(service, notification):
    # entity with no value and no type
    notification['data'][0] = {
        'id': 'Room1',
        'type': 'Room',
        'odour': {
            'type': 'Text',
            'value': 'Good',
            'metadata': {}
        },
        'temperature': {
            'metadata': {}
        },
        'pressure': {
            'type': 'Number',
            'value': 26,
            'metadata': {}
        },
    }
    url = '{}'.format(notify_url)
    get_url = "{}/entities/Room1/attrs/temperature/value".format(QL_URL)
    url_new = '{}'.format(get_url)
    r = requests.post(url,
                      data=json.dumps(notification),
                      headers=notify_header(service))
    assert r.status_code == 200
    # Give time for notification to be processed
    time.sleep(SLEEP_TIME)
    res_get = requests.get(url_new, headers=query_header(service))
    assert res_get.status_code == 404
    # Get value of attribute having value
    get_url_new = "{}/entities/Room1/attrs/pressure/value".format(QL_URL)
    url_new = '{}'.format(get_url_new)
    res_get = requests.get(url_new, headers=query_header(service))
    assert res_get.status_code == 200
    assert res_get.json()['values'][0] == 26

    # entity with value other than Null
    notification['data'][0] = {
        'id': 'Room1',
        'type': 'Room',
        'temperature': {
            'type': 'Number',
            'value': 25,
            'metadata': {}
        }
    }
    url = '{}'.format(notify_url)
    get_url = "{}/entities/Room1/attrs/temperature/value".format(QL_URL)
    url_new = '{}'.format(get_url)
    r = requests.post(url,
                      data=json.dumps(notification),
                      headers=notify_header(service))
    assert r.status_code == 200
    # Give time for notification to be processed
    time.sleep(SLEEP_TIME)
    res_get = requests.get(url_new, headers=query_header(service))
    assert res_get.status_code == 200
    assert res_get.json()['values'][1] == 25
    delete_entity_type(service, notification['data'][0]['type'])
コード例 #8
0
def test_geocoding(service, notification):
    # Add an address attribute to the entity
    notification['data'][0]['address'] = {
        'type': 'StructuredValue',
        'value': {
            "streetAddress": "Kaivokatu",
            "postOfficeBoxNumber": "1",
            "addressLocality": "Helsinki",
            "addressCountry": "FI",
        },
        'metadata': {
            'dateModified': {
                'type': 'DateTime',
                'value': '2017-06-19T11:46:45.00Z'
            }
        }
    }
    insert_data(notification, notify_header(service), service)

    entities_url = "{}/entities".format(QL_URL)

    r = requests.get(entities_url, params=None, headers=query_header(service))
    assert r.status_code == 200
    entities = r.json()
    assert len(entities) == 1

    assert 'location' in entities[0]
    assert entities[0]['location']['type'] == 'geo:point'
    lon, lat = entities[0]['location']['values'][0].split(',')
    assert float(lon) == pytest.approx(60.1707129, abs=1e-2)
    assert float(lat) == pytest.approx(24.9412167, abs=1e-2)
    delete_entity_type(service, notification['data'][0]['type'])
コード例 #9
0
def test_multiple_data_elements_different_servicepath(service, notification):
    """
    Test that the notify API can process notifications containing multiple elements in the data array
    and different fiwareServicePath.
    """

    notify_headers = notify_header(service)

    notify_headers[
        'Fiware-ServicePath'] = '/Test/Path1, /Test/Path1, /Test/Path2'

    query_headers = query_header(service)

    query_headers['Fiware-ServicePath'] = '/Test'

    etype = 'test_multiple_data_elements_different_servicepath'
    # ^ avoid interfering w/ other tests
    notification['data'] = entities_with_different_attrs(etype)

    insert_data(notification, notify_headers, service)

    entities_url = "{}/entities".format(QL_URL)
    r = requests.get(entities_url, params=None, headers=query_headers)
    entities = find_by_type(etype, r.json())
    #          ^ i.e. don't assume there's no other data in the DB!
    # some tests don't delete their data to speed up the test run.
    assert len(entities) == 3

    delete_entity_type(service, etype)
コード例 #10
0
def test_issue_382(service, notification):
    # entity with one Null value and no type
    notification['data'][0] = {
        "id": "urn:ngsi-ld:Test:0002",
        "type": "Test",
        "errorNumber": {
            "type": "Integer",
            "value": 2
        },
        "refVacuumPump": {
            "type": "Relationship",
            "value": "urn:ngsi-ld:VacuumPump:FlexEdgePump"
        },
        "refOutgoingPallet": {
            "type": "Array",
            "value": ["urn:ngsi-ld:Pallet:0003", "urn:ngsi-ld:Pallet:0004"]
        }
    }
    url = '{}'.format(notify_url)
    get_url = "{}/entities/urn:ngsi-ld:Test:0002/attrs/errorNumber/value".format(
        QL_URL)
    url_new = '{}'.format(get_url)
    insert_data(notification, notify_header(service), service)

    res_get = requests.get(url_new, headers=query_header(service))
    assert res_get.status_code == 200
    assert res_get.json()['values'][0] == 2
    delete_entity_type(service, notification['data'][0]['type'])
コード例 #11
0
def test_json_ld_date_modified_at_attribute(service, notification):
    # example json-ld entity with modifiedAt as attribute
    notification['data'][0] = {
        "id": "urn:ngsi-ld:Device:filling001",
        "type": "FillingSensor",
        "modifiedAt": "2021-01-28T12:33:22.000Z",
        "filling": {
            "type": "Property",
            "value": 0.94,
            "unitCode": "C62"
        }
    }
    url = '{}'.format(notify_url)
    get_url = "{}/entities/urn:ngsi-ld:Device:filling001".format(QL_URL)
    url_new = '{}'.format(get_url)
    r = requests.post(url,
                      data=json.dumps(notification),
                      headers=notify_header(service))
    assert r.status_code == 200
    # Give time for notification to be processed
    time.sleep(SLEEP_TIME)
    res_get = requests.get(url_new, headers=query_header(service))
    assert res_get.status_code == 200
    expected_value = [notification['data'][0]['modifiedAt']]
    assert_equal_time_index_arrays([res_get.json()['index'][0]],
                                   expected_value)
    delete_entity_type(service, notification['data'][0]['type'])
コード例 #12
0
def test_multiple_data_elements_different_servicepath(
        service, notification, diffEntityWithDifferentAttrs):
    """
    Test that the notify API can process notifications containing multiple elements in the data array
    and different fiwareServicePath.
    """

    notify_headers = notify_header(service)

    notify_headers[
        'Fiware-ServicePath'] = '/Test/Path1, /Test/Path1, /Test/Path2'

    query_headers = query_header(service)

    query_headers['Fiware-ServicePath'] = '/Test'

    notification['data'] = diffEntityWithDifferentAttrs

    r = requests.post('{}'.format(notify_url),
                      data=json.dumps(notification),
                      headers=notify_headers)
    assert r.status_code == 200
    assert r.json().startswith('Notification successfully processed')

    entities_url = "{}/entities".format(QL_URL)
    time.sleep(2 * SLEEP_TIME)
    r = requests.get(entities_url, params=None, headers=query_headers)
    entities = r.json()
    assert len(entities) == 3
    delete_entity_type(service, diffEntityWithDifferentAttrs[0]['type'],
                       '/Test')
コード例 #13
0
def test_json_ld_both_at_meta(service, notification):
    # example json-ld entity with modifiedAt and observedAt as metadata
    notification['data'][0] = {
        "id": "urn:ngsi-ld:Device:filling001",
        "type": "FillingSensor",
        "modifiedAt": "2021-01-28T12:33:22.000Z",
        "filling": {
            "type": "Property",
            "value": 0.94,
            "unitCode": "C62",
            "observedAt": "2021-01-28T12:33:20.000Z",
            "modifiedAt": "2021-01-28T12:33:22.000Z"
        }
    }
    url = '{}'.format(notify_url)
    get_url = "{}/entities/urn:ngsi-ld:Device:filling001".format(QL_URL)
    url_new = '{}'.format(get_url)
    insert_data(notification, notify_header(service), service)

    res_get = requests.get(url_new, headers=query_header(service))
    assert res_get.status_code == 200
    expected_value = [notification['data'][0]['filling']['observedAt']]
    assert_equal_time_index_arrays([res_get.json()['index'][0]],
                                   expected_value)
    delete_entity_type(service, notification['data'][0]['type'])
コード例 #14
0
def test_no_value_with_type_for_attributes(service, notification):
    # entity with one Null value and no type
    notification['data'][0] = {
        'id': 'Hall1',
        'type': 'Hall',
        'odour': {
            'type': 'Text',
            'value': 'Good',
            'metadata': {}
        },
        'temperature': {
            'type': 'Number',
            'metadata': {}
        },
        'pressure': {
            'type': 'Number',
            'value': 26,
            'metadata': {}
        },
    }
    url = '{}'.format(notify_url)
    get_url = "{}/entities/Hall1/attrs/temperature/value".format(QL_URL)
    url_new = '{}'.format(get_url)
    insert_data(notification, notify_header(service), service)

    res_get = requests.get(url_new, headers=query_header(service))
    assert res_get.status_code == 200
    assert res_get.json()['values'][0] is None
    delete_entity_type(service, notification['data'][0]['type'])
コード例 #15
0
def do_integration(entity,
                   subscription,
                   orion_client,
                   service=None,
                   service_path=None):
    subscription_id = orion_client.subscribe(subscription, service,
                                             service_path). \
        headers['Location'][18:]
    time.sleep(SLEEP_TIME)

    orion_client.insert(entity, service, service_path)
    time.sleep(4 * SLEEP_TIME)  # Give time for notification to be processed.

    entities_url = "{}/entities".format(QL_URL)

    h = headers(service=service, service_path=service_path, content_type=False)

    r = requests.get(entities_url, params=None, headers=h)
    assert r.status_code == 200
    entities = r.json()
    assert len(entities) == 1

    assert entities[0]['id'] == entity['id']
    assert entities[0]['type'] == entity['type']

    delete_entity_type(service, entity['type'], service_path)
    orion_client.delete(entity['id'], service, service_path)
    orion_client.delete_subscription(subscription_id, service, service_path)
コード例 #16
0
def test_no_value_in_notification(service, notification):
    # No value
    notification['data'][0] = {
        'id': '299531',
        'type': 'AirQualityObserved',
        'p': {
            'type': 'string',
            'value': '994',
            'metadata': {}
        },
        'ti': {
            'type': 'ISO8601',
            'value': ' ',
            'metadata': {}
        },
        'pm10': {
            'type': 'string',
            'metadata': {}
        },
        'pm25': {
            'type': 'string',
            'value': '5',
            'metadata': {}
        },
    }
    url = '{}'.format(notify_url)
    r = requests.post(url,
                      data=json.dumps(notification),
                      headers=notify_header(service))
    assert r.status_code == 200

    # Empty value
    notification['data'][0] = {
        'id': '299531',
        'type': 'AirQualityObserved',
        'p': {
            'type': 'string',
            'value': '994',
            'metadata': {}
        },
        'pm10': {
            'type': 'string',
            'value': '0',
            'metadata': {}
        },
        'pm25': {
            'type': 'string',
            'value': '',
            'metadata': {}
        },
    }
    url = '{}'.format(notify_url)
    r = requests.post(url,
                      data=json.dumps(notification),
                      headers=notify_header(service))
    assert r.status_code == 200
    delete_entity_type(service, notification['data'][0]['type'])
コード例 #17
0
def test_integration_multiple_entities(service, diffEntityWithDifferentAttrs,
                                       orion_client):
    """
    Test Reporter using input directly from an Orion notification and output
    directly to Cratedb.
    """

    subscription = {
        "description": "Integration Test subscription",
        "subject": {
            "entities": [
                {
                    "idPattern": ".*",
                    "type": "Room"
                }
            ],
            "condition": {
                "attrs": [
                    "temperature",
                ]
            }
        },
        "notification": {
            "http": {
                "url": notify_url
            },
            "attrs": [
                "temperature",
            ],
            "metadata": ["dateCreated", "dateModified"]
        },
        "throttling": 1,
    }
    subscription_id = orion_client.subscribe(subscription, service,
                                             "/Root/#"). \
                          headers['Location'][18:]

    for idx, e in enumerate(diffEntityWithDifferentAttrs):
        orion_client.insert(e, service, "/Root/{}".format(idx))
    time.sleep(10 * SLEEP_TIME)  # Give time for notification to be processed.

    entities_url = "{}/entities".format(QL_URL)

    r = requests.get(entities_url, params=None,
                     headers=query_header(service, "/Root"))
    assert r.status_code == 200
    entities = r.json()
    assert len(entities) == 3
    delete_entity_type(service, diffEntityWithDifferentAttrs[0]['type'],
                       "/Root")

    for idx, e in enumerate(diffEntityWithDifferentAttrs):
        orion_client.insert(e, service, "/Root/{}".format(idx))
        orion_client.delete(e['id'], service, "/Root/{}".format(idx))
    orion_client.delete_subscription(subscription_id, service,
                                     "/Root/#")
コード例 #18
0
def setup_entities():
    notification_data = [{'data': [e]} for e in [entity_1, entity_2]]
    for service in services:
        send_notifications(service, notification_data)
        wait_for_insert([entity_type], service, 2)

    yield {}

    for service in services:
        delete_entity_type(service, entity_type)
コード例 #19
0
def test_valid_notification(notification, service):
    r = requests.post('{}'.format(notify_url),
                      data=json.dumps(notification),
                      headers=notify_header(service))
    assert r.status_code == 200
    assert r.json().startswith('Notification successfully processed')
    time.sleep(SLEEP_TIME)
    r = requests.get(query_url(), params=None, headers=query_header(service))
    assert r.status_code == 200, r.text
    delete_entity_type(service, 'Room')
コード例 #20
0
def test_time_index(service):
    etype = 'test_time_index'  # avoid interfering w/ other tests
    notification = create_notification(entity_type=etype)

    # If present, use entity-level dateModified as time_index
    global_modified = datetime(2000, 1, 2, 0, 0, 0, 0,
                               timezone.utc).isoformat()
    modified = {'type': 'DateTime', 'value': global_modified}
    notification['data'][0]['dateModified'] = modified
    insert_data(notification, notify_header(service), service)

    entities_url = "{}/entities".format(QL_URL)
    r = requests.get(entities_url, params=None, headers=query_header(service))
    entities = find_by_type(etype, r.json())
    #          ^ i.e. don't assume there's no other data in the DB!
    # some tests don't delete their data to speed up the test run.
    assert len(entities) == 1
    assert_equal_time_index_arrays([entities[0]['index']], [global_modified])

    # If not, use newest of changes
    notification['data'][0].pop('dateModified')
    temp = notification['data'][0]['temperature']
    notification['data'][0]['pressure'] = copy.deepcopy(temp)

    older = datetime(2001, 1, 2, 0, 0, 0, 0, timezone.utc).isoformat()
    newer = datetime(2002, 1, 2, 0, 0, 0, 0, timezone.utc).isoformat()
    e = notification['data'][0]
    e['temperature']['metadata']['dateModified']['value'] = older
    e['pressure']['metadata']['dateModified']['value'] = newer

    insert_data(notification, notify_header(service), service)
    time.sleep(SLEEP_TIME)  # still needed b/c of entity update w/ new attr

    r = requests.get(entities_url, params=None, headers=query_header(service))
    entities = find_by_type(etype, r.json())
    assert len(entities) == 1
    obtained = [entities[0]['index']]
    assert_equal_time_index_arrays(obtained, [global_modified, newer])

    # Otherwise, use current time.
    current = datetime.now()
    notification['data'][0]['pressure'].pop('metadata')
    notification['data'][0]['temperature'].pop('metadata')
    insert_data(notification, notify_header(service), service)
    time.sleep(SLEEP_TIME)  # still needed b/c of entity update w/ new attr

    r = requests.get(entities_url, params=None, headers=query_header(service))
    entities = find_by_type(etype, r.json())
    assert len(entities) == 1
    obtained = [entities[0]['index']]
    assert obtained[-1].startswith("{}".format(current.year))

    delete_entity_type(service, etype)
コード例 #21
0
def test_for_valid_headers(notification):
    notification['data'][0] = {
        'id': 'Room0',
        'type': 'Room',
        'temperature': {
            'type': 'Number',
            'value': '100',
            'metadata': {
                'dateModified': {
                    'type': 'DateTime',
                    'value': '1980-01-30T00:00:00.000+00:00'
                }
            }
        },
        'pressure': {
            'type': 'Number',
            'value': '10',
            'metadata': {
                'dateModified': {
                    'type': 'DateTime',
                    'value': '1980-01-30T00:00:00.000+00:00'
                }
            }
        },
    }

    res_post = requests.post('{}'.format(notify_url),
                             data=json.dumps(notification),
                             headers=HEADERS_VALID)
    time.sleep(1)
    assert res_post.status_code == 200
    assert res_post.json().startswith('Notification successfully processed')

    get_url = "{}/entities/Room0".format(QL_URL)
    res_get = requests.get(get_url, headers=HEADERS_VALID)

    assert res_get.status_code == 200

    exp_values = {
        "attributes": [{
            'attrName': 'pressure',
            'values': [10.0]
        }, {
            'attrName': 'temperature',
            'values': [100.0]
        }],
        "entityId":
        'Room0',
        "index": ['1980-01-30T00:00:00.000+00:00']
    }
    assert res_get.json() == exp_values
    delete_entity_type('test', 'Room')
コード例 #22
0
def run_test(service, entity_type, attr_name):
    entity = mk_entity('d1', entity_type, attr_name)

    insert_entity(service, entity)

    query_result = query_entity(service, entity['id'], attr_name)
    query_result.pop('index', None)
    assert query_result == {
        'attrName': attr_name,
        'entityId': entity['id'],
        'values': [entity[attr_name]['value']]
    }

    delete_entity_type(service, entity['type'])
コード例 #23
0
def test_for_valid_headers(notification):
    notification['data'][0] = {
        'id': 'Room0',
        'type': ENTITY_TYPE,
        'temperature': {
            'type': 'Number',
            'value': '100',
            'metadata': {
                'dateModified': {
                    'type': 'DateTime',
                    'value': '1980-01-30T00:00:00.000+00:00'
                }
            }
        },
        'pressure': {
            'type': 'Number',
            'value': '10',
            'metadata': {
                'dateModified': {
                    'type': 'DateTime',
                    'value': '1980-01-30T00:00:00.000+00:00'
                }
            }
        },
    }

    insert_data(notification, HEADERS_VALID)

    get_url = "{}/entities/Room0".format(QL_URL)
    res_get = requests.get(get_url, headers=HEADERS_VALID)

    assert res_get.status_code == 200

    exp_values = {
        "attributes": [{
            'attrName': 'pressure',
            'values': [10.0]
        }, {
            'attrName': 'temperature',
            'values': [100.0]
        }],
        "entityId":
        'Room0',
        "entityType":
        'Room',
        "index": ['1980-01-30T00:00:00.000+00:00']
    }
    assert res_get.json() == exp_values
    delete_entity_type('test', 'Room')
コード例 #24
0
def test_valid_data_for_type(notification, service, e_type, e_value,
                             exp_value):
    del notification['data'][0]['temperature']

    notification['data'][0][e_type.lower()] = {
        'type': e_type,
        'value': e_value
    }
    insert_data(notification, notify_header(service), service)

    r = requests.get(query_url(attr_name=e_type.lower(), last=True),
                     params=None,
                     headers=query_header(service))
    assert r.status_code == 200
    assert r.json()['values'][0] == exp_value

    delete_entity_type(service, 'Room')
コード例 #25
0
def test_valid_data_for_type(notification, service, e_type, e_value,
                             exp_value):
    del notification['data'][0]['temperature']

    notification['data'][0][e_type.lower()] = {
        'type': e_type,
        'value': e_value
    }
    r = requests.post('{}'.format(notify_url),
                      data=json.dumps(notification),
                      headers=notify_header(service))
    assert r.status_code == 200
    time.sleep(SLEEP_TIME)
    r = requests.get(query_url(attr_name=e_type.lower(), last=True),
                     params=None,
                     headers=query_header(service))
    assert r.status_code == 200
    assert r.json()['values'][0] == exp_value

    delete_entity_type(service, 'Room')
コード例 #26
0
def test_valid_notification(notification, service):
    insert_data(notification, notify_header(service), service)

    r = requests.get(query_url(), params=None, headers=query_header(service))
    assert r.status_code == 200, r.text
    delete_entity_type(service, 'Room')
コード例 #27
0
def test_json_ld(service, notification):
    # example json-ld entity
    notification['data'][0] = {
        "id":
        "urn:ngsi-ld:Streetlight:streetlight:guadalajara:4567",
        "type":
        "Streetlight",
        "location": {
            "type": "GeoProperty",
            "value": {
                "type": "Point",
                "coordinates": [-3.164485591715449, 40.62785133667262]
            }
        },
        "areaServed": {
            "type": "Property",
            "value": "Roundabouts city entrance"
        },
        "status": {
            "type": "Property",
            "value": "ok"
        },
        "refStreetlightGroup": {
            "type": "Relationship",
            "object": "urn:ngsi-ld:StreetlightGroup:streetlightgroup:G345"
        },
        "refStreetlightModel": {
            "type":
            "Relationship",
            "object":
            "urn:ngsi-ld:StreetlightModel:streetlightmodel:STEEL_Tubular_10m"
        },
        "circuit": {
            "type": "Property",
            "value": "C-456-A467"
        },
        "lanternHeight": {
            "type": "Property",
            "value": 10
        },
        "locationCategory": {
            "type": "Property",
            "value": "centralIsland"
        },
        "powerState": {
            "type": "Property",
            "value": "off"
        },
        "controllingMethod": {
            "type": "Property",
            "value": "individual"
        },
        "dateLastLampChange": {
            "type": "Property",
            "value": {
                "@type": "DateTime",
                "@value": "2016-07-08T08:02:21.753Z"
            }
        },
        "@context": [
            "https://schema.lab.fiware.org/ld/context",
            "https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-context.jsonld"
        ]
    }
    url = '{}'.format(notify_url)
    get_url = "{}/entities/urn:ngsi-ld:Streetlight:streetlight:guadalajara:4567/attrs/lanternHeight/value".format(
        QL_URL)
    url_new = '{}'.format(get_url)
    insert_data(notification, notify_header(service), service)

    res_get = requests.get(url_new, headers=query_header(service))
    assert res_get.status_code == 200
    assert res_get.json()['values'][0] == 10
    delete_entity_type(service, notification['data'][0]['type'])
コード例 #28
0
def test_integration_multiple_values(service, entity, orion_client,
                                     clean_mongo):
    subscription = {
        "description": "Integration Test subscription",
        "subject": {
            "entities": [{
                "id": entity['id'],
                "type": "Room"
            }],
            "condition": {
                "attrs": []  # all attributes
            }
        },
        "notification": {
            "http": {
                "url": notify_url
            },
            "attrs": [],  # all attributes
            "metadata": ["dateCreated", "dateModified"]
        },
        "throttling": 1,
    }
    subscription_id = orion_client.subscribe(subscription, service, '/'). \
        headers['Location'][18:]
    time.sleep(SLEEP_TIME)

    orion_client.insert(entity, service, '/')
    time.sleep(4 * SLEEP_TIME)  # Give time for notification to be processed.

    # Update values in Orion
    for i in range(1, 4):
        attrs = {
            'temperature': {
                'value': entity['temperature']['value'] + i,
                'type': 'Number',
            },
            'pressure': {
                'value': entity['pressure']['value'] + i,
                'type': 'Number',
            },
        }
        orion_client.update_attr(entity['id'], attrs, service, '/')
        time.sleep(1)

    # Query in Quantumleap
    query_params = {
        'type': entity['type'],
    }
    query_url = "{qlUrl}/entities/{entityId}".format(
        qlUrl=QL_URL,
        entityId=entity['id'],
    )
    r = requests.get(query_url,
                     params=query_params,
                     headers=query_header(service, "/"))
    assert r.status_code == 200, r.text
    data = r.json()
    assert len(data['index']) > 1
    assert len(data['attributes']) == 2

    # Note some notifications may have been lost
    pressures = data['attributes'][0]['values']
    assert set(pressures).issubset(set([720.0, 721.0, 722.0, 723.0]))
    temperatures = data['attributes'][1]['values']
    assert set(temperatures).issubset(set([24.2, 25.2, 26.2, 27.2]))
    delete_entity_type(service, entity['type'], "/")
    orion_client.delete(entity['id'], service, '/')
    orion_client.delete_subscription(subscription_id, service, '/')
コード例 #29
0
def test_integration_custom_index(service, entity, orion_client, clean_mongo):
    subscription = {
        "description": "Integration Test subscription",
        "subject": {
            "entities": [{
                "id": entity['id'],
                "type": "Room"
            }],
            "condition": {
                "attrs": []  # all attributes
            }
        },
        "notification": {
            "httpCustom": {
                "url": notify_url,
                "headers": {
                    "Fiware-TimeIndex-Attribute": "myCustomIndex"
                },
            },
            "attrs": [],  # all attributes
            "metadata": ["dateCreated", "dateModified"]
        },
        "throttling": 1,
    }

    orion_client.subscribe(subscription, service, '/')
    time.sleep(SLEEP_TIME)

    # Insert values in Orion
    entity['myCustomIndex'] = {
        'value': '2019-08-22T18:22:00',
        'type': 'DateTime',
        'metadata': {}
    }
    entity.pop('temperature')
    entity.pop('pressure')

    orion_client.insert(entity, service, '/')
    time.sleep(4 * SLEEP_TIME)  # Give time for notification to be processed.

    # Update values in Orion
    for i in range(1, 4):
        attrs = {
            'myCustomIndex': {
                'value': '2019-08-22T18:22:0{}'.format(i),
                'type': 'DateTime',
            },
        }
        orion_client.update_attr(entity['id'], attrs, service, '/')
        time.sleep(1)

    # Query in Quantumleap
    query_params = {
        'type': entity['type'],
    }
    query_url = "{qlUrl}/entities/{entityId}".format(
        qlUrl=QL_URL,
        entityId=entity['id'],
    )
    r = requests.get(query_url,
                     params=query_params,
                     headers=query_header(service, "/"))
    assert r.status_code == 200, r.text

    data = r.json()
    # Note some notifications may have been lost
    assert data['attributes'][0]['values'] == data['index']
    assert len(data['index']) > 1
    delete_entity_type(service, entity['type'], '/')
コード例 #30
0
def test_no_value_for_attributes(service, notification):
    # with empty value
    notification['data'][0] = {
        'id': '299531',
        'type': 'AirQualityObserved',
        'p': {
            'type': 'string',
            'value': '',
            'metadata': {}
        },
        'pm10': {
            'type': 'string',
            'value': '',
            'metadata': {}
        },
        'pm25': {
            'type': 'string',
            'value': '',
            'metadata': {}
        },
    }
    url = '{}'.format(notify_url)
    get_url = "{}/entities/299531".format(QL_URL)
    url_new = '{}'.format(get_url)
    r = requests.post(url,
                      data=json.dumps(notification),
                      headers=notify_header(service))
    assert r.status_code == 200
    # Give time for notification to be processed
    time.sleep(SLEEP_TIME)
    res_get = requests.get(url_new, headers=notify_header(service))
    assert res_get.status_code == 404
    # entity with missing value string
    notification['data'][0] = {
        'id': '299531',
        'type': 'AirQualityObserved',
        'p': {
            'type': 'string'
        },
        'pm10': {
            'type': 'string',
            'value': '',
            'metadata': {}
        },
        'pm25': {
            'type': 'string',
            'value': '',
            'metadata': {}
        },
    }
    url = '{}'.format(notify_url)
    get_url = "{}/entities/299531/attrs/p/value".format(QL_URL)
    url_new = '{}'.format(get_url)
    r = requests.post(url,
                      data=json.dumps(notification),
                      headers=notify_header(service))
    assert r.status_code == 200
    # Give time for notification to be processed
    time.sleep(SLEEP_TIME)
    res_get = requests.get(url_new, headers=query_header(service))
    assert res_get.status_code == 404
    # entity has both valid and empty attributes
    notification['data'][0] = {
        'id': '299531',
        'type': 'AirQualityObserved',
        'p': {
            'type': 'string'
        },
        'pm10': {
            'type': 'string',
            'value': '10',
            'metadata': {}
        },
    }
    url = '{}'.format(notify_url)
    get_url_new = "{}/entities/299531/attrs/pm10/value".format(QL_URL)
    url_new = '{}'.format(get_url_new)
    r = requests.post(url,
                      data=json.dumps(notification),
                      headers=notify_header(service))
    assert r.status_code == 200
    # Give time for notification to be processed
    time.sleep(SLEEP_TIME)
    res_get = requests.get(url_new, headers=query_header(service))
    assert res_get.status_code == 200
    assert res_get.json()['values'][0] == '10'
    delete_entity_type(service, notification['data'][0]['type'])