Skip to content

Commit

Permalink
First pass creating all page tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ugyballoons committed Jul 10, 2024
1 parent 911c773 commit 21d1335
Showing 1 changed file with 59 additions and 5 deletions.
64 changes: 59 additions & 5 deletions tests/handlers/external_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,17 @@
from fastapi import FastAPI
from httpx import AsyncClient
from lsst.ts.rubintv.background.currentpoller import CurrentPoller
from lsst.ts.rubintv.models.models import Location
from lsst.ts.rubintv.background.historicaldata import HistoricalPoller
from lsst.ts.rubintv.config import config
from lsst.ts.rubintv.models.models import Camera, Location, get_current_day_obs
from lsst.ts.rubintv.models.models_helpers import find_first
from lsst.ts.rubintv.models.models_init import ModelsInitiator

from ..mockdata import RubinDataMocker

m = ModelsInitiator()
app_name = config.name
day_obs = get_current_day_obs().isoformat()


@pytest.mark.asyncio
Expand All @@ -25,7 +29,7 @@ async def test_get_home(
) -> None:
"""Test that home page has links to every location"""
client, app, mocker = mocked_client
response = await client.get("/rubintv/")
response = await client.get(f"/{app_name}/")
html = await response.aread()
parsed = BeautifulSoup(html, "html.parser")
locations = m.locations
Expand All @@ -51,7 +55,7 @@ async def test_get_location(

groups = location.camera_groups.values()
camera_names = list(chain(*groups))
response = await client.get(f"/rubintv/{location_name}")
response = await client.get(f"/{app_name}/{location_name}")
html = await response.aread()

parsed = BeautifulSoup(html, "html.parser")
Expand All @@ -78,11 +82,12 @@ async def test_current_channels(
loc_cam = f"{location.name}/{camera.name}"
for seq_chan in camera.seq_channels():
url = (
f"/rubintv/{location.name}/{camera.name}"
f"/{app_name}/{location.name}/{camera.name}"
f"/current/{seq_chan.name}"
)
response = await client.get(url)
assert response.status_code == 200
assert response.is_success

html = await response.aread()
parsed = BeautifulSoup(html, "html.parser")
if mocker.empty_channel[loc_cam] == seq_chan.name:
Expand All @@ -91,3 +96,52 @@ async def test_current_channels(
else:
assert parsed.select(".event-info")
assert not parsed.select(".event-error")


@pytest.mark.asyncio
async def test_all_endpoints(
mocked_client: tuple[AsyncClient, FastAPI, RubinDataMocker]
) -> None:

client, app, mocker = mocked_client

locations = [loc.name for loc in m.locations]
summit: Location = find_first(m.locations, "name", "summit-usdf")
assert isinstance(summit, Location)

cameras = [f"{summit.name}/{cam.name}" for cam in summit.cameras if cam.online]
camera_historical = [f"{cam}/historical" for cam in cameras]
camera_dates = [f"{cam}/date/{day_obs}" for cam in cameras if cam]
night_reports = [f"{cam}/night_report" for cam in cameras]
night_reports = [f"{cam}/night_report/{day_obs}" for cam in cameras]

auxtel: Camera = find_first(summit.cameras, "name", "auxtel")
assert isinstance(auxtel, Camera)

channels = [
f"{summit.name}/{auxtel.name}/current/{chan.name}"
for chan in auxtel.seq_channels()
]

page_rel_urls = [
"admin",
*locations,
*cameras,
*camera_dates,
*camera_historical,
*night_reports,
*channels,
]

for url_frag in page_rel_urls:
url = f"/{app_name}/{url_frag}"
print(f"Looking for: {url}")
res = await client.get(url)
assert res.is_success

hp: HistoricalPoller = app.state.historical
while hp._have_downloaded is False:
await asyncio.sleep(0.1)

# make sure we've reached here!
assert True

0 comments on commit 21d1335

Please sign in to comment.