-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* develop: Uncomment master deployment pipeline stage Rename LSSTTS_DEV_VERSION for dev_cycle Rollback to develop-env c0017.000 Remove deprecated command Upgrade to lsstts/develop-env:c0018.000 Build docker images from tickets branch Remove except specification to catch all exceptions Improve EFD tests Add EFD reconnection when after it failst on startup Add flake8 project config file Linter fixes
- Loading branch information
Showing
9 changed files
with
139 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,8 @@ | |
# Cycle to build | ||
# | ||
cycle=c0014 | ||
|
||
# | ||
# Development cycle to build | ||
# | ||
dev_cycle=c0017.000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[flake8] | ||
ignore = E128, E231 | ||
max-line-length = 120 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,78 +1,104 @@ | ||
import json | ||
import asyncio | ||
from aiohttp import web | ||
from unittest.mock import patch | ||
from itertools import chain, combinations | ||
from lsst.ts import salobj | ||
from commander.app import create_app | ||
from utils import NumpyEncoder | ||
from tests import conftest | ||
import pytest | ||
import pandas as pd | ||
from unittest.mock import patch, call, MagicMock | ||
from unittest.mock import patch, MagicMock | ||
from aiohttp.test_utils import TestClient, TestServer | ||
|
||
|
||
# Patch for using MagicMock in async environments | ||
async def async_magic(): | ||
pass | ||
|
||
|
||
MagicMock.__await__ = lambda x: async_magic().__await__() | ||
|
||
|
||
class MockEFDClient(object): | ||
async def select_time_series(cls, topic_name, fields, start, end, is_window=False, index=None): | ||
async def select_time_series( | ||
cls, topic_name, fields, start, end, is_window=False, index=None | ||
): | ||
f = asyncio.Future() | ||
data = {} | ||
for field in fields: | ||
data[field] = { | ||
pd.Timestamp("2020-03-06 21:49:41"):0.21, | ||
pd.Timestamp("2020-03-06 21:50:41"):0.21, | ||
pd.Timestamp("2020-03-06 21:51:41"):0.21, | ||
pd.Timestamp("2020-03-06 21:52:41"):0.21, | ||
pd.Timestamp("2020-03-06 21:53:41"):0.21 | ||
pd.Timestamp("2020-03-06 21:49:41"): 0.21, | ||
pd.Timestamp("2020-03-06 21:50:41"): 0.21, | ||
pd.Timestamp("2020-03-06 21:51:41"): 0.21, | ||
pd.Timestamp("2020-03-06 21:52:41"): 0.21, | ||
pd.Timestamp("2020-03-06 21:53:41"): 0.21, | ||
} | ||
|
||
df = pd.DataFrame.from_dict(data) | ||
f.set_result(df) | ||
return df | ||
|
||
# Start patching `efd_client`. | ||
mock_efd_patcher = patch("lsst_efd_client.EfdClient") | ||
mock_efd_client = mock_efd_patcher.start() | ||
mock_efd_client.return_value = MockEFDClient() | ||
|
||
# For EFD client's timeouts | ||
def raise_exception(name): | ||
print(name) | ||
raise ConnectionError | ||
|
||
|
||
async def test_efd_timeseries(client): | ||
""" Test the get timeseries response.""" | ||
# Start patching `efd_client`. | ||
mock_efd_patcher = patch("lsst_efd_client.EfdClient") | ||
mock_efd_client = mock_efd_patcher.start() | ||
mock_efd_client.return_value = MockEFDClient() | ||
loop = asyncio.get_event_loop() | ||
app = await create_app() | ||
async with TestClient(TestServer(app), loop=loop) as client: | ||
|
||
|
||
cscs = { | ||
"ATDome": { | ||
0: { | ||
"topic1": ["field1"] | ||
}, | ||
}, | ||
"ATMCS": { | ||
1: { | ||
"topic2": ["field2", "field3"] | ||
}, | ||
cscs = { | ||
"ATDome": {0: {"topic1": ["field1"]},}, | ||
"ATMCS": {1: {"topic2": ["field2", "field3"]},}, | ||
} | ||
} | ||
request_data = { | ||
"start_date": "2020-03-16T12:00:00", | ||
"time_window": 15, | ||
"cscs": cscs, | ||
"resample": "1min", | ||
} | ||
response = await client.post("/efd/timeseries", json=request_data) | ||
assert response.status == 200 | ||
|
||
response_data = await response.json() | ||
assert "ATDome-0-topic1" in list(response_data.keys()) | ||
assert "ATMCS-1-topic2" in list(response_data.keys()) | ||
assert len(response_data["ATDome-0-topic1"]) == 1 | ||
assert len(response_data["ATMCS-1-topic2"]) == 2 | ||
# Endpoint truncates seconds due to resample | ||
assert response_data["ATDome-0-topic1"]["field1"][0]["ts"] == "2020-03-06 21:49:00" | ||
assert response_data["ATDome-0-topic1"]["field1"][0]["value"] == 0.21 | ||
|
||
# Stop patching `efd_client`. | ||
mock_efd_patcher.stop() | ||
request_data = { | ||
"start_date": "2020-03-16T12:00:00", | ||
"time_window": 15, | ||
"cscs": cscs, | ||
"resample": "1min", | ||
} | ||
response = await client.post("/efd/timeseries", json=request_data) | ||
assert response.status == 200 | ||
|
||
response_data = await response.json() | ||
assert "ATDome-0-topic1" in list(response_data.keys()) | ||
assert "ATMCS-1-topic2" in list(response_data.keys()) | ||
assert len(response_data["ATDome-0-topic1"]) == 1 | ||
assert len(response_data["ATMCS-1-topic2"]) == 2 | ||
# Endpoint truncates seconds due to resample | ||
assert ( | ||
response_data["ATDome-0-topic1"]["field1"][0]["ts"] == "2020-03-06 21:49:00" | ||
) | ||
assert response_data["ATDome-0-topic1"]["field1"][0]["value"] == 0.21 | ||
|
||
# Stop patching `efd_client`. | ||
mock_efd_patcher.stop() | ||
|
||
|
||
async def test_efd_timeseries_with_errors(): | ||
""" Test the get timeseries response with errors.""" | ||
# Start patching `efd_client`. | ||
mock_efd_patcher = patch("lsst_efd_client.EfdClient") | ||
mock_efd_client = mock_efd_patcher.start() | ||
mock_efd_client.return_value = MockEFDClient() | ||
mock_efd_client.side_effect = raise_exception | ||
loop = asyncio.get_event_loop() | ||
app = await create_app() | ||
async with TestClient(TestServer(app), loop=loop) as client: | ||
cscs = { | ||
"ATDome": {0: {"topic1": ["field1"]},}, | ||
"ATMCS": {1: {"topic2": ["field2", "field3"]},}, | ||
} | ||
request_data = { | ||
"start_date": "2020-03-16T12:00:00", | ||
"time_window": 15, | ||
"cscs": cscs, | ||
"resample": "1min", | ||
} | ||
response = await client.post("/efd/timeseries", json=request_data) | ||
assert response.status == 400 | ||
|
||
# Stop patching `efd_client`. | ||
mock_efd_patcher.stop() |