Skip to content

Commit

Permalink
Merge pull request #77 from LCOGT/filter_cases
Browse files Browse the repository at this point in the history
save the configdb filter case for any filters submitted
  • Loading branch information
jnation3406 committed Sep 4, 2019
2 parents 3217c86 + 913f9c8 commit 2401f3b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
7 changes: 5 additions & 2 deletions observation_portal/requestgroups/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,11 +364,14 @@ def validate(self, data):
if plural_type not in available_optical_elements:
raise serializers.ValidationError(_("optical_element of type {} is not available on {} instruments"
.format(oe_type, data['instrument_type'])))
available_elements = [element['code'].lower() for element in available_optical_elements[plural_type]]
if plural_type in available_optical_elements and value.lower() not in available_elements:
available_elements = {element['code'].lower(): element['code'] for element in available_optical_elements[plural_type]}
if plural_type in available_optical_elements and value.lower() not in available_elements.keys():
raise serializers.ValidationError(_("optical element {} of type {} is not available".format(
value, oe_type
)))
else:
instrument_config['optical_elements'][oe_type] = available_elements[value.lower()]


# Also check that any optical element group in configdb is specified in the request unless we are a BIAS or
# DARK or SCRIPT type observation
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 @@ -1377,6 +1377,13 @@ def test_invalid_filter_for_instrument(self):
self.assertIn('optical element magic of type filter is not available', str(response.content))
self.assertEqual(response.status_code, 400)

def test_filter_case_is_overridden(self):
bad_data = self.generic_payload.copy()
bad_data['requests'][0]['configurations'][0]['instrument_configs'][0]['optical_elements']['filter'] = 'AiR'
response = self.client.post(reverse('api:request_groups-list'), data=bad_data)
self.assertEqual(response.json()['requests'][0]['configurations'][0]['instrument_configs'][0]['optical_elements']['filter'], 'air')
self.assertEqual(response.status_code, 201)

def test_filter_not_necessary_for_type(self):
good_data = self.generic_payload.copy()

Expand Down

0 comments on commit 2401f3b

Please sign in to comment.