Skip to content

Commit

Permalink
Merge 8ae058d into ef13db5
Browse files Browse the repository at this point in the history
  • Loading branch information
jnation3406 committed Jun 20, 2019
2 parents ef13db5 + 8ae058d commit 9c885de
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 9 deletions.
5 changes: 4 additions & 1 deletion observation_portal/observations/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,10 @@ def validate_instrument_type(self, value):
return value

def validate(self, data):
validated_data = super().validate(data)
# Currently don't validate configuration params for direct submissions until we add unschedulable flag to
# generic modes in configdb
# validated_data = super().validate(data)
validated_data = data
if validated_data['type'] not in ['BIAS', 'DARK', 'SKY_FLAT']:
target_serializer = TargetSerializer(data=validated_data['target'])
if not target_serializer.is_valid():
Expand Down
11 changes: 11 additions & 0 deletions observation_portal/observations/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,17 @@ def test_self_guiding_with_no_guide_camera_set_sets_same_instrument_for_guide_ca
obs_json['request']['configurations'][0]['guide_camera_name']
)

def test_post_observation_hour_angle_missing_required_fields(self):
bad_observation = copy.deepcopy(self.observation)
bad_observation['request']['configurations'][0]['target']['type'] = 'HOUR_ANGLE'
bad_observation['request']['configurations'][0]['target']['ha'] = 9.45
del bad_observation['request']['configurations'][0]['target']['ra']
del bad_observation['request']['configurations'][0]['target']['dec']

response = self.client.post(reverse('api:schedule-list'), data=bad_observation)
self.assertEqual(response.status_code, 400)
self.assertIn('dec', str(response.content))


class TestPostScheduleMultiConfigApi(SetTimeMixin, APITestCase):
def setUp(self):
Expand Down
6 changes: 6 additions & 0 deletions observation_portal/requestgroups/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,12 @@ def validate(self, data):
if data['observation_type'] == RequestGroup.DIRECT:
# Don't do any time accounting stuff if it is a directly scheduled observation
return data
else:
# for non-DIRECT observations, don't allow HOUR_ANGLE targets
for request in data['requests']:
for config in request['configurations']:
if config['target']['type'] == 'HOUR_ANGLE':
raise serializers.ValidationError(_('HOUR_ANGLE Target type not supported in scheduled observations'))

try:
total_duration_dict = get_total_duration_dict(data)
Expand Down
10 changes: 2 additions & 8 deletions observation_portal/requestgroups/test/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1114,17 +1114,11 @@ def setUp(self):
'epoch': 2000
}

def test_post_requestgroup_hour_angle_target(self):
good_data = self.generic_payload.copy()
response = self.client.post(reverse('api:request_groups-list'), data=good_data)
self.assertEqual(response.status_code, 201)

def test_post_requestgroup_hour_angle_missing_required_fields(self):
def test_post_requestgroup_hour_angle_target_fails(self):
bad_data = self.generic_payload.copy()
del bad_data['requests'][0]['configurations'][0]['target']['dec']
response = self.client.post(reverse('api:request_groups-list'), data=bad_data)
self.assertEqual(response.status_code, 400)
self.assertIn('dec', str(response.content))
self.assertIn('HOUR_ANGLE Target type not supported', str(response.content))


class TestLocationApi(SetTimeMixin, APITestCase):
Expand Down

0 comments on commit 9c885de

Please sign in to comment.