-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[py-578][py-580] get properties endpoints (#747)
* base annotation darwin * fixes for annotations * base str vs url * tests for base annotation loading * cleanup * cleanup 2: electric boogaloo * test bounding box auto-calculate * typing * cleanup * property addition * property metadata parsing * cleanup validator * test for properties base example * linting * Changes for list/get endpoint * linting * get_all_properties * get properties and get by id * linting * base annotation darwin * fixes for annotations * base str vs url * tests for base annotation loading * cleanup * cleanup 2: electric boogaloo * test bounding box auto-calculate * typing * cleanup * property metadata parsing * cleanup validator * test for properties base example * Changes for list/get endpoint * get_all_properties * get properties and get by id * linting * linting * QS helper and params checker on team_full_properties * change for lower case True * test change
- Loading branch information
1 parent
e12b601
commit 009ba15
Showing
7 changed files
with
195 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from darwin.future.core.properties.get import ( | ||
get_property_by_id, | ||
get_team_full_properties, | ||
get_team_properties, | ||
) |
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,72 @@ | ||
from typing import List, Optional, Union | ||
from uuid import UUID | ||
|
||
from pydantic import parse_obj_as | ||
|
||
from darwin.future.core.client import ClientCore | ||
from darwin.future.core.types.common import QueryString | ||
from darwin.future.data_objects.properties import FullProperty | ||
|
||
|
||
def get_team_properties( | ||
client: ClientCore, | ||
team_slug: Optional[str] = None, | ||
params: Optional[QueryString] = None, | ||
) -> List[FullProperty]: | ||
""" | ||
Returns a List[FullProperty] object for the specified team slug. | ||
Parameters: | ||
client (ClientCore): The client to use for the request. | ||
team_slug (Optional[str]): The slug of the team to get. If not specified, the | ||
default team from the client's config will be used. | ||
Returns: | ||
List[FullProperty]: List of FullProperty objects for the specified team slug. | ||
Raises: | ||
HTTPError: If the response status code is not in the 200-299 range. | ||
""" | ||
if not team_slug: | ||
team_slug = client.config.default_team | ||
response = client.get(f"/v2/teams/{team_slug}/properties", query_string=params) | ||
assert isinstance(response, dict) | ||
return parse_obj_as(List[FullProperty], response.get("properties")) | ||
|
||
|
||
def get_team_full_properties( | ||
client: ClientCore, | ||
team_slug: Optional[str] = None, | ||
params: Optional[QueryString] = None, | ||
) -> List[FullProperty]: | ||
params = ( | ||
params + QueryString({"include_values": True}) | ||
if params and not params.get("include_values") | ||
else QueryString({"include_values": True}) | ||
) | ||
return get_team_properties(client, team_slug, params) | ||
|
||
|
||
def get_property_by_id( | ||
client: ClientCore, property_id: Union[str, UUID], team_slug: Optional[str] = None | ||
) -> FullProperty: | ||
""" | ||
Returns a FullProperty object for the specified team slug. | ||
Parameters: | ||
client (ClientCore): The client to use for the request. | ||
property_id (str | UUID): The ID of the property to get. | ||
team_slug (Optional[str]): The slug of the team to get. If not specified, the | ||
default team from the client's config will be used. | ||
Returns: | ||
FullProperty: FullProperty object from id | ||
Raises: | ||
HTTPError: If the response status code is not in the 200-299 range. | ||
""" | ||
if not team_slug: | ||
team_slug = client.config.default_team | ||
response = client.get(f"/v2/teams/{team_slug}/properties/{property_id}") | ||
assert isinstance(response, dict) | ||
return parse_obj_as(FullProperty, response) |
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
Empty file.
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,82 @@ | ||
import responses | ||
from responses.matchers import query_param_matcher | ||
|
||
from darwin.future.core.client import ClientCore | ||
from darwin.future.core.properties import ( | ||
get_property_by_id, | ||
get_team_full_properties, | ||
get_team_properties, | ||
) | ||
from darwin.future.core.types.common import QueryString | ||
from darwin.future.data_objects.properties import FullProperty | ||
from darwin.future.tests.core.fixtures import * | ||
|
||
|
||
@responses.activate | ||
def test_get_team_properties( | ||
base_client: ClientCore, base_property_object: FullProperty | ||
) -> None: | ||
# Mocking the response using responses library | ||
base_property_object.options = None | ||
base_property_object.property_values = None | ||
response_data = {"properties": [base_property_object.dict()]} | ||
responses.add( | ||
responses.GET, | ||
f"{base_client.config.base_url}api/v2/teams/{base_client.config.default_team}/properties", | ||
json=response_data, | ||
status=200, | ||
) | ||
|
||
# Call the function being tested | ||
properties = get_team_properties(base_client) | ||
|
||
# Assertions | ||
assert isinstance(properties, list) | ||
assert all(isinstance(property, FullProperty) for property in properties) | ||
assert properties[0] == base_property_object | ||
|
||
|
||
@responses.activate | ||
def test_get_team_full_properties( | ||
base_client: ClientCore, base_property_object: FullProperty | ||
) -> None: | ||
# Mocking the response using responses library | ||
response_data = {"properties": [base_property_object.dict()]} | ||
responses.add( | ||
responses.GET, | ||
f"{base_client.config.base_url}api/v2/teams/{base_client.config.default_team}/properties", | ||
match=[ | ||
query_param_matcher({"include_values": "true"}), | ||
], | ||
json=response_data, | ||
status=200, | ||
) | ||
params = QueryString({"include_values": True}) | ||
# Call the function being tested | ||
properties = get_team_full_properties(base_client, params=params) | ||
|
||
# Assertions | ||
assert isinstance(properties, list) | ||
assert all(isinstance(property, FullProperty) for property in properties) | ||
assert properties[0] == base_property_object | ||
|
||
|
||
@responses.activate | ||
def test_get_property_by_id( | ||
base_client: ClientCore, base_property_object: FullProperty | ||
) -> None: | ||
# Mocking the response using responses library | ||
property_id = "0" | ||
responses.add( | ||
responses.GET, | ||
f"{base_client.config.base_url}api/v2/teams/{base_client.config.default_team}/properties/{property_id}", | ||
json=base_property_object.dict(), | ||
status=200, | ||
) | ||
|
||
# Call the function being tested | ||
property = get_property_by_id(base_client, property_id) | ||
|
||
# Assertions | ||
assert isinstance(property, FullProperty) | ||
assert property == base_property_object |
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