Example #1
0
 def test_id_already_exists(self) -> None:
     """Test exception on object `id` already exists."""
     with pytest.raises(IntegrityError):
         Object.add({
             'id': 1,
             'type_id': 5,
             'aliases': {
                 'bayer': 'α Ori',
                 'flamsteed': '58 Ori',
                 'HR': 'HR 2061',
                 'BD': 'BD + 7°1055',
                 'HD': 'HD 39801',
                 'FK5': 'FK5 224',
                 'HIP': 'HIP 27989',
                 'SAO': 'SAO 113271',
                 'GC': 'GC 7451',
                 'CCDM': 'CCDM J05552+0724',
                 'AAVSO': 'AAVSO 0549+07'
             },
             'ra': 88.7917,
             'dec': 7.4069,
             'redshift': 0.000073,
             'data': {
                 'parallax': 6.55,
             }
         })
Example #2
0
 def test_embedded(self) -> None:
     """Test embedded method to check JSON-serialization and full join."""
     assert Recommendation.from_id(1).to_json(join=True) == {
         'id':
         1,
         'group_id':
         1,
         'tag_id':
         1,
         'time':
         '2020-10-24 20:02:00' +
         ('' if config.backend == 'sqlite' else '-04:00'),
         'priority':
         1,
         'object_id':
         1,
         'facility_id':
         1,
         'user_id':
         2,
         'forecast_id':
         1,
         'predicted_observation_id':
         11,
         'observation_id':
         19,
         'accepted':
         True,
         'rejected':
         False,
         'data': {},
         'group':
         RecommendationGroup.from_id(1).to_json(join=True),
         'tag':
         RecommendationTag.from_id(1).to_json(join=True),
         'user':
         User.from_id(2).to_json(join=True),
         'facility':
         Facility.from_id(1).to_json(join=True),
         'object':
         Object.from_id(1).to_json(join=True),
         'forecast':
         Forecast.from_id(1).to_json(join=True),
         'predicted':
         Observation.from_id(11).to_json(join=True),
         'observed':
         Observation.from_id(19).to_json(join=True),
     }
Example #3
0
 def test_embedded(self) -> None:
     """Test embedded method to check JSON-serialization and auto-join."""
     assert Object.from_id(1).to_json(join=True) == {
         'id': 1,
         'type_id': 1,
         'aliases': {
             'antares': 'ANT2020ae7t5xa',
             'ztf': 'ZTF20actrfli',
             'tag': 'determined_thirsty_cray'
         },
         'ra': 133.0164572,
         'dec': 44.80034109999999,
         'redshift': None,
         'data': {},
         'type': {
             'id': 1,
             'name': 'Unknown',
             'description': 'Objects with unknown or unspecified type'
         }
     }
Example #4
0
 def test_id_missing(self) -> None:
     """Test exception on missing object `id`."""
     with pytest.raises(NotFound):
         Object.from_id(-1)
Example #5
0
 def test_from_id(self, testdata: TestData) -> None:
     """Test loading object from `id`."""
     # NOTE: `id` not set until after insert
     for i, record in enumerate(testdata['object']):
         assert Object.from_id(i + 1).aliases == record['aliases']
Example #6
0
 def test_embedded_no_join(self, testdata: TestData) -> None:
     """Tests embedded method to check JSON-serialization."""
     for data in testdata['object']:
         assert data == json_roundtrip(Object(**data).to_json(join=False))
Example #7
0
 def test_tuple(self, testdata: TestData) -> None:
     """Test tuple-conversion."""
     for data in testdata['object']:
         object = Object.from_dict(data)
         assert tuple(data.values()) == object.to_tuple()
Example #8
0
 def test_dict(self, testdata: TestData) -> None:
     """Test round-trip of dict translations."""
     for data in testdata['object']:
         object = Object.from_dict(data)
         assert data == object.to_dict()
Example #9
0
 def test_init(self, testdata: TestData) -> None:
     """Create object instance and validate accessors."""
     for data in testdata['object']:
         object = Object(**data)
         for key, value in data.items():
             assert getattr(object, key) == value
Example #10
0
 def test_relationship_object_type(self, testdata: TestData) -> None:
     """Test object foreign key relationship on object_type."""
     for i, record in enumerate(testdata['object']):
         assert Object.from_id(i + 1).type.id == record['type_id']
Example #11
0
 def test_alias_exists(self) -> None:
     with pytest.raises(AlreadyExists):
         Object.add_alias(2, ztf=Object.from_id(1).aliases['ztf'])
Example #12
0
 def test_alias_missing(self) -> None:
     """Test exception on object `alias` not found."""
     with pytest.raises(NotFound):
         Object.from_alias(foo='bar')
Example #13
0
 def test_from_alias(self, testdata: TestData) -> None:
     """Test loading object from known `alias`."""
     for record in testdata['object']:
         assert Object.from_alias(
             ztf=record['aliases']['ztf']).aliases == record['aliases']