Skip to content

Commit

Permalink
Merge 162cf52 into f732532
Browse files Browse the repository at this point in the history
  • Loading branch information
taliaga committed Aug 23, 2019
2 parents f732532 + 162cf52 commit fdae11e
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 12 deletions.
7 changes: 7 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# QuantumLeap Release Notes

## 0.7.4

- Fix bug with Custom Time Index header handling (#247)
- Timescale backend fixes (#243 #246)
- Bring back /ui endpoint (#229)
- Update dependencies (#244)

## 0.7.3

- Relax Crate health check (#239)
Expand Down
2 changes: 1 addition & 1 deletion src/reporter/reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def notify():

# Add TIME_INDEX attribute
entity[CrateTranslator.TIME_INDEX_NAME] = \
select_time_index_value_as_iso(request.headers, entity)
select_time_index_value_as_iso(dict(request.headers), entity)

# Add GEO-DATE if enabled
add_geodata(entity)
Expand Down
2 changes: 1 addition & 1 deletion src/reporter/tests/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ services:
image: fiware/orion:${ORION_VERSION}
ports:
- "1026:1026"
command: -logLevel DEBUG -dbhost mongo
command: -logLevel DEBUG -noCache -dbhost mongo
depends_on:
- mongo
healthcheck:
Expand Down
69 changes: 64 additions & 5 deletions src/reporter/tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def test_integration(entity, clean_mongo, clean_crate):
data = json.dumps(entity)
r = requests.post('{}/entities'.format(ORION_URL), data=data, headers=h)
assert r.ok
time.sleep(2)
time.sleep(1)

# Update values in Orion
for i in range(1, 4):
Expand All @@ -35,7 +35,7 @@ def test_integration(entity, clean_mongo, clean_crate):
endpoint = '{}/entities/{}/attrs'.format(ORION_URL, entity['id'])
r = requests.patch(endpoint, data=json.dumps(attrs), headers=h)
assert r.ok
time.sleep(2)
time.sleep(1)

# Query in Quantumleap
query_params = {
Expand All @@ -48,7 +48,66 @@ def test_integration(entity, clean_mongo, clean_crate):
r = requests.get(query_url, params=query_params)
assert r.status_code == 200, r.text
data = r.json()
assert len(data['index']) == 4
assert len(data['index']) > 1
assert len(data['attributes']) == 2
assert data['attributes'][0]['values'] == [720.0, 721.0, 722.0, 723.0]
assert data['attributes'][1]['values'] == [24.2, 25.2, 26.2, 27.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]))


def test_integration_custom_index(entity, clean_mongo, clean_crate):
# Subscribe QL to Orion
params = {
'orionUrl': ORION_URL,
'quantumleapUrl': QL_URL,
'timeIndexAttribute': 'myCustomIndex'
}
r = requests.post("{}/subscribe".format(QL_URL), params=params)
assert r.status_code == 201

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

data = json.dumps(entity)
h = {'Content-Type': 'application/json'}
r = requests.post('{}/entities'.format(ORION_URL), data=data, headers=h)
assert r.ok
time.sleep(1)

# Update values in Orion
for i in range(1, 4):
attrs = {
'myCustomIndex': {
'value': '2019-08-22T18:22:0{}'.format(i),
'type': 'DateTime',
},
}
endpoint = '{}/entities/{}/attrs'.format(ORION_URL, entity['id'])
r = requests.patch(endpoint, data=json.dumps(attrs), headers=h)
assert r.ok
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)
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
18 changes: 18 additions & 0 deletions src/reporter/tests/test_timex.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from datetime import *
from reporter.timex import *
import pytest


def build_notification(custom, ti, ts, dm,
Expand Down Expand Up @@ -73,6 +74,23 @@ def test_custom_index_takes_priority():
select_time_index_value(headers, notification)


@pytest.mark.parametrize('header_name', [
TIME_INDEX_HEADER_NAME,
TIME_INDEX_HEADER_NAME.lower(),
TIME_INDEX_HEADER_NAME.swapcase()
])
def test_headers_are_case_insensitive(header_name):
headers = {
header_name: 'customTimeIndex'
}
custom_time_index_value = datetime(2019, 1, 1)
ts = build_notification_timepoints(custom_time_index_value)
notification = build_notification(*ts)

assert custom_time_index_value == \
select_time_index_value(headers, notification)


def test_use_latest_meta_custom_index():
headers = {
TIME_INDEX_HEADER_NAME: 'customTimeIndex'
Expand Down
2 changes: 1 addition & 1 deletion src/reporter/tests/test_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ def test_version():
r = requests.get('{}'.format(version_url))
assert r.status_code == 200, r.text
assert r.json() == {
"version": "0.7.3"
"version": "0.7.4"
}
5 changes: 2 additions & 3 deletions src/reporter/timex.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from datetime import datetime
from typing import Iterable, Union

from utils.common import iter_entity_attrs
from utils.jsondict import maybe_value
from utils.jsondict import maybe_value, maybe_string_match
from utils.timestr import latest_from_str_rep, to_datetime

TIME_INDEX_HEADER_NAME = 'Fiware-TimeIndex-Attribute'
Expand Down Expand Up @@ -37,7 +36,7 @@ def time_index_priority_list(headers: dict, notification: dict) -> datetime:
Returns the next possible time_index value using the strategy described in
the function select_time_index_value.
"""
custom_attribute = maybe_value(headers, TIME_INDEX_HEADER_NAME)
custom_attribute = maybe_string_match(headers, TIME_INDEX_HEADER_NAME)

# Custom time index attribute
yield to_datetime(_attribute(notification, custom_attribute))
Expand Down
2 changes: 1 addition & 1 deletion src/reporter/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

def version():
return {
'version': '0.7.3'
'version': '0.7.4'
}

0 comments on commit fdae11e

Please sign in to comment.