shared: implementazione package identity
Continuous Integration / Quality Assurance (push) Canceled after 0s

This commit is contained in:
2026-08-06 17:01:45 +02:00
parent 3bf84e4163
commit 575deedaa2
18 changed files with 718 additions and 0 deletions
+43
View File
@@ -0,0 +1,43 @@
"""
Tests for the ArtifactId Value Object.
"""
from __future__ import annotations
from shared.identity import ArtifactId, Identifier
def test_new_creates_module_id() -> None:
"""A new ArtifactId should be created."""
# Arrange
# Act
module_id = ArtifactId.new()
# Assert
assert isinstance(module_id, ArtifactId)
def test_module_id_is_identifier() -> None:
"""ArtifactId should inherit from Identifier."""
# Arrange
# Act
module_id = ArtifactId.new()
# Assert
assert isinstance(module_id, Identifier)
def test_module_id_preserves_type() -> None:
"""Factory methods should preserve the concrete type."""
# Arrange
# Act
module_id = ArtifactId.new()
# Assert
assert type(module_id) is ArtifactId
@@ -0,0 +1,43 @@
"""
Tests for the BlueprintId Value Object.
"""
from __future__ import annotations
from shared.identity import BlueprintId, Identifier
def test_new_creates_module_id() -> None:
"""A new BlueprintId should be created."""
# Arrange
# Act
module_id = BlueprintId.new()
# Assert
assert isinstance(module_id, BlueprintId)
def test_module_id_is_identifier() -> None:
"""BlueprintId should inherit from Identifier."""
# Arrange
# Act
module_id = BlueprintId.new()
# Assert
assert isinstance(module_id, Identifier)
def test_module_id_preserves_type() -> None:
"""Factory methods should preserve the concrete type."""
# Arrange
# Act
module_id = BlueprintId.new()
# Assert
assert type(module_id) is BlueprintId
@@ -0,0 +1,43 @@
"""
Tests for the ExecutionId Value Object.
"""
from __future__ import annotations
from shared.identity import ExecutionId, Identifier
def test_new_creates_module_id() -> None:
"""A new ExecutionId should be created."""
# Arrange
# Act
module_id = ExecutionId.new()
# Assert
assert isinstance(module_id, ExecutionId)
def test_module_id_is_identifier() -> None:
"""ExecutionId should inherit from Identifier."""
# Arrange
# Act
module_id = ExecutionId.new()
# Assert
assert isinstance(module_id, Identifier)
def test_module_id_preserves_type() -> None:
"""Factory methods should preserve the concrete type."""
# Arrange
# Act
module_id = ExecutionId.new()
# Assert
assert type(module_id) is ExecutionId
+158
View File
@@ -0,0 +1,158 @@
"""
Tests for the Identifier Value Object.
"""
from __future__ import annotations
from dataclasses import FrozenInstanceError
from uuid import UUID
import pytest
from shared.identity import Identifier
def test_new_creates_identifier() -> None:
"""A new identifier should contain a valid UUID."""
# Arrange
# Act
identifier = Identifier.new()
# Assert
assert isinstance(identifier.value, UUID)
def test_from_string_creates_identifier() -> None:
"""An identifier can be created from a UUID string."""
# Arrange
value = "550e8400-e29b-41d4-a716-446655440000"
# Act
identifier = Identifier.from_string(value)
# Assert
assert identifier.value == UUID(value)
def test_from_uuid_creates_identifier() -> None:
"""An identifier can be created from an existing UUID."""
# Arrange
value = UUID("550e8400-e29b-41d4-a716-446655440000")
# Act
identifier = Identifier.from_uuid(value)
# Assert
assert identifier.value == value
def test_from_string_raises_for_invalid_uuid() -> None:
"""Creating an identifier from an invalid UUID should fail."""
# Arrange
value = "invalid-uuid"
# Act / Assert
with pytest.raises(ValueError):
Identifier.from_string(value)
def test_identifiers_with_same_value_are_equal() -> None:
"""Identifiers with the same UUID should be equal."""
# Arrange
value = UUID("550e8400-e29b-41d4-a716-446655440000")
# Act
first = Identifier.from_uuid(value)
second = Identifier.from_uuid(value)
# Assert
assert first == second
def test_identifiers_with_different_values_are_not_equal() -> None:
"""Identifiers with different UUIDs should not be equal."""
# Arrange / Act
first = Identifier.new()
second = Identifier.new()
# Assert
assert first != second
def test_identifier_is_hashable() -> None:
"""Identifiers should be hashable."""
# Arrange
identifier = Identifier.new()
# Act
values = {identifier}
# Assert
assert identifier in values
def test_str_returns_uuid_string() -> None:
"""The string representation should match the UUID."""
# Arrange
identifier = Identifier.from_string(
"550e8400-e29b-41d4-a716-446655440000",
)
# Act / Assert
assert str(identifier) == "550e8400-e29b-41d4-a716-446655440000"
def test_repr_returns_developer_representation() -> None:
"""The repr should contain the class name and UUID."""
# Arrange
identifier = Identifier.from_string(
"550e8400-e29b-41d4-a716-446655440000",
)
# Act / Assert
assert repr(identifier) == "Identifier('550e8400-e29b-41d4-a716-446655440000')"
def test_hex_returns_uuid_hexadecimal() -> None:
"""The hexadecimal representation should match the UUID."""
# Arrange
identifier = Identifier.from_string(
"550e8400-e29b-41d4-a716-446655440000",
)
# Act / Assert
assert identifier.hex == "550e8400e29b41d4a716446655440000"
def test_urn_returns_uuid_urn() -> None:
"""The URN representation should match the UUID."""
# Arrange
identifier = Identifier.from_string(
"550e8400-e29b-41d4-a716-446655440000",
)
# Act / Assert
assert identifier.urn == "urn:uuid:550e8400-e29b-41d4-a716-446655440000"
def test_identifier_is_immutable() -> None:
"""Identifiers must be immutable."""
# Arrange
identifier = Identifier.new()
# Act / Assert
with pytest.raises(FrozenInstanceError):
object.__setattr__(identifier, "value", UUID(int=0))
+43
View File
@@ -0,0 +1,43 @@
"""
Tests for the ModuleId Value Object.
"""
from __future__ import annotations
from shared.identity import Identifier, ModuleId
def test_new_creates_module_id() -> None:
"""A new ModuleId should be created."""
# Arrange
# Act
module_id = ModuleId.new()
# Assert
assert isinstance(module_id, ModuleId)
def test_module_id_is_identifier() -> None:
"""ModuleId should inherit from Identifier."""
# Arrange
# Act
module_id = ModuleId.new()
# Assert
assert isinstance(module_id, Identifier)
def test_module_id_preserves_type() -> None:
"""Factory methods should preserve the concrete type."""
# Arrange
# Act
module_id = ModuleId.new()
# Assert
assert type(module_id) is ModuleId
+43
View File
@@ -0,0 +1,43 @@
"""
Tests for the RequestId Value Object.
"""
from __future__ import annotations
from shared.identity import Identifier, RequestId
def test_new_creates_module_id() -> None:
"""A new RequestId should be created."""
# Arrange
# Act
module_id = RequestId.new()
# Assert
assert isinstance(module_id, RequestId)
def test_module_id_is_identifier() -> None:
"""RequestId should inherit from Identifier."""
# Arrange
# Act
module_id = RequestId.new()
# Assert
assert isinstance(module_id, Identifier)
def test_module_id_preserves_type() -> None:
"""Factory methods should preserve the concrete type."""
# Arrange
# Act
module_id = RequestId.new()
# Assert
assert type(module_id) is RequestId
+43
View File
@@ -0,0 +1,43 @@
"""
Tests for the SessionId Value Object.
"""
from __future__ import annotations
from shared.identity import Identifier, SessionId
def test_new_creates_module_id() -> None:
"""A new SessionId should be created."""
# Arrange
# Act
module_id = SessionId.new()
# Assert
assert isinstance(module_id, SessionId)
def test_module_id_is_identifier() -> None:
"""SessionId should inherit from Identifier."""
# Arrange
# Act
module_id = SessionId.new()
# Assert
assert isinstance(module_id, Identifier)
def test_module_id_preserves_type() -> None:
"""Factory methods should preserve the concrete type."""
# Arrange
# Act
module_id = SessionId.new()
# Assert
assert type(module_id) is SessionId