Skip to content

Commit 96e456e

Browse files
committed
more fixes
1 parent 205799f commit 96e456e

15 files changed

+11
-295
lines changed

backend/app/infrastructure/mappers/__init__.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,16 @@
1414
from .rate_limit_mapper import (
1515
RateLimitConfigMapper,
1616
RateLimitRuleMapper,
17-
RateLimitStatusMapper,
1817
UserRateLimitMapper,
1918
)
2019
from .replay_api_mapper import ReplayApiMapper
2120
from .replay_mapper import ReplayApiMapper as AdminReplayApiMapper
2221
from .replay_mapper import (
2322
ReplayQueryMapper,
24-
ReplaySessionDataMapper,
2523
ReplaySessionMapper,
2624
ReplayStateMapper,
2725
)
2826
from .saga_mapper import (
29-
SagaEventMapper,
3027
SagaFilterMapper,
3128
SagaInstanceMapper,
3229
SagaMapper,
@@ -52,13 +49,11 @@
5249
"RateLimitRuleMapper",
5350
"UserRateLimitMapper",
5451
"RateLimitConfigMapper",
55-
"RateLimitStatusMapper",
5652
# Replay
5753
"ReplayApiMapper",
5854
"AdminReplayApiMapper",
5955
"ReplaySessionMapper",
6056
"ReplayQueryMapper",
61-
"ReplaySessionDataMapper",
6257
"ReplayStateMapper",
6358
# Saved scripts
6459
"SavedScriptMapper",
@@ -69,6 +64,5 @@
6964
# Saga
7065
"SagaMapper",
7166
"SagaFilterMapper",
72-
"SagaEventMapper",
7367
"SagaInstanceMapper",
7468
]

backend/app/infrastructure/mappers/rate_limit_mapper.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import json
2-
from dataclasses import asdict
32
from datetime import datetime, timezone
43
from typing import Any, Dict
54

@@ -8,7 +7,6 @@
87
RateLimitAlgorithm,
98
RateLimitConfig,
109
RateLimitRule,
11-
RateLimitStatus,
1210
UserRateLimit,
1311
)
1412

@@ -124,9 +122,3 @@ def model_validate_json(json_str: str | bytes) -> RateLimitConfig:
124122
def model_dump_json(config: RateLimitConfig) -> str:
125123
"""Pydantic-compatible method for serialization to JSON."""
126124
return json.dumps(RateLimitConfigMapper.to_dict(config))
127-
128-
129-
class RateLimitStatusMapper:
130-
@staticmethod
131-
def to_dict(status: RateLimitStatus) -> Dict[str, Any]:
132-
return asdict(status)

backend/app/infrastructure/mappers/replay_mapper.py

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
from app.domain.admin import (
55
ReplayQuery,
66
ReplaySession,
7-
ReplaySessionData,
87
ReplaySessionFields,
98
ReplaySessionStatusDetail,
109
ReplaySessionStatusInfo,
@@ -150,30 +149,6 @@ def to_mongodb_query(query: ReplayQuery) -> dict[str, Any]:
150149
return mongo_query
151150

152151

153-
class ReplaySessionDataMapper:
154-
@staticmethod
155-
def to_dict(data: ReplaySessionData) -> dict[str, Any]:
156-
result = {
157-
"dry_run": data.dry_run,
158-
"total_events": data.total_events,
159-
"replay_correlation_id": data.replay_correlation_id,
160-
"query": data.query,
161-
}
162-
163-
if data.dry_run and data.events_preview:
164-
result["events_preview"] = [
165-
{
166-
"event_id": e.event_id,
167-
"event_type": e.event_type,
168-
"timestamp": e.timestamp,
169-
"aggregate_id": e.aggregate_id,
170-
}
171-
for e in data.events_preview
172-
]
173-
174-
return result
175-
176-
177152
class ReplayApiMapper:
178153
"""API-level mapper for converting replay requests to domain queries."""
179154

backend/app/infrastructure/mappers/saga_mapper.py

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
from app.domain.enums.saga import SagaState
44
from app.domain.saga.models import Saga, SagaFilter, SagaInstance
5-
from app.infrastructure.kafka.events.metadata import AvroEventMetadata as EventMetadata
6-
from app.infrastructure.kafka.events.saga import SagaCancelledEvent
75

86

97
class SagaMapper:
@@ -139,37 +137,6 @@ def to_mongo(instance: SagaInstance) -> dict[str, Any]:
139137
}
140138

