feat: expose effective function incumbency contracts
This commit is contained in:
@@ -133,6 +133,100 @@ class IdmDirectoryDelegationTests(unittest.TestCase):
|
||||
)
|
||||
self.assertEqual(expected_ids, tuple(item.id for item in assignments))
|
||||
|
||||
def test_reverse_lookup_returns_only_effective_function_assignments(self) -> None:
|
||||
now = datetime.now(timezone.utc)
|
||||
active = IdmOrganizationFunctionAssignment(
|
||||
id="active-function-holder",
|
||||
tenant_id="tenant-1",
|
||||
identity_id="identity-active",
|
||||
account_id="account-active",
|
||||
function_id="function-1",
|
||||
organization_unit_id="unit-1",
|
||||
source="direct",
|
||||
is_active=True,
|
||||
settings={},
|
||||
)
|
||||
expired = IdmOrganizationFunctionAssignment(
|
||||
id="expired-function-holder",
|
||||
tenant_id="tenant-1",
|
||||
identity_id="identity-expired",
|
||||
function_id="function-1",
|
||||
organization_unit_id="unit-1",
|
||||
source="direct",
|
||||
is_active=True,
|
||||
valid_until=now - timedelta(minutes=1),
|
||||
settings={},
|
||||
)
|
||||
other_tenant = IdmOrganizationFunctionAssignment(
|
||||
id="other-tenant-holder",
|
||||
tenant_id="tenant-2",
|
||||
identity_id="identity-other",
|
||||
function_id="function-1",
|
||||
organization_unit_id="unit-1",
|
||||
source="direct",
|
||||
is_active=True,
|
||||
settings={},
|
||||
)
|
||||
with self.database.session() as session:
|
||||
session.add_all((active, expired, other_tenant))
|
||||
session.commit()
|
||||
|
||||
assignments = self.directory.organization_function_assignments_for_function(
|
||||
"function-1",
|
||||
tenant_id="tenant-1",
|
||||
)
|
||||
|
||||
self.assertEqual(
|
||||
("active-function-holder",),
|
||||
tuple(item.id for item in assignments),
|
||||
)
|
||||
|
||||
def test_batch_incumbency_reports_vacancy_and_honors_effective_time(
|
||||
self,
|
||||
) -> None:
|
||||
boundary = datetime.now(timezone.utc)
|
||||
assignment = IdmOrganizationFunctionAssignment(
|
||||
id="bounded-holder",
|
||||
tenant_id="tenant-1",
|
||||
identity_id="identity-bounded",
|
||||
account_id="account-bounded",
|
||||
function_id="function-1",
|
||||
organization_unit_id="unit-1",
|
||||
source="direct",
|
||||
is_active=True,
|
||||
valid_from=boundary - timedelta(hours=1),
|
||||
valid_until=boundary + timedelta(hours=1),
|
||||
settings={},
|
||||
)
|
||||
with self.database.session() as session:
|
||||
session.add(assignment)
|
||||
session.commit()
|
||||
|
||||
current = self.directory.organization_function_incumbencies(
|
||||
("function-1", "function-2"),
|
||||
tenant_id="tenant-1",
|
||||
effective_at=boundary,
|
||||
)
|
||||
later = self.directory.organization_function_incumbencies(
|
||||
("function-1",),
|
||||
tenant_id="tenant-1",
|
||||
effective_at=boundary + timedelta(hours=2),
|
||||
)
|
||||
|
||||
self.assertEqual(
|
||||
("bounded-holder",),
|
||||
tuple(item.id for item in current["function-1"].assignments),
|
||||
)
|
||||
self.assertFalse(current["function-1"].vacant)
|
||||
self.assertTrue(current["function-2"].vacant)
|
||||
self.assertTrue(later["function-1"].vacant)
|
||||
|
||||
with self.assertRaisesRegex(ValueError, "another tenant"):
|
||||
self.directory.organization_function_incumbencies(
|
||||
("function-1",),
|
||||
tenant_id="tenant-2",
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user