-
Notifications
You must be signed in to change notification settings - Fork 100
remove attribute validation boilerplate, add tests, improve tests #863
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
remove attribute validation boilerplate, add tests, improve tests #863
Conversation
9233618 to
794920b
Compare
| AllocationAttributeFactory( | ||
| allocation=cls.allocation, | ||
| value=100, | ||
| allocation_attribute_type=AllocationAttributeTypeFactory(name="Storage Quota (TB)"), | ||
| ) | ||
| attr_type = AAttributeTypeFactory(name="Int") | ||
| alloc_attr_type = AllocationAttributeTypeFactory(name="Storage Quota (TB)", attribute_type=attr_type) | ||
| AllocationAttributeFactory(allocation=cls.allocation, value=100, allocation_attribute_type=alloc_attr_type) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was fragile. It depended on the fact that AAttributeTypeFactory has name="Int" by default.
4b38576 to
cd29a3c
Compare
| cls.nonproject_user = UserFactory(is_staff=False, is_superuser=False) | ||
|
|
||
| attributetype = PAttributeTypeFactory(name="string") | ||
| attributetype = PAttributeTypeFactory(name="Text") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
string is not a valid attribute type.
| def _raise_if_empty(self): | ||
| if self.value == "": | ||
| raise ValidationError(f'Invalid Value "{self.value}". Value cannot be empty.') | ||
|
|
||
| def validate_int(self): | ||
| self._raise_if_empty() | ||
| try: | ||
| validate = validators.Int() | ||
| validate.to_python(self.value) | ||
| except Exception: | ||
| raise ValidationError(f"Invalid Value {self.value}. Value must be an int.") | ||
|
|
||
| def validate_float(self): | ||
| self._raise_if_empty() | ||
| try: | ||
| validate = validators.Number() | ||
| validate.to_python(self.value) | ||
| except Exception: | ||
| raise ValidationError(f"Invalid Value {self.value}. Value must be an float.") | ||
|
|
||
| def validate_yes_no(self): | ||
| self._raise_if_empty() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
without _raise_if_empty(), validate_int(""), validate_float(""), and validate_yes_no("") all succeed.
cd29a3c to
b4a7152
Compare
b4a7152 to
fd428c8
Compare
copied from
Project:coldfront/coldfront/core/project/models.py
Lines 479 to 488 in 46d0eba
I would have removed attribute validation boilerplate from
Resource, too, but it's incompatible. See #865 and #864.