From 49b8a206f2771011a6e915cf55c81ecbe434721f Mon Sep 17 00:00:00 2001 From: Jared Atkinson Date: Thu, 19 Nov 2026 21:50:09 -0800 Subject: [PATCH] fix: BED-10665 preserve organization role assignments without descriptions --- src/openhound_github/models/org_role_team.py | 2 +- tests/test_org_role_model.py | 75 ++++++++++++++++++++ 2 files changed, 76 insertions(+), 1 deletion(-) diff --git a/src/openhound_github/models/org_role_team.py b/src/openhound_github/models/org_role_team.py index 08f41653..03a12cd6 100644 --- a/src/openhound_github/models/org_role_team.py +++ b/src/openhound_github/models/org_role_team.py @@ -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 diff --git a/tests/test_org_role_model.py b/tests/test_org_role_model.py index f27be232..cd5f208a 100644 --- a/tests/test_org_role_model.py +++ b/tests/test_org_role_model.py @@ -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 @@ -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() + )