141139

142-
class SagaEventMapper:
143-
"""Maps saga domain objects to typed Kafka events."""
144-
145-
@staticmethod
146-
def to_cancelled_event(
147-
instance: SagaInstance,
148-
*,
149-
user_id: str | None = None,
150-
service_name: str = "saga-orchestrator",
151-
service_version: str = "1.0.0",
152-
) -> SagaCancelledEvent:
153-
cancelled_by = user_id or instance.context_data.get("user_id") or "system"
154-
metadata = EventMetadata(
155-
service_name=service_name,
156-
service_version=service_version,
157-
user_id=cancelled_by,
158-
)
159-
160-
return SagaCancelledEvent(
161-
saga_id=instance.saga_id,
162-
saga_name=instance.saga_name,
163-
execution_id=instance.execution_id,
164-
reason=instance.error_message or "User requested cancellation",
165-
completed_steps=instance.completed_steps,
166-
compensated_steps=instance.compensated_steps,
167-
cancelled_at=instance.completed_at,
168-
cancelled_by=cancelled_by,
169-
metadata=metadata,
170-
)
171-
172-
173140
class SagaFilterMapper:
174141
"""Maps saga filters to MongoDB queries."""
175142

backend/tests/unit/infrastructure/mappers/test_admin_mapper.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import pytest
21
from datetime import datetime, timezone
32

4-
from app.infrastructure.mappers import AuditLogMapper, SettingsMapper, UserMapper
3+
import pytest
54
from app.domain.admin import (
65
AuditAction,
76
AuditLogEntry,
@@ -11,10 +10,10 @@
1110
SystemSettings,
1211
)
1312
from app.domain.user import User as DomainAdminUser
14-
from app.domain.user import UserRole, UserUpdate, UserCreation
13+
from app.domain.user import UserCreation, UserRole, UserUpdate
14+
from app.infrastructure.mappers import AuditLogMapper, SettingsMapper, UserMapper
1515
from app.schemas_pydantic.user import User as ServiceUser
1616

17-
1817
pytestmark = pytest.mark.unit
1918

2019

backend/tests/unit/infrastructure/mappers/test_event_mapper_extended.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,9 @@
33
from datetime import datetime, timezone
44

55
import pytest
6-
76
from app.domain.events.event_models import (
87
ArchivedEvent,
98
Event,
10-
EventExportRow,
119
EventFields,
1210
EventFilter,
1311
)

backend/tests/unit/infrastructure/mappers/test_infra_event_mapper.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from datetime import datetime, timezone
22

