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
2 changes: 1 addition & 1 deletion src/openhound_github/models/org_role_team.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class OrgRoleTeam(BaseAsset):
url: str
name: str
slug: str
description: str
description: str | None = None
# privacy: Optional[str] = None
permission: str
members_url: str
Expand Down
75 changes: 75 additions & 0 deletions tests/test_org_role_model.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
from datetime import datetime
import json
from pathlib import Path
from unittest.mock import MagicMock

import pytest
from pydantic import ValidationError

from openhound_github.kinds import edges as ek
from openhound_github.models.org_role import OrgRole
from openhound_github.models.org_role_member import OrgRoleMember
from openhound_github.models.org_role_team import OrgRoleTeam
Expand Down Expand Up @@ -66,3 +73,71 @@ def test_custom_org_role_uses_role_only_name_for_assignment_node_ids() -> None:
assert role.as_node.properties.name == "acme/Custom Role Manager"
assert member.org_role_node_id == role.node_id
assert team.org_role_node_id == role.node_id


@pytest.fixture
def role_team_payload():
team = json.loads(
(Path(__file__).parent / "test_data/api/org-role-teams.json").read_text()
)[0]
return {
**team,
"org_role_id": 1,
"org_role_name": "Custom Role Manager",
"org_node_id": "ORG_1",
"org_login": "acme",
}


@pytest.mark.parametrize(
"description_fields",
[{"description": None}, {}, {"description": ""}, {"description": "Security team"}],
ids=["null", "missing", "empty", "populated"],
)
def test_org_role_team_preserves_assignment_with_optional_description(
role_team_payload, description_fields
):
from openhound_github.resources.organization import SourceContext, org_role_teams

role = _role("ORG_1", "acme", name="Custom Role Manager", role_type="custom")
team_payload = {
key: value
for key, value in role_team_payload.items()
if key
not in {
"description",
"org_role_id",
"org_role_name",
"org_node_id",
"org_login",
}
}
team_payload.update(description_fields)
client = MagicMock()
client.paginate.return_value = iter([[team_payload]])

rows = list(org_role_teams.__wrapped__(role, SourceContext(client=client)))
assert len(rows) == 1
assignment = OrgRoleTeam.model_validate(rows[0])
assert assignment.description == description_fields.get("description")
assert assignment.as_node is None
(edge,) = assignment.edges
assert edge.kind == ek.HAS_ROLE
assert edge.start.value == role_team_payload["node_id"]
assert edge.end.value == role.node_id
assert edge.start.match_by == edge.end.match_by == "id"
assert edge.properties.traversable is True
client.paginate.assert_called_once_with("/orgs/acme/organization-roles/1/teams")


@pytest.mark.parametrize(
"field", ["id", "node_id", "org_role_id", "org_role_name", "org_node_id"]
)
def test_org_role_team_still_requires_assignment_identifiers(role_team_payload, field):
del role_team_payload[field]
with pytest.raises(ValidationError) as caught:
OrgRoleTeam.model_validate(role_team_payload)
assert any(
error["loc"] == (field,) and error["type"] == "missing"
for error in caught.value.errors()
)