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

fix tests after rebuild of DB on server using init-db.sh #40

Merged
merged 2 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
214 changes: 19 additions & 195 deletions tests/expected_pat.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,167 +34,35 @@

default_fields = ["dec", "flux", "ra", "sparcl_id", "specid", "wavelength"]

# OLD as of Dec 14, 2023
# retrieve_0 = [1254334738051655680, 1254335012929562624]

# OLD as of May 3, 2024
#retrieve_0 = [39627920993422590, 39627926995470031]

retrieve_0 = ["_dr", "flux", "sparcl_id", "specid"]

retrieve_0b = ["_dr", "dec", "flux", "ra", "sparcl_id", "specid", "wavelength"]


# OLD as of Dec 14, 2023
# retrieve_5 = [1254334738051655680, 1254335012929562624]

# OLD as of May 3, 2024
#retrieve_5 = [39627920993422590, 39627926995470031]

retrieve_5 = 2

# OLD as of Dec 14, 2023
# find_0 = [
# {
# "_dr": "BOSS-DR16",
# "dec": 28.038113,
# "ra": 132.95902999999998,
# "sparcl_id": "611a5a1c-75d8-11ee-8b9f-525400aad0aa",
# },
# {
# "_dr": "BOSS-DR16",
# "dec": 28.019856,
# "ra": 132.93685,
# "sparcl_id": "61357ba4-75d8-11ee-a1b5-525400aad0aa",
# },
# ]

# OLD as of May 3, 2024
#find_0 = [
# {
# "_dr": "BOSS-DR16",
# "dec": 3.4911852,
# "ra": 340.93613000000005,
# "sparcl_id": "0c46e982-992d-11ee-b800-525400aad0aa",
# },
# {
# "_dr": "BOSS-DR16",
# "dec": 3.0464991,
# "ra": 340.93298000000004,
# "sparcl_id": "2602c4a5-992d-11ee-b3e7-525400aad0aa",
# },
#]

find_0 = [{'_dr': 'BOSS-DR16',
'data_release': 'BOSS-DR16',
'specid': -6444642403514822656}]

# OLD as of Dec 14, 2023
# find_1 = [
# {
# "_dr": "SDSS-DR17",
# "dec": -0.98681,
# "ra": 313.90848,
# "sparcl_id": "0002f55c-75d7-11ee-822f-525400aad0aa",
# }
# ]

# OLD as of May 3, 2024
#find_1 = [
# {
# "_dr": "DESI-EDR",
# "dec": 5.662937176455572,
# "ra": 208.7076645721256,
# "sparcl_id": "00063e73-992e-11ee-ad57-525400aad0aa",
# }
#]
find_0 = [
{
"_dr": "BOSS-DR16",
"data_release": "BOSS-DR16",
"specid": -6444532452352045056,
}
]

find_1 = [{'_dr': 'SDSS-DR16',
'data_release': 'SDSS-DR16',
'specid': 1506454396622366720}]
find_1 = [
{
"_dr": "SDSS-DR16",
"data_release": "SDSS-DR16",
"specid": 1506454396622366720,
}
]

find_2 = 936894 # PAT

# OLD as of Dec 14, 2023
# find_3 = [
# {
# "_dr": "SDSS-DR17",
# "dec": -0.98681,
# "ra": 313.90848,
# "sparcl_id": "0002f55c-75d7-11ee-822f-525400aad0aa",
# },
# {
# "_dr": "SDSS-DR17",
# "dec": -0.945676,
# "ra": 313.91043,
# "sparcl_id": "000df610-75d7-11ee-9957-525400aad0aa",
# },
# {
# "_dr": "SDSS-DR17",
# "dec": -0.486388,
# "ra": 313.70407,
# "sparcl_id": "0018f253-75d7-11ee-8253-525400aad0aa",
# },
# ]

# OLD as of March 13, 2024
# find_3 = [{'_dr': 'DESI-EDR',
# 'dec': 5.662937176455572,
# 'ra': 208.7076645721256,
# 'sparcl_id': '00063e73-992e-11ee-ad57-525400aad0aa'},
# {'_dr': 'DESI-EDR',
# 'dec': 5.492057016906403,
# 'ra': 209.52823969727436,
# 'sparcl_id': '000d4892-9931-11ee-9e4d-525400aad0aa'},
# {'_dr': 'SDSS-DR17',
# 'dec': 34.863511,
# 'ra': 194.86904,
# 'sparcl_id': '000e388f-992d-11ee-a373-525400aad0aa'}]

