|
3 | 3 | from datetime import datetime, timezone
|
4 | 4 | from typing import Sequence
|
5 | 5 |
|
| 6 | +from decoy import Decoy |
6 | 7 | import pytest
|
7 | 8 | import sqlalchemy
|
8 | 9 |
|
|
32 | 33 | StoredLabwareOffsetLocationSequenceComponents,
|
33 | 34 | UnknownLabwareOffsetLocationSequenceComponent,
|
34 | 35 | )
|
| 36 | +from robot_server.service.notifications.publishers.labware_offsets_publisher import ( |
| 37 | + LabwareOffsetsPublisher, |
| 38 | +) |
| 39 | + |
| 40 | + |
| 41 | +@pytest.fixture |
| 42 | +def mock_labware_offsets_publisher(decoy: Decoy) -> LabwareOffsetsPublisher: |
| 43 | + """Return a mock in the shape of a LabwareOffsetsPublisher.""" |
| 44 | + return decoy.mock(cls=LabwareOffsetsPublisher) |
35 | 45 |
|
36 | 46 |
|
37 | 47 | @pytest.fixture
|
38 |
| -def subject(sql_engine: sqlalchemy.engine.Engine) -> LabwareOffsetStore: |
| 48 | +def subject( |
| 49 | + sql_engine: sqlalchemy.engine.Engine, |
| 50 | + mock_labware_offsets_publisher: LabwareOffsetsPublisher, |
| 51 | +) -> LabwareOffsetStore: |
39 | 52 | """Return a test subject."""
|
40 |
| - return LabwareOffsetStore(sql_engine) |
| 53 | + return LabwareOffsetStore(sql_engine, mock_labware_offsets_publisher) |
41 | 54 |
|
42 | 55 |
|
43 | 56 | def test_empty_search(subject: LabwareOffsetStore) -> None:
|
@@ -260,7 +273,7 @@ def test_filter_fields(
|
260 | 273 | )
|
261 | 274 | ]
|
262 | 275 | )
|
263 |
| - assert sorted(results, key=lambda o: o.id,) == sorted( |
| 276 | + assert sorted(results, key=lambda o: o.id) == sorted( |
264 | 277 | [
|
265 | 278 | StoredLabwareOffset(
|
266 | 279 | id=offsets[id_].id,
|
@@ -473,3 +486,26 @@ def test_handle_unknown(
|
473 | 486 | )
|
474 | 487 | )
|
475 | 488 | assert subject.search([SearchFilter(id="id-a")]) == [outgoing_offset]
|
| 489 | + |
| 490 | + |
| 491 | +def test_notifications( |
| 492 | + subject: LabwareOffsetStore, |
| 493 | + decoy: Decoy, |
| 494 | + mock_labware_offsets_publisher: LabwareOffsetsPublisher, |
| 495 | +) -> None: |
| 496 | + """It should publish notifications any time the set of labware offsets changes.""" |
| 497 | + decoy.verify(mock_labware_offsets_publisher.publish_labware_offsets(), times=0) |
| 498 | + subject.add( |
| 499 | + IncomingStoredLabwareOffset( |
| 500 | + id="id", |
| 501 | + createdAt=datetime.now(timezone.utc), |
| 502 | + definitionUri="definitionUri", |
| 503 | + locationSequence=ANY_LOCATION, |
| 504 | + vector=LabwareOffsetVector(x=1, y=2, z=3), |
| 505 | + ) |
| 506 | + ) |
| 507 | + decoy.verify(mock_labware_offsets_publisher.publish_labware_offsets(), times=1) |
| 508 | + subject.delete("id") |
| 509 | + decoy.verify(mock_labware_offsets_publisher.publish_labware_offsets(), times=2) |
| 510 | + subject.delete_all() |
| 511 | + decoy.verify(mock_labware_offsets_publisher.publish_labware_offsets(), times=3) |
0 commit comments