Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 6 additions & 3 deletions src/_incydr_sdk/actors/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
"""
Expand All @@ -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:
Expand Down
7 changes: 5 additions & 2 deletions tests/test_actors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)


Expand Down
Loading