# OLD as of May 3, 2024
#find_3 = [
# {
# "_dr": "DESI-EDR",
# "dec": 5.662937176455572,
# "ra": 208.7076645721256,
# "sparcl_id": "00063e73-992e-11ee-ad57-525400aad0aa",
# },
# {
# "_dr": "DESI-EDR",
# "dec": 5.492057016906403,
# "ra": 209.52823969727436,
# "sparcl_id": "000d4892-9931-11ee-9e4d-525400aad0aa",
# },
# {
# "_dr": "BOSS-DR16",
# "dec": 27.461703,
# "ra": 141.95067,
# "sparcl_id": "001b11a6-992f-11ee-993c-525400aad0aa",
# },
#]

find_3 = [{'_dr': 'BOSS-DR16', 'data_release': 'BOSS-DR16'},
{'_dr': 'BOSS-DR16', 'data_release': 'BOSS-DR16'},
{'_dr': 'BOSS-DR16', 'data_release': 'BOSS-DR16'}]

# OLD as of Dec 14, 2023
# find_4 = [
# "0002f55c-75d7-11ee-822f-525400aad0aa",
# "000df610-75d7-11ee-9957-525400aad0aa",
# "0018f253-75d7-11ee-8253-525400aad0aa",
# ]

# OLD as of March 13, 2024
# find_4 = ['00063e73-992e-11ee-ad57-525400aad0aa',
# '000d4892-9931-11ee-9e4d-525400aad0aa',
# '000e388f-992d-11ee-a373-525400aad0aa']

# OLD as of May 3, 2024
#find_4 = [
# "00063e73-992e-11ee-ad57-525400aad0aa",
# "000d4892-9931-11ee-9e4d-525400aad0aa",
# "001b11a6-992f-11ee-993c-525400aad0aa",
#]
find_3 = [
{"_dr": "BOSS-DR16", "data_release": "BOSS-DR16"},
{"_dr": "DESI-EDR", "data_release": "DESI-EDR"},
{"_dr": "SDSS-DR16", "data_release": "SDSS-DR16"},
]

find_4 = 36

Expand All @@ -205,50 +73,6 @@

find_5d = []

# OLD as of Dec 14, 2023
# reorder_1a = [
# "9452379f-d82d-43bb-8fc2-c26451df4710",
# "529936c6-14ef-4119-a80d-b184dcb6308e",
# "fbb22144-25c5-4330-9b0b-8b2eac83079c",
# ]

# OLD as of March 13, 2024
# reorder_1a = ['00063e73-992e-11ee-ad57-525400aad0aa',
# '000d4892-9931-11ee-9e4d-525400aad0aa',
# '000e388f-992d-11ee-a373-525400aad0aa']

# OLD as of May 3, 2024
#reorder_1a = [
# "00063e73-992e-11ee-ad57-525400aad0aa",
# "000d4892-9931-11ee-9e4d-525400aad0aa",
# "001b11a6-992f-11ee-993c-525400aad0aa",
#]

# OLD as of Dec 14, 2023
# reorder_1b = [1254334738051655680, 1254335012929562624, 1254335287807469568]

# OLD as of March 13, 2024
# reorder_1b = [39627926995470031, 39627920993422590, 2258670445286942720]

# OLD as of May 3, 2024
#reorder_1b = [39627926995470031, 39627920993422590, -5672180510041550848]

# OLD as of Dec 14, 2023
# reorder_2a = [1254334738051655680, 1254335012929562624, None]

# OLD as of May 3, 2024
#reorder_2a = [
# "00063e73-992e-11ee-ad57-525400aad0aa",
# "000d4892-9931-11ee-9e4d-525400aad0aa",
# "None",
#]

# OLD as of Dec 14, 2023
# reorder_2b = [1254334738051655680, 1254335012929562624, None]

# OLD as of May 3, 2024
#reorder_2b = [39627926995470031, 39627920993422590, None]

