-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into fix-irs-urls
- Loading branch information
Showing
3 changed files
with
126 additions
and
74 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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# This workflow will install Python dependencies, run tests and lint with a single version of Python | ||
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions | ||
|
||
name: Scheduled Checks | ||
|
||
on: | ||
schedule: | ||
- cron: '30 1 1 * *' | ||
workflow_dispatch: # manual execution | ||
|
||
jobs: | ||
build: | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Set up Python 3.10 | ||
uses: actions/setup-python@v3 | ||
with: | ||
python-version: '3.10' | ||
|
||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install pytest ads | ||
pip install astrodbkit2 | ||
- name: Test with pytest | ||
run: | | ||
pytest -s tests/scheduled_checks.py |
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,66 @@ | ||
import os | ||
import pytest | ||
import sys | ||
import requests | ||
from tqdm import tqdm | ||
from astrodbkit2.astrodb import create_database, Database | ||
from scripts.ingests.utils import check_internet_connection | ||
|
||
sys.path.append(".") | ||
from simple.schema import * | ||
from . import REFERENCE_TABLES | ||
|
||
|
||
DB_NAME = "temp.db" | ||
DB_PATH = "data" | ||
|
||
|
||
# Load the database for use in individual tests | ||
@pytest.fixture(scope="module") | ||
def db(): | ||
# Create a fresh temporary database and assert it exists | ||
# Because we've imported simple.schema, we will be using that schema for the database | ||
|
||
if os.path.exists(DB_NAME): | ||
os.remove(DB_NAME) | ||
connection_string = "sqlite:///" + DB_NAME | ||
create_database(connection_string) | ||
assert os.path.exists(DB_NAME) | ||
|
||
# Connect to the new database and confirm it has the Sources table | ||
db = Database(connection_string, reference_tables=REFERENCE_TABLES) | ||
assert db | ||
assert "source" in [c.name for c in db.Sources.columns] | ||
|
||
# Load data into an in-memory sqlite database first, for performance | ||
|
||
# create and connects to a temporary in-memory database | ||
temp_db = Database("sqlite://", reference_tables=REFERENCE_TABLES) | ||
|
||
# load the data from the data files into the database | ||
temp_db.load_database(DB_PATH, verbose=False) | ||
|
||
# dump in-memory database to file | ||
temp_db.dump_sqlite(DB_NAME) | ||
# replace database object with new file version | ||
db = Database("sqlite:///" + DB_NAME, reference_tables=REFERENCE_TABLES) | ||
|
||
return db | ||
|
||
|
||
def test_spectra_urls(db): | ||
spectra_urls = db.query(db.Spectra.c.spectrum).astropy() | ||
broken_urls = [] | ||
codes = [] | ||
internet = check_internet_connection() | ||
if internet: | ||
for spectrum_url in tqdm(spectra_urls["spectrum"]): | ||
request_response = requests.head(spectrum_url) | ||
status_code = request_response.status_code | ||
# The website is up if the status code is 200 | ||
# cuny academic commons links give 301 status code | ||
if status_code != 200 and status_code != 301: | ||
broken_urls.append(spectrum_url) | ||
codes.append(status_code) | ||
assert (149 <= len(broken_urls) <= 150 | ||
), f"found {len(broken_urls)} broken spectra urls: {broken_urls}, {codes}" |
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