Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DM-40351: Make vcr-based testing site agnostic #57

Merged
merged 3 commits into from
Aug 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 14 additions & 1 deletion python/lsst/summit/utils/efdUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,9 +337,19 @@ def getMostRecentRowWithDataBefore(client, topic, timeToLookBefore, warnStaleAft
return lastRow


def makeEfdClient():
def makeEfdClient(testing=False):
"""Automatically create an EFD client based on the site.

Parameters
----------
testing : `bool`, optional
Set to ``True`` if running in a test suite. This will default to using
the USDF EFD, for which data has been recorded for replay by the ``vcr`
package. Note data must be re-recorded to ``vcr`` from both inside and
outside the USDF when the package/data changes, due to the use of a
proxy meaning that the web requests are different depending on whether
the EFD is being contacted from inside and outside the USDF.

Returns
-------
efdClient : `lsst_efd_client.efd_helper.EfdClient`
Expand All @@ -348,6 +358,9 @@ def makeEfdClient():
if not HAS_EFD_CLIENT:
raise RuntimeError("Could not create EFD client because importing lsst_efd_client failed.")

if testing:
return EfdClient('usdf_efd')

try:
site = getSite()
except ValueError as e:
Expand Down
102 changes: 102 additions & 0 deletions tests/data/cassettes/setUpClass.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2573,4 +2573,106 @@ interactions:
code: 200
message: OK
url: https://summit-lsp.lsst.codes:443/influxdb/query
- request:
body: null
headers:
Accept:
- '*/*'
Accept-Encoding:
- gzip, deflate, br
Connection:
- keep-alive
User-Agent:
- python-requests/2.31.0
method: GET
uri: https://roundtable.lsst.codes/segwarides/
response:
body:
string: '{"_metadata": {"name": "segwarides", "version": "0.4.2", "description":
"A simple app to serve credentials to other services.", "repository_url":
"https://github.com/lsst-sqre/segwarides", "documentation_url": "https://github.com/lsst-sqre/segwarides"}}'
headers:
Connection:
- keep-alive
Content-Length:
- '253'
Content-Type:
- application/json; charset=utf-8
Date:
- Wed, 09 Aug 2023 16:32:51 GMT
Strict-Transport-Security:
- max-age=15724800; includeSubDomains
status:
code: 200
message: OK
- request:
body: null
headers:
Accept:
- '*/*'
Accept-Encoding:
- gzip, deflate, br
Connection:
- keep-alive
User-Agent:
- python-requests/2.31.0
method: GET
uri: https://roundtable.lsst.codes/segwarides/creds/usdf_efd
response:
body:
string: '{"host": "usdf-rsp.slac.stanford.edu", "username": "efdreader", "password":
"cD32sDoymy69EWAmD5nsSA==", "schema_registry": "http://sasquatch-schema-registry.sasquatch:8081",
"port": "443", "path": "/influxdb/"}'
headers:
Connection:
- keep-alive
Content-Length:
- '210'
Content-Type:
- application/json; charset=utf-8
Date:
- Wed, 09 Aug 2023 16:32:52 GMT
Strict-Transport-Security:
- max-age=15724800; includeSubDomains
status:
code: 200
message: OK
- request:
body: null
headers:
Accept:
- '*/*'
Accept-Encoding:
- gzip, deflate, br
Connection:
- keep-alive
User-Agent:
- python-requests/2.31.0
method: GET
uri: https://usdf-rsp.slac.stanford.edu/influxdb/health
response:
body:
string: '{"checks":[],"message":"ready for queries and writes","name":"influxdb","status":"pass","version":"1.8.10"}'
headers:
Connection:
- keep-alive
Content-Length:
- '107'
Content-Type:
- application/json
Date:
- Wed, 09 Aug 2023 16:32:52 GMT
Request-Id:
- 5ae59e7ab05d7fc31978a1ab09732921
Strict-Transport-Security:
- max-age=16070400
X-Influxdb-Build:
- OSS
X-Influxdb-Version:
- 1.8.10
X-Request-Id:
- 5ae59e7ab05d7fc31978a1ab09732921
status:
code: 200
message: OK
version: 1
77 changes: 77 additions & 0 deletions tests/data/cassettes/test_clipDataToEvent.yaml

Large diffs are not rendered by default.

385 changes: 385 additions & 0 deletions tests/data/cassettes/test_getEfdData.yaml

Large diffs are not rendered by default.

154 changes: 154 additions & 0 deletions tests/data/cassettes/test_getMostRecentRowWithDataBefore.yaml

Large diffs are not rendered by default.

76 changes: 76 additions & 0 deletions tests/data/cassettes/test_getSubTopics.yaml

Large diffs are not rendered by default.

9 changes: 1 addition & 8 deletions tests/test_efdUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@

from lsst.utils import getPackageDir
from lsst.summit.utils.tmaUtils import TMAEvent, TMAState
from lsst.summit.utils.utils import getSite

from lsst.summit.utils.efdUtils import (
getEfdData,
Expand Down Expand Up @@ -69,22 +68,16 @@
path_transformer=vcr.VCR.ensure_suffix(".yaml"),
)

# all EFD and TMA tests must be skipped on the TTS because the TTS EFD
# contains different data to the real EFD instances, so all the tests will
# always (and should) fail
ON_THE_TTS = getSite() == 'tucson'


@unittest.skipIf(not HAS_EFD_CLIENT, "No EFD client available")
@unittest.skipIf(ON_THE_TTS, "Skipping EFD-based tests on the TTS")
@safe_vcr.use_cassette()
class EfdUtilsTestCase(lsst.utils.tests.TestCase):

@classmethod
@safe_vcr.use_cassette()
def setUpClass(cls):
try:
cls.client = makeEfdClient()
cls.client = makeEfdClient(testing=True)
except RuntimeError:
raise unittest.SkipTest("Could not instantiate an EFD client")
cls.dayObs = 20230531
Expand Down
10 changes: 1 addition & 9 deletions tests/test_tmaUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@

from lsst.utils import getPackageDir
from lsst.summit.utils.enums import PowerState
from lsst.summit.utils.utils import getSite
from lsst.summit.utils.efdUtils import makeEfdClient, getDayObsStartTime, calcNextDay
from lsst.summit.utils.tmaUtils import (
getSlewsFromEventList,
Expand Down Expand Up @@ -69,11 +68,6 @@
path_transformer=vcr.VCR.ensure_suffix(".yaml"),
)

# all EFD and TMA tests must be skipped on the TTS because the TTS EFD
# contains different data to the real EFD instances, so all the tests will
# always (and should) fail
ON_THE_TTS = getSite() == 'tucson'


def getTmaEventTestTruthValues():
"""Get the current truth values for the TMA event test cases.
Expand Down Expand Up @@ -156,7 +150,6 @@ def _turnOn(tma):
tma._parts['elevationSystemState'] = PowerState.ON


@unittest.skipIf(ON_THE_TTS, "Skipping EFD-based tests on the TTS")
class TmaUtilsTestCase(lsst.utils.tests.TestCase):

def test_tmaInit(self):
Expand Down Expand Up @@ -237,15 +230,14 @@ def test_initStateLogic(self):
# tma._axesInPosition()


@unittest.skipIf(ON_THE_TTS, "Skipping EFD-based tests on the TTS")
@safe_vcr.use_cassette()
class TMAEventMakerTestCase(lsst.utils.tests.TestCase):

@classmethod
@safe_vcr.use_cassette()
def setUpClass(cls):
try:
cls.client = makeEfdClient()
cls.client = makeEfdClient(testing=True)
except RuntimeError:
raise unittest.SkipTest("Could not instantiate an EFD client")

Expand Down