Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 4 additions & 1 deletion .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@ omit =
*/env/*
*/migrations/*
*wsgi.py
*apps.py
*apps.py
*/tests/*
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing tests from the calculation results in a 5% drop in test coverage. :D

exclude_lines =
except AttributeError:
49 changes: 47 additions & 2 deletions tom_dataproducts/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from astropy import units
from astropy.io import fits
from astropy.table import Table
from datetime import date, time
from datetime import date, time, timezone
from django.test import TestCase, override_settings
from django.conf import settings
from django.contrib.auth.models import Group, User
Expand All @@ -18,10 +18,11 @@

from tom_dataproducts.exceptions import InvalidFileFormatException
from tom_dataproducts.forms import DataProductUploadForm
from tom_dataproducts.models import DataProduct, is_fits_image_file
from tom_dataproducts.models import DataProduct, is_fits_image_file, ReducedDatum
from tom_dataproducts.processors.data_serializers import SpectrumSerializer
from tom_dataproducts.processors.photometry_processor import PhotometryProcessor
from tom_dataproducts.processors.spectroscopy_processor import SpectroscopyProcessor
from tom_dataproducts.alertstreams.hermes import BuildHermesMessage, publish_photometry_to_hermes
from tom_dataproducts.utils import create_image_dataproduct
from tom_observations.tests.utils import FakeRoboticFacility
from tom_observations.tests.factories import SiderealTargetFactory, ObservingRecordFactory
Expand All @@ -39,6 +40,10 @@ def mock_is_fits_image_file(filename):
return True


def mock_hermes_post(url, json, headers):
return json


@override_settings(TOM_FACILITY_CLASSES=['tom_observations.tests.utils.FakeRoboticFacility'],
TARGET_PERMISSIONS_ONLY=True)
@patch('tom_dataproducts.models.DataProduct.get_preview', return_value='/no-image.jpg')
Expand Down Expand Up @@ -489,3 +494,43 @@ def test_create_thumbnail(self, mock_is_fits_image_file):
'ignore_missing_simple=True')

self.assertIn(expected, logs.output)


class TestDataSharing(TestCase):
def setUp(self):
self.target = SiderealTargetFactory.create()
self.message_info = BuildHermesMessage()
datum = {'target': self.target,
'data_type': 'photometry',
'value': {'magnitude': 12,
'magnitude_error': .1,
'filter': 'v',
'telescope': 'ogg',
'instrument': 'kb27',
'unit': "Mag",
}
}
self.rd = ReducedDatum.objects.create(**datum)

@patch('tom_dataproducts.alertstreams.hermes.requests.post', mock_hermes_post)
def test_publish_photometry_to_hermes(self):
"""Test a basic Hermes message format."""
expected_message = {'topic': 'hermes.test',
'title': '',
'submitter': '',
'authors': '',
'data': {'photometry': [{'target_name': self.target.name,
'ra': self.target.ra,
'dec': self.target.dec,
'date': self.rd.timestamp.replace(tzinfo=timezone.utc).isoformat(),
'telescope': 'ogg',
'instrument': 'kb27',
'band': 'v',
'brightness_unit': 'Mag',
'brightness': 12,
'brightness_error': 0.1}],
'extra_info': {}},
'message_text': ''}
datums = ReducedDatum.objects.all()
response = publish_photometry_to_hermes(self.message_info, datums)
self.assertEqual(response, expected_message)