Skip to content

Commit

Permalink
Merge pull request #103 from LCOGT/fix/validate-at-least-instconfig
Browse files Browse the repository at this point in the history
Add validation to make sure there is at least one instrument configuration
  • Loading branch information
eheinrich committed Feb 12, 2020
2 parents 2708946 + 73e5083 commit 539df88
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions observation_portal/requestgroups/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,8 @@ def to_representation(self, instance):
def validate_instrument_configs(self, value):
if len(set([instrument_config.get('rotator_mode', '') for instrument_config in value])) > 1:
raise serializers.ValidationError(_('Rotator modes within the same configuration must be the same'))
if len(value) < 1:
raise serializers.ValidationError(_('A configuration must have at least one instrument configuration'))
return value

def validate_instrument_type(self, value):
Expand Down
7 changes: 7 additions & 0 deletions observation_portal/requestgroups/test/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1287,6 +1287,13 @@ def setUp(self):
self.generic_payload['proposal'] = self.proposal.id
self.extra_configuration = copy.deepcopy(self.generic_payload['requests'][0]['configurations'][0])

def test_must_have_at_least_one_instrument_config(self):
bad_data = self.generic_payload.copy()
bad_data['requests'][0]['configurations'][0]['instrument_configs'] = []
response = self.client.post(reverse('api:request_groups-list'), data=bad_data)
self.assertEqual(response.status_code, 400)
self.assertIn('must have at least one instrument configuration', str(response.content))

def test_default_guide_mode_for_spectrograph(self):
good_data = self.generic_payload.copy()
response = self.client.post(reverse('api:request_groups-list'), data=good_data)
Expand Down

0 comments on commit 539df88

Please sign in to comment.