def insert_test_data(entity_id=None): # 3 entity types, 2 entities for each, 10 updates for each entity. for t in ("AirQualityObserved", "Room", "TrafficFlowObserved"): for e in range(2): for u in range(10): ei = entity_id or '{}{}'.format(t, e) notification = create_notification(t, ei) data = json.dumps(notification) h = {'Content-Type': 'application/json'} r = requests.post(notify_url, data=data, headers=h) assert r.status_code == 200, r.text
def test_delete_no_type_with_multitenancy(service): """ A Car and a Truck with the same entity_id. Same thing in two different tenants (USA an EU). """ # You have a car1 car = json.dumps(create_notification("Car", "car1")) # In Default h_def = { 'Content-Type': 'application/json', 'Fiware-Service': service } r = requests.post(notify_url, data=car, headers=h_def) assert r.status_code == 200 # In EU h_eu = { 'Content-Type': 'application/json', 'Fiware-Service': 'EU' } r = requests.post(notify_url, data=car, headers=h_eu) assert r.status_code == 200 # In USA h_usa = { 'Content-Type': 'application/json', 'Fiware-Service': 'USA' } r = requests.post(notify_url, data=car, headers=h_usa) assert r.status_code == 200 time.sleep(SLEEP_TIME) # I could delete car1 from default without giving a type url = '{}/entities/{}'.format(QL_URL, 'car1') r = requests.delete(url, params={}, headers=h_def) assert r.status_code == 204, r.text # But it should still be in EU. r = requests.get(url, params={}, headers=h_eu) assert r.status_code == 200, r.text time.sleep(SLEEP_TIME) # I could delete car1 from EU without giving a type url = '{}/entities/{}'.format(QL_URL, 'car1') r = requests.delete(url, params={}, headers=h_eu) assert r.status_code == 204, r.text # But it should still be in USA. r = requests.get(url, params={}, headers=h_usa) assert r.status_code == 200, r.text delete_test_data(service, ["Car"]) delete_test_data('USA', ["Car"]) delete_test_data('EU', ["Car"])
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)
def insert_test_data(service, service_path=None, entity_id=None): # 3 entity types, 2 entities for each, 10 updates for each entity. for t in ("AirQualityObserved", "Room", "TrafficFlowObserved"): for e in range(2): for u in range(10): ei = entity_id or '{}{}'.format(t, e) notification = create_notification(t, ei) data = json.dumps(notification) h = { 'Content-Type': 'application/json', 'Fiware-Service': service } if service_path: h['Fiware-ServicePath'] = service_path r = requests.post(notify_url, data=data, headers=h) assert r.status_code == 200, r.text time.sleep(SLEEP_TIME)
def insert_test_data(service, service_path='/', entity_id=None): etypes = ['AirQualityObserved', 'Room', 'TrafficFlowObserved'] # 3 entity types, 2 entities for each, 10 updates for each entity. for t in etypes: for e in range(2): for u in range(10): ei = entity_id or '{}{}'.format(t, e) notification = create_notification(t, ei) data = json.dumps(notification) h = { 'Content-Type': 'application/json', 'Fiware-Service': service } if service_path: h['Fiware-ServicePath'] = service_path r = requests.post(notify_url, data=data, headers=h) assert r.status_code == 200, r.text wait_for_insert(etypes, service, 2 * 10)