Skip to content
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

Major refactor of helper functions #167

Draft
wants to merge 36 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
3dfd816
Base implementation of CIVSource and validations
chrisvanrun Aug 20, 2024
73e2f76
Minor refactor of upload sources and allow for values as input to fil…
chrisvanrun Aug 22, 2024
b8377cd
Initial version of add_civ_sets
chrisvanrun Aug 22, 2024
459fda4
Refactor proto civ
chrisvanrun Aug 22, 2024
a60beaa
Minor improvements
chrisvanrun Aug 22, 2024
22731a9
Add model casting to ModifiableMixin
chrisvanrun Aug 23, 2024
d50d251
Disable https checks (should revert)
chrisvanrun Aug 23, 2024
2824521
Correctly implement generators in protoCIV
chrisvanrun Aug 23, 2024
092c482
Simplify interface cache
chrisvanrun Aug 23, 2024
b39de18
Fix upload source tests
chrisvanrun Aug 23, 2024
f384e9b
Rename upload sources
chrisvanrun Aug 23, 2024
a4eea12
Apply fixes for tests
chrisvanrun Aug 26, 2024
a9ceb3b
Extend add_cases_reader_study tests
chrisvanrun Aug 26, 2024
7284545
Add ProtoJob
chrisvanrun Aug 26, 2024
069b73c
Convert update_archive_item, minor refactors
chrisvanrun Aug 26, 2024
dcad7e0
Add api_url detail retrieval and test for HyperlinkedImage
chrisvanrun Aug 27, 2024
baf2eae
Add add_cases_to_archive
chrisvanrun Aug 27, 2024
1022c00
DRY civ_set tests
chrisvanrun Aug 27, 2024
a636667
Add update_display_set
chrisvanrun Aug 27, 2024
89c5ff7
Update docstring
chrisvanrun Aug 27, 2024
7a92f50
Revert "Disable https checks (should revert)"
chrisvanrun Aug 27, 2024
b9c4932
Revert local api URL change
chrisvanrun Aug 27, 2024
48abf62
Test for HyperlinkedComponentInterfaceValueFactory
chrisvanrun Aug 27, 2024
97d74c6
Unflaky an order based integration test
chrisvanrun Aug 27, 2024
ffbb9a9
Minor typing
chrisvanrun Aug 27, 2024
aa90608
Check for pk + api_url + params
chrisvanrun Aug 27, 2024
4613179
Fix non-model get_file usage
chrisvanrun Aug 27, 2024
b6c7266
Remove '# type: ignore'
chrisvanrun Aug 27, 2024
e7dae9e
Fix incorrect kwargs
chrisvanrun Aug 27, 2024
4526306
Make test more robust: do not use iterator when detail suffices.
chrisvanrun Aug 27, 2024
d6bd5a3
REALLY remove the # type: ignore
chrisvanrun Aug 27, 2024
d4f923c
Minor syntax
chrisvanrun Aug 27, 2024
3a92a4b
Fix copy+pasta addition of awaits
chrisvanrun Aug 27, 2024
a2b23e4
Add race-safe check for complete civ_set
chrisvanrun Aug 27, 2024
d4278cb
Fix deprecation warnings in tests
chrisvanrun Aug 27, 2024
1a458cb
Also recurse when ObjectNotFound is thrown.
chrisvanrun Aug 28, 2024
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
23 changes: 17 additions & 6 deletions gcapi/apibase.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,14 +143,20 @@ def iterate_all(self, params=None) -> Iterator[T]:
yield from current_list
offset += req_count

def detail(self, pk=None, **params) -> Generator[T, dict[Any, Any], T]:
def detail(
self, pk=None, api_url=None, **params
) -> Generator[T, dict[Any, Any], T]:
if all((pk, params)):
raise ValueError("Only one of pk or params must be specified")

if pk is not None:
if pk is not None or api_url is not None:
if pk is not None:
request_kwargs = dict(path=urljoin(self.base_path, pk + "/"))
else:
request_kwargs = dict(url=api_url)
try:
result = yield self.yield_request(
method="GET", path=urljoin(self.base_path, pk + "/")
method="GET", **request_kwargs
)
return self.model(**result)
except HTTPStatusError as e:
Expand All @@ -170,6 +176,8 @@ def detail(self, pk=None, **params) -> Generator[T, dict[Any, Any], T]:


class ModifiableMixin(Common):
response_model: type

def _process_request_arguments(self, data):
if data is None:
data = {}
Expand All @@ -188,13 +196,16 @@ def perform_request(self, method, data=None, pk=False):
return (yield from self._execute_request(method, data, pk))

def create(self, **kwargs):
return (yield from self.perform_request("POST", data=kwargs))
result = yield from self.perform_request("POST", data=kwargs)
return self.response_model(**result)

def update(self, pk, **kwargs):
return (yield from self.perform_request("PUT", pk=pk, data=kwargs))
result = yield from self.perform_request("PUT", pk=pk, data=kwargs)
return self.response_model(**result)

def partial_update(self, pk, **kwargs):
return (yield from self.perform_request("PATCH", pk=pk, data=kwargs))
result = yield from self.perform_request("PATCH", pk=pk, data=kwargs)
return self.response_model(**result)

def delete(self, pk):
return (yield from self.perform_request("DELETE", pk=pk))
Loading
Loading