-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #90 from zest-derm/samm/parent-accessors
Unify parent accessor methods
- Loading branch information
Showing
15 changed files
with
329 additions
and
277 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,45 @@ | ||
import inspect | ||
|
||
import pytest | ||
|
||
from welkin.models import Patient, __all__ | ||
from welkin.models.base import Collection | ||
from welkin.pagination import PageIterator | ||
|
||
|
||
def test_collection_pageable(client): | ||
for v in vars(client).values(): | ||
try: | ||
if not issubclass(v, Collection): | ||
continue | ||
except TypeError: | ||
continue | ||
@pytest.mark.parametrize("class_name", __all__) | ||
def test_collection_pageable(client, class_name: str): | ||
cls = getattr(client, class_name) | ||
if not issubclass(cls, Collection): | ||
return | ||
|
||
assert hasattr(cls, "get"), f"{cls} has no get method" | ||
assert issubclass(cls.iterator, PageIterator) | ||
|
||
method = cls.get | ||
args = inspect.getfullargspec(method) | ||
assert args.varargs is not None, f"{method} must accept variable args" | ||
assert args.varkw is not None, f"{method} must accept variable kwargs" | ||
|
||
|
||
@pytest.mark.parametrize("class_name", __all__) | ||
def test_method_args(client, class_name: str): | ||
cls = getattr(client, class_name) | ||
|
||
for method_name, method in inspect.getmembers(cls, predicate=inspect.isfunction): | ||
if method_name.startswith("__"): | ||
continue # skip dunder methods | ||
|
||
if hasattr(method, "__wrapped__"): | ||
method = method.__wrapped__ # unwrap decorated functions | ||
|
||
if method.__qualname__ != f"{class_name}.{method_name}": | ||
continue # skip methods from parent classes | ||
|
||
assert hasattr(v, "get"), f"{v} has no get method" | ||
assert issubclass(v.iterator, PageIterator) | ||
args = inspect.getfullargspec(method) | ||
|
||
args = inspect.getfullargspec(v.get) | ||
assert args.varargs is not None, f"{v}.get must accept variable args" | ||
assert args.varkw is not None, f"{v}.get must accept variable kwargs" | ||
if cls in Patient.subresources: | ||
try: | ||
assert args.args.index("patient_id") == 1, f"patient_id must be first" | ||
except ValueError: | ||
pytest.fail(f"{method} must accept patient_id") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.