Skip to content

Commit ce3fede

Browse files
committed
Service tests
1 parent 8641899 commit ce3fede

7 files changed

Lines changed: 907 additions & 53 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ build-backend = "uv_build"
2626
dev = [
2727
"deptry>=0.24.0",
2828
"pytest>=9.0.2",
29+
"pytest-asyncio>=1.3.0",
2930
"ruff>=0.14.14",
3031
"time-machine>=3.2.0",
3132
"ty>=0.0.14",

src/circle/api.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,9 @@ async def get_pipeline_by_number(
7676
)
7777
return api_types.Pipeline.model_validate(response.json())
7878

79-
async def get_workflows(self, pipeline_id: str) -> list[api_types.Workflow]:
79+
async def get_pipeline_workflows(
80+
self, pipeline_id: str
81+
) -> list[api_types.Workflow]:
8082
"""
8183
GET /pipeline/{pipeline-id}/workflow
8284
"""
@@ -98,7 +100,7 @@ async def get_workflow(self, workflow_id: str) -> api_types.Workflow:
98100
)
99101
return api_types.Workflow.model_validate(response.json())
100102

101-
async def get_jobs(self, workflow_id: str) -> list[api_types.Job]:
103+
async def get_workflow_jobs(self, workflow_id: str) -> list[api_types.Job]:
102104
"""
103105
GET /workflow/{id}/job
104106
"""

src/circle/service.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ async def get_pipeline_workflows(
114114

115115
workflows = self.cache_manager.get_pipeline_workflows(pipeline_id)
116116
if workflows is None:
117-
workflows = await self.api_client.get_workflows(pipeline_id)
117+
workflows = await self.api_client.get_pipeline_workflows(pipeline_id)
118118
self.cache_manager.set_pipeline_workflows(pipeline_id, workflows)
119119

120120
return workflows
@@ -297,7 +297,7 @@ async def _get_workflow_jobs(
297297
) -> list[api_types.Job]:
298298
jobs = self.cache_manager.get_workflow_jobs(workflow.id)
299299
if jobs is None:
300-
jobs = await self.api_client.get_jobs(workflow.id)
300+
jobs = await self.api_client.get_workflow_jobs(workflow.id)
301301
self.cache_manager.set_workflow_jobs(workflow.id, workflow.status, jobs)
302302
return jobs
303303

tests/conftest.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,19 @@
55
from circle import api_types
66

77

8+
class FakeCache:
9+
def __init__(self):
10+
self.store: dict[str, object] = {}
11+
self.ttls: dict[str, int | None] = {}
12+
13+
def get(self, k: str):
14+
return self.store.get(k)
15+
16+
def set(self, k: str, v: object, ttl: int | None):
17+
self.store[k] = v
18+
self.ttls[k] = ttl
19+
20+
821
def _deep_merge(base: dict, overrides: dict) -> dict:
922
result = base.copy()
1023
for k, v in overrides.items():

0 commit comments

Comments
 (0)