authorized_1 = {
"Loggedin_As": "[email protected]",
"Authorized_Datasets": {
Expand Down
66 changes: 24 additions & 42 deletions tests/tests_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@

# Local Packages
from tests.utils import tic, toc
import tests.expected_pat as exp_pat
import tests.expected_dev1 as exp_dev
import tests.expected_pat as exp
import sparcl.exceptions as ex
import sparcl.gather_2d as sg
import sparcl.client
Expand All @@ -81,31 +80,19 @@
_PROD = "https://astrosparcl.datalab.noirlab.edu" # noqa: E221

serverurl = os.environ.get("serverurl", _PROD)
#!DEV_SERVERS = [_DEV1,]
DEV_SERVERS = []

if serverurl in DEV_SERVERS:
exp = exp_dev
else:
exp = exp_pat

showact = False
showact = showact or os.environ.get("showact") == "1"

showcurl = False
showcurl = showcurl or os.environ.get("showcurl") == "1"

clverb = False
clverb = clverb or os.environ.get("clverb") == "1"

showall = False
showall = showall or os.environ.get("showall") == "1"
if showall:
showact = showcurl = clverb = True

usrpw = os.environ.get("usrpw")

show_run_context = True
usrpw = os.environ.get("usrpw") # password for test users
show_run_context = True # Print message about parameters of this test run


@contextmanager
Expand Down Expand Up @@ -150,6 +137,22 @@ def load_tests(loader, tests, ignore):
return tests


def print_run_context(cls):
print(
f"""
Running Client Tests
against Server: \t"{urlparse(serverurl).netloc}"
comparing to: \t{exp.__name__}
{showact=}
{showcurl=}
client={cls.client}

For REPRODUCIBLE RESULTS rebuild Server DB before running tests!
Use: init-db.sh
"""
)


class SparclClientTest(unittest.TestCase):
"""Test access to each endpoint of the Server API"""

Expand Down Expand Up @@ -180,14 +183,7 @@ def setUpClass(cls):
global show_run_context

if show_run_context:
print(
f"Running Client Tests\n"
f' against Server: "{urlparse(serverurl).netloc}"\n'
f" comparing to: {exp.__name__}\n"
f" showact={showact}\n"
f" showcurl={showcurl}\n"
f" client={cls.client}\n"
)
print_run_context(cls)
show_run_context = False

# Get some id_lists to use in tests
Expand Down Expand Up @@ -377,23 +373,16 @@ def test_find_0(self):
"""Get metadata using search spec."""

outfields = ["data_release", "specid"]
# from list(FitsRecord.objects.all().values('ra','dec'))

# To get suitable constraints (in sparc-shell on Server):
# sorted(FitsRecord.objects.all().values('ra','dec'),
# key=lambda r: r['dec'])
# if serverurl in DEV_SERVERS:
# !constraints = {"ra": [246.0, 247.0], "dec": [+34.7, +34.8]}
# constraints = {"ra": [194.0, 195.0], "dec": [+27.5, +27.6]}
# else:
# constraints = {"ra": [340.0, 341.0], "dec": [+3.0, +4.0]}
constraints = {"ra": [134.288, 134.291], "dec": [+28.34, +28.351]}
# list(FitsRecord.objects.all().values('ra','dec'))
constraints = {"ra": [132.1, 132.2], "dec": [+28.0, +28.1]}
found = self.client.find(outfields, constraints=constraints, limit=3)
actual = found.records[:2]
if showact:
print(f"find_0: actual={pf(actual[:2])}")
self.assertEqual(actual, exp.find_0, msg="Actual to Expected")

@skip("fiddly bit skipped until we use factoryboy")
def test_find_1(self):
"""Get metadata using search spec."""
outfields = ["data_release", "specid"]
Expand Down Expand Up @@ -756,14 +745,7 @@ def setUpClass(cls):
global show_run_context

if show_run_context:
print(
f"Running Client Tests\n"
f' against Server: "{urlparse(serverurl).netloc}"\n'
f" comparing to: {exp.__name__}\n"
f" showact={showact}\n"
f" showcurl={showcurl}\n"
f" client={cls.client}\n"
)
print_run_context(cls)
show_run_context = False

cls.outflds = ["sparcl_id", "data_release"]
Expand Down
Loading