Exemplo n.º 1
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),
     }
Exemplo n.º 2
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'
         }
     }
Exemplo n.º 3
0
 def test_id_missing(self) -> None:
     """Test exception on missing object `id`."""
     with pytest.raises(NotFound):
         Object.from_id(-1)
Exemplo n.º 4
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']
Exemplo n.º 5
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']
Exemplo n.º 6
0
 def test_alias_exists(self) -> None:
     with pytest.raises(AlreadyExists):
         Object.add_alias(2, ztf=Object.from_id(1).aliases['ztf'])