Skip to content

Commit 503b8dd

Browse files
committed
Fix broken update test and fake service
Signed-off-by: Mathias L. Baumann <[email protected]>
1 parent 4790d7e commit 503b8dd

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/frequenz/client/dispatch/test/_service.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,15 @@ async def UpdateMicrogridDispatch(
123123
request: DispatchUpdateRequest,
124124
) -> Empty:
125125
"""Update a dispatch."""
126-
dispatch = next((d for d in self.dispatches if d.id == request.id), None)
126+
index = next(
127+
(i for i, d in enumerate(self.dispatches) if d.id == request.id),
128+
None,
129+
)
127130

128-
if dispatch is None:
131+
if index is None:
129132
return Empty()
130133

131-
pb_dispatch = dispatch.to_protobuf()
134+
pb_dispatch = self.dispatches[index].to_protobuf()
132135

133136
# Go through the paths in the update mask and update the dispatch
134137
for path in request.update_mask.paths:
@@ -174,6 +177,8 @@ async def UpdateMicrogridDispatch(
174177
dispatch = Dispatch.from_protobuf(pb_dispatch)
175178
dispatch.update_time = datetime.now(tz=timezone.utc)
176179

180+
self.dispatches[index] = dispatch
181+
177182
return Empty()
178183

179184
async def GetMicrogridDispatch(

tests/test_dispatch_client.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ async def test_update_dispatch() -> None:
8181
assert dispatch == sample
8282

8383
await client.update(dispatch.id, {"recurrence.interval": 4})
84+
assert client.dispatches[0].recurrence.interval == 4
8485

8586

8687
async def test_get_dispatch() -> None:

0 commit comments

Comments
 (0)