diff --git a/CHANGELOG.md b/CHANGELOG.md index 201776c..18f7dfd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,12 @@ how a consumer would use the library or CLI tool (e.g. adding unit tests, updating documentation, etc) are not captured here. +## Unreleased + +### Updated + +- `client.actors.v1.get_actor_by_name` now defaults to `prefer_parent=True`. Previously, it defaulted to `False`. + ## 2.1.0 - 2024-09-30 ### Added diff --git a/src/_incydr_sdk/actors/client.py b/src/_incydr_sdk/actors/client.py index ce98a18..099eab3 100644 --- a/src/_incydr_sdk/actors/client.py +++ b/src/_incydr_sdk/actors/client.py @@ -118,14 +118,14 @@ def get_actor_by_id(self, actor_id: str, prefer_parent: bool = False) -> Actor: if err.response.status_code == 404: raise ActorNotFoundError - def get_actor_by_name(self, name: str, prefer_parent: bool = False) -> Actor: + def get_actor_by_name(self, name: str, prefer_parent: bool = True) -> Actor: """ Get an actor by their name. **Parameters**: * **name**: `str` (required) - The actor name. - * **prefer_parent**: `str` - Returns an actor's parent when applicable. Returns an actor themselves if they have no parent. + * **prefer_parent**: `str` - Returns an actor's parent when applicable. Returns an actor themselves if they have no parent. Defaults to True. **Returns**: An [`Actor`][actor-model] object representing the actor. """ @@ -142,7 +142,10 @@ def get_actor_by_name(self, name: str, prefer_parent: bool = False) -> Actor: matches = self.get_page(name_starts_with=name) for actor in matches.actors: if actor.name == name: - return actor + actor_profile = self._parent.session.get( + f"/v1/actors/actor/id/{actor.actor_id}" + ) + return Actor.parse_response(actor_profile) raise ActorNotFoundError(name) def get_family_by_member_id(self, actor_id: str) -> ActorFamily: diff --git a/tests/test_actors.py b/tests/test_actors.py index b5a2bfa..4ac5cb5 100644 --- a/tests/test_actors.py +++ b/tests/test_actors.py @@ -143,6 +143,9 @@ def mock_get_actor_by_name(httpserver_auth: HTTPServer): } ), ).respond_with_json({"actors": [CHILD_ACTOR]}) + httpserver_auth.expect_request( + "/v1/actors/actor/id/child-actor-id", method="GET" + ).respond_with_json(CHILD_ACTOR) @pytest.fixture @@ -407,7 +410,7 @@ def test_get_actor_by_id_with_prefer_parent_returns_expected_data( def test_get_actor_by_name_returns_expected_data(mock_get_actor_by_name): client = Client() - response = client.actors.v1.get_actor_by_name(CHILD_ACTOR_NAME) + response = client.actors.v1.get_actor_by_name(CHILD_ACTOR_NAME, prefer_parent=False) assert isinstance(response, Actor) assert response.actor_id == CHILD_ACTOR_ID assert response.name == CHILD_ACTOR_NAME @@ -438,7 +441,7 @@ def test_get_actor_by_name_when_actor_not_found_raises_error( client = Client() with pytest.raises(ActorNotFoundError) as e: - client.actors.v1.get_actor_by_name(CHILD_ACTOR_NAME) + client.actors.v1.get_actor_by_name(CHILD_ACTOR_NAME, prefer_parent=False) assert "Actor Not Found Error" in str(e.value)