def test_patch_no_such_object(self):
     option_spec = CriterionOptionSpecFactory()
     option_spec_id = option_spec.id
     option_spec.delete()
     data = {'option': 'Patched Option', 'weight': 1.5, 'count': 1}
     with self.login(email=self.basic_user().email):
         url = reverse(self.view.view_name, args=[option_spec_id])
         response = self.client.patch(url, data)
         self.assertEqual(response.status_code, 404)
 def test_patch_object_exists(self):
     option_spec = CriterionOptionSpecFactory()
     criterion = CriterionFactory()
     data = {
         'option': 'Patched Option',
         'weight': 1.5,
         'count': 1,
         'criterion_id': criterion.id
     }
     with self.login(email=self.basic_user().email):
         url = reverse(self.view.view_name, args=[option_spec.id])
         self.client.patch(url, data)
         option_spec.refresh_from_db()
         assert_data_is_consistent_with_instance(data, option_spec)
 def test_get(self):
     CriterionOptionSpec.objects.all().delete()
     option_specs = CriterionOptionSpecFactory.create_batch(5)
     with self.login(email=self.basic_user().email):
         url = reverse(self.view.view_name)
         response = self.client.get(url)
         data = json.loads(response.content)
         results = {result['id']: result for result in data['results']}
         for spec in option_specs:
             assert results[spec.id]['option'] == spec.option
 def test_filter_by_judging_round_id(self):
     option_spec = CriterionOptionSpecFactory()
     judging_round_id = option_spec.criterion.judging_round_id
     with self.login(email=self.basic_user().email):
         url = reverse(self.view.view_name)
         url += "?judging_round_id={}".format(judging_round_id)
         response = self.client.get(url)
         results = json.loads(response.content)['results']
         self.assertEqual(len(results), 1)
         for key, val in results[0].items():
             self.assertEqual(val, getattr(option_spec, key))
 def test_patch_bad_key_in_data(self):
     option_spec = CriterionOptionSpecFactory()
     data = {
         'option': 'Patched Option',
         'weight': 1.5,
         'count': 1,
         'bad_key': 'B flat minor'
     }
     with self.login(email=self.basic_user().email):
         url = reverse(self.view.view_name, args=[option_spec.id])
         response = self.client.patch(url, data)
         note = valid_keys_note(self.view.helper_class.INPUT_KEYS)
         assert note in str(response.content)
 def test_patch_options(self):
     option_spec = CriterionOptionSpecFactory()
     patch_options = {
         "id": {
             "type": "integer",
             "readOnly": True,
             "required": True
         },
         "option": {
             "type": "string"
         },
         "weight": {
             "type": "number"
         },
         "count": {
             "type": "integer"
         },
         "criterion_id": {
             "type": "integer"
         }
     }
     self.assert_options_include("PATCH",
                                 patch_options,
                                 object_id=option_spec.id)
 def test_get(self):
     option_spec = CriterionOptionSpecFactory()
     with self.login(email=self.basic_user().email):
         url = reverse(self.view.view_name, args=[option_spec.id])
         response = self.client.get(url)
         assert_data_is_consistent_with_instance(response.data, option_spec)