Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions bert_e/server/api/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,20 @@
def __init_subclass__(cls, **kwargs):
"""Runs some health checks on class properties."""
super().__init_subclass__(**kwargs)
assert cls.rule
assert type(cls.rule) == str
assert cls.method in ['GET', 'DELETE', 'PATCH', 'POST', 'PUT']
assert type(cls.admin) == bool
if cls.view == APIEndpoint.view:
assert issubclass(cls.job, APIJob)
# Explicit checks rather than ``assert``: asserts are stripped
# when Python runs with -O, which would silently skip validation.
name = cls.__name__
if not cls.rule or not isinstance(cls.rule, str):
raise TypeError(f"{name}.rule must be a non-empty string")

Check warning on line 90 in bert_e/server/api/base.py

View check run for this annotation

Codecov / codecov/patch

bert_e/server/api/base.py#L90

Added line #L90 was not covered by tests
if cls.method not in ('GET', 'DELETE', 'PATCH', 'POST', 'PUT'):
raise ValueError(f"{name}.method {cls.method!r} is not a "

Check warning on line 92 in bert_e/server/api/base.py

View check run for this annotation

Codecov / codecov/patch

bert_e/server/api/base.py#L92

Added line #L92 was not covered by tests
"supported HTTP method")
if not isinstance(cls.admin, bool):
raise TypeError(f"{name}.admin must be a bool")

Check warning on line 95 in bert_e/server/api/base.py

View check run for this annotation

Codecov / codecov/patch

bert_e/server/api/base.py#L95

Added line #L95 was not covered by tests
if cls.view == APIEndpoint.view and not (
isinstance(cls.job, type) and issubclass(cls.job, APIJob)):
raise TypeError(f"{name}.job must be a subclass of APIJob "

Check warning on line 98 in bert_e/server/api/base.py

View check run for this annotation

Codecov / codecov/patch

bert_e/server/api/base.py#L98

Added line #L98 was not covered by tests
"when view() is not overridden")

@staticmethod
def validate_endpoint_data(*args, **kwargs):
Expand Down
Loading