diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml new file mode 100644 index 00000000..46da69ac --- /dev/null +++ b/.github/workflows/run-tests.yml @@ -0,0 +1,77 @@ +name: Unit tests + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +jobs: + test: + runs-on: ubuntu-latest + defaults: + run: + working-directory: ./tests + + steps: + - uses: actions/checkout@v4 + with: + submodules: 'recursive' + + - name: Unpack test files + run: | + tar xf elasticc2_alert_test_data.tar.bz2 + + - name: Build docker images + run: | + docker compose build + + - name: Bring docker environments up + run: | + docker compose up -d shell + + - name: Run Cycle Tests + run: | + docker compose exec -it shell /bin/bash -c "python3 -m pytest /tests/test_elasticc2_spectrumcycle.py" + + - name: Post to a Slack channel + #if: ${{ failure() && github.event_name != 'workflow_dispatch' }} + id: slack + uses: slackapi/slack-github-action@v2 + with: + # #lf-resspect-ci channel in LSSTC slack workspace + method: chat.postMessage + token: ${{ secrets.SLACK_BOT_TOKEN }} + payload: | + { + "channel": "C080P31B1L4", + "text": "GitHub Action build result: *${{ job.status }}* :${{ job.status }}:", + "blocks": [ + { + "type": "header", + "text": { + "type": "plain_text", + "text": "${{ github.repository }}" + } + }, + { + "type": "section", + "text": { + "type": "mrkdwn", + "text": "GitHub Action build result: *${{ job.status }}* :${{ job.status }}:" + } + }, + { + "type": "divider" + }, + { + "type": "section", + "text": { + "type": "mrkdwn", + "text": "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" + } + } + ] + } + env: + SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }} diff --git a/.gitignore b/.gitignore index b9cf019c..ddbadfd7 100644 --- a/.gitignore +++ b/.gitignore @@ -157,3 +157,8 @@ tom_desc/admin_tools/elasticc2_dump_10obj.sql tom_desc/admin_tools/elasticc2_dump_100obj.sql tom_desc/admin_tools/elasticc2_dump_1000obj.sql tom_desc/elasticc_subset.sql + +# Locations of runtime files for a docker compose dev setup +tom_desc/elasticc2/static/ +tom_desc/load_snana_fits_reconstruct_indexes_constraints.sql + diff --git a/tests/alertcyclefixtures.py b/tests/alertcyclefixtures.py index 8135a3a4..f4f72bc1 100644 --- a/tests/alertcyclefixtures.py +++ b/tests/alertcyclefixtures.py @@ -507,5 +507,6 @@ def alert_cycle_complete( request, tomclient ): 'classifications_100daysmore_elasticc2_ingested', 'classifications_100daysmore_fastdb_dev_ingested', 'update_fastdb_dev_diasource_100daysmore', + 'update_elasticc2_diasource_100daysmore', 'api_classify_existing_alerts', 'alert_cycle_complete' ] diff --git a/tests/test_elasticc2_spectrumcycle.py b/tests/test_elasticc2_spectrumcycle.py index b0a87236..f9d46409 100644 --- a/tests/test_elasticc2_spectrumcycle.py +++ b/tests/test_elasticc2_spectrumcycle.py @@ -28,7 +28,7 @@ class TestSpectrumCycle: @pytest.fixture( scope='class' ) - def ask_for_spectra( self, update_diasource_100daysmore, tomclient ): + def ask_for_spectra( self, update_elasticc2_diasource_100daysmore, tomclient ): objs = elasticc2.models.DiaObject.objects.all().order_by("diaobject_id") objs = list( objs ) @@ -51,7 +51,7 @@ def ask_for_spectra( self, update_diasource_100daysmore, tomclient ): # TODO : test things other than detected_since_mjd sent to gethottransients - def test_hot_sne( self, update_diasource_100daysmore, tomclient ): + def test_hot_sne( self, update_elasticc2_diasource_100daysmore, tomclient ): # Testing detected_in_last_days is fraught because # the mjds in elasticc2 are what they are, are # in the future (as of this comment writing). @@ -59,10 +59,10 @@ def test_hot_sne( self, update_diasource_100daysmore, tomclient ): res = tomclient.post( 'elasticc2/gethottransients', json={ 'detected_since_mjd': 60660 } ) sne = res.json()['diaobject'] - assert len(sne) == 5 + assert len(sne) == 8 snids = { s['objectid'] for s in sne } - assert snids == { 15232, 416626, 1263066, 1286131, 1913410 } + assert snids == {15232, 1913410, 2110476, 416626, 1286131, 1684659, 1045654, 1263066} # Should probably check more than this... assert set( sne[0].keys() ) == { 'objectid', 'ra', 'dec', 'photometry', 'zp', 'redshift', 'sncode' } diff --git a/tom_desc/fastdb_dev/DataTools.py b/tom_desc/fastdb_dev/DataTools.py index 3db5ec3a..1b1bc91a 100644 --- a/tom_desc/fastdb_dev/DataTools.py +++ b/tom_desc/fastdb_dev/DataTools.py @@ -48,7 +48,9 @@ from rest_framework.settings import api_settings _logger = logging.getLogger("fastdb_queries") -_logout = logging.FileHandler( pathlib.Path( os.getenv('LOGDIR'), "/logs" ) / "fastdb_queries.log" ) +_log_path = pathlib.Path( os.environ.get('LOGDIR',""), "/logs" ) +_log_path.mkdir(parents=True, exist_ok=True) +_logout = logging.FileHandler( _log_path / "fastdb_queries.log" ) _logger.addHandler( _logout ) _formatter = logging.Formatter( f'[%(asctime)s - %(levelname)s] - %(message)s', datefmt='%Y-%m-%d %H:%M:%S' )