def create_object(self, post_data): object_data = self.data_from_post(post_data) self.invalid_keys(post_data.keys()) if self.errors: note = valid_keys_note(self.helper_class.ALL_KEYS) self.errors.append(note) return None return self.helper_class.construct_object(object_data)
def _error_response(helper): subject = helper.profile_helper.subject if subject: _valid_keys = valid_keys(subject.user_type) note = valid_keys_note(_valid_keys) else: note = MISSING_PROFILE_ERROR.format(helper.subject.id) return Response(status=403, data=helper.errors + [note])
def create_object(self, posted_data): user_args = self._user_args(posted_data) profile_args = self._profile_args(posted_data) self.invalid_keys(posted_data) if self.errors: _valid_keys = valid_keys( profile_args.get("user_type"), post=True) self.errors.append(valid_keys_note(_valid_keys)) return None return _construct_user(user_args, profile_args)
def test_post_bad_key_in_data(self): data = { 'option': 'Posted 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) response = self.client.post(url, data) note = valid_keys_note(self.view.helper_class.INPUT_KEYS) assert note in str(response.content)
def test_post_bad_key_in_data(self): data = { 'name': 'Posted Criterion', 'type': 'sans serif', 'judging_round_id': 1, 'bad_key': 'B flat minor' } with self.login(email=self.basic_user().email): url = reverse(self.view.view_name) response = self.client.post(url, data) note = valid_keys_note(self.view.helper_class.INPUT_KEYS) assert note in str(response.content)
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 error_response(self, keys): note = valid_keys_note(self.helper_class.INPUT_KEYS) return Response(status=403, data=self.errors + [note])