33
import pytest
4-
54
from app.domain.events.event_models import (
65
Event,
76
EventSummary,

backend/tests/unit/infrastructure/mappers/test_rate_limit_mapper.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
11
from datetime import datetime, timedelta, timezone
22

33
import pytest
4-
54
from app.domain.rate_limit.rate_limit_models import (
65
EndpointGroup,
76
RateLimitAlgorithm,
87
RateLimitConfig,
98
RateLimitRule,
10-
RateLimitStatus,
119
UserRateLimit,
1210
)
1311
from app.infrastructure.mappers import (
1412
RateLimitConfigMapper,
1513
RateLimitRuleMapper,
16-
RateLimitStatusMapper,
1714
UserRateLimitMapper,
1815
)
1916

@@ -36,7 +33,7 @@ def test_user_rate_limit_mapper_roundtrip_and_dates() -> None:
3633
assert u2.user_id == "u1" and len(u2.rules) == 1 and isinstance(u2.created_at, datetime)
3734

3835
# from string timestamps
39-
d["created_at"] = now.isoformat();
36+
d["created_at"] = now.isoformat()
4037
d["updated_at"] = (now + timedelta(seconds=1)).isoformat()
4138
u3 = UserRateLimitMapper.from_dict(d)
4239
assert u3.created_at <= u3.updated_at
@@ -53,9 +50,3 @@ def test_config_mapper_roundtrip_and_json() -> None:
5350
js = RateLimitConfigMapper.model_dump_json(cfg)
5451
c3 = RateLimitConfigMapper.model_validate_json(js)
5552
assert isinstance(c3, RateLimitConfig) and c3.global_enabled is False
56-
57-
58-
def test_status_mapper_to_dict() -> None:
59-
s = RateLimitStatus(allowed=True, limit=10, remaining=5, reset_at=datetime.now(timezone.utc))
60-
d = RateLimitStatusMapper.to_dict(s)
61-
assert d["allowed"] is True and d["limit"] == 10

backend/tests/unit/infrastructure/mappers/test_rate_limit_mapper_extended.py

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,16 @@
33
from datetime import datetime, timezone
44

55
import pytest
6-
76
from app.domain.rate_limit import (
87
EndpointGroup,
98
RateLimitAlgorithm,
109
RateLimitConfig,
1110
RateLimitRule,
12-
RateLimitStatus,
1311
UserRateLimit,
1412
)
1513
from app.infrastructure.mappers.rate_limit_mapper import (
1614
RateLimitConfigMapper,
1715
RateLimitRuleMapper,
18-
RateLimitStatusMapper,
1916
UserRateLimitMapper,
2017
)
2118

@@ -322,42 +319,3 @@ def test_model_dump_json(self):
322319
assert data["default_rules"][0]["endpoint_pattern"] == "/test"
323320
assert data["global_enabled"] is True
324321
assert data["redis_ttl"] == 3600
325-
326-
327-
class TestRateLimitStatusMapper:
328-
"""Test RateLimitStatusMapper."""
329-
330-
def test_to_dict(self):
331-
"""Test converting RateLimitStatus to dict using asdict."""
332-
status = RateLimitStatus(
333-
allowed=True,
334-
limit=100,
335-
remaining=75,
336-
reset_at=datetime(2024, 1, 1, 12, 0, 0, tzinfo=timezone.utc),
337-
retry_after=None,
338-
)
339-
340-
result = RateLimitStatusMapper.to_dict(status)
341-
342-
assert result["allowed"] is True
343-
assert result["limit"] == 100
344-
assert result["remaining"] == 75
345-
assert result["reset_at"] == status.reset_at
346-
assert result["retry_after"] is None
347-
348-
def test_to_dict_with_retry_after(self):
349-
"""Test converting RateLimitStatus with retry_after set."""
350-
status = RateLimitStatus(
351-
allowed=False,
352-
limit=100,
353-
remaining=0,
354-
reset_at=datetime(2024, 1, 1, 12, 5, 0, tzinfo=timezone.utc),
355-
retry_after=300, # 5 minutes
356-
)
357-
358-
result = RateLimitStatusMapper.to_dict(status)
359-
360-
assert result["allowed"] is False
361-
assert result["limit"] == 100
362-
assert result["remaining"] == 0
363-
assert result["retry_after"] == 300

backend/tests/unit/infrastructure/mappers/test_replay_api_mapper.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33
from datetime import datetime, timezone
44

55
import pytest
6-
76
from app.domain.enums.events import EventType
8-
from app.domain.enums.replay import ReplayStatus, ReplayType, ReplayTarget
7+
from app.domain.enums.replay import ReplayStatus, ReplayTarget, ReplayType
98
from app.domain.replay import ReplayConfig, ReplayFilter, ReplaySessionState
109
from app.infrastructure.mappers.replay_api_mapper import ReplayApiMapper
1110
from app.schemas_pydantic.replay import ReplayRequest
@@ -389,4 +388,4 @@ def test_cleanup_to_response(self):
389388
)
390389

391390
assert response.removed_sessions == 5
392-
assert response.message == "Cleaned up 5 old sessions"
391+
assert response.message == "Cleaned up 5 old sessions"

0 commit comments

Comments
 (0)