-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add: e2e tests for entities and entity lists
- fix: entity.py `create()` should send JSON not form-encoded data - fix: projects.py typo in comment - chg: readme.md make description generic rather than listing everything - add: test entity_lists.py creation of test fixture with properties - add: e2e test cases for entities and entity_lists functionality
- Loading branch information
1 parent
5530d12
commit 1715fdd
Showing
5 changed files
with
86 additions
and
3 deletions.
There are no files selected for viewing
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
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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
from pyodk._endpoints.entity_lists import EntityList, log | ||
from pyodk.client import Client | ||
from pyodk.errors import PyODKError | ||
|
||
|
||
def create_new_or_get_entity_list( | ||
client: Client, entity_list_name: str, entity_props: list[str] | ||
) -> EntityList: | ||
""" | ||
Create a new entity list, or get the entity list metadata. | ||
:param client: Client instance to use for API calls. | ||
:param entity_list_name: Name of the entity list. | ||
:param entity_props: Properties to add to the entity list. | ||
""" | ||
try: | ||
entity_list = client.session.response_or_error( | ||
method="POST", | ||
url=client.session.urlformat( | ||
"projects/{pid}/datasets", | ||
pid=client.project_id, | ||
), | ||
logger=log, | ||
json={"name": entity_list_name}, | ||
) | ||
except PyODKError: | ||
entity_list = client.session.get( | ||
url=client.session.urlformat( | ||
"projects/{pid}/datasets/{eln}", | ||
pid=client.project_id, | ||
eln=entity_list_name, | ||
), | ||
) | ||
try: | ||
for prop in entity_props: | ||
client.session.response_or_error( | ||
method="GET", | ||
url=client.session.urlformat( | ||
"projects/{pid}/datasets/{eln}/properties", | ||
pid=client.project_id, | ||
eln=entity_list_name, | ||
), | ||
logger=log, | ||
json={"name": prop}, | ||
) | ||
except PyODKError: | ||
pass | ||
return EntityList(**entity_list.json()) |