コード例 #1
0
ファイル: test_spy_log.py プロジェクト: mcous/decoy
def test_consume_prop_rehearsal_raises_empty_error() -> None:
    """It should raise an error a valid rehearsal event isn't found."""
    subject = SpyLog()

    with pytest.raises(MissingRehearsalError):
        subject.consume_prop_rehearsal()

    event = SpyEvent(
        spy_id=42,
        spy_name="my_spy",
        payload=SpyPropAccess(prop_name="my_prop",
                              access_type=PropAccessType.GET),
    )
    subject.push(event)
    subject.consume_prop_rehearsal()

    with pytest.raises(MissingRehearsalError):
        subject.consume_prop_rehearsal()

    call = SpyEvent(
        spy_id=42,
        spy_name="my_spy",
        payload=SpyCall(args=(), kwargs={}),
    )
    subject.push(call)

    with pytest.raises(MissingRehearsalError):
        subject.consume_prop_rehearsal()

    event = SpyEvent(
        spy_id=42,
        spy_name="my_spy",
        payload=SpyPropAccess(prop_name="my_prop",
                              access_type=PropAccessType.DELETE),
    )
    subject.push(event)

    with pytest.raises(MissingRehearsalError):
        subject.consume_prop_rehearsal()
コード例 #2
0
ファイル: test_spy_log.py プロジェクト: mcous/decoy
def test_push_and_consume_prop_rehearsal_for_prop() -> None:
    """It should be able to push and consume a prop rehearsal for more rehearsals."""
    subject = SpyLog()
    event = SpyEvent(
        spy_id=42,
        spy_name="my_spy",
        payload=SpyPropAccess(prop_name="my_prop",
                              access_type=PropAccessType.GET),
    )

    subject.push(event)
    result = subject.consume_prop_rehearsal()
    assert isinstance(result, PropRehearsal)
    assert result == event
コード例 #3
0
def test_prop(
    decoy: Decoy,
    spy_log: SpyLog,
    subject: DecoyCore,
) -> None:
    """It should be able to create set and delete rehearsals."""
    rehearsal = PropRehearsal(
        spy_id=1,
        spy_name="my_spy",
        payload=SpyPropAccess(prop_name="my_prop",
                              access_type=PropAccessType.GET),
    )

    decoy.when(spy_log.consume_prop_rehearsal()).then_return(rehearsal)

    result = subject.prop("__rehearsal__")

    result.set("hello")

    expected_set_event = SpyEvent(
        spy_id=1,
        spy_name="my_spy",
        payload=SpyPropAccess(
            prop_name="my_prop",
            access_type=PropAccessType.SET,
            value="hello",
        ),
    )
    decoy.verify(spy_log.push(expected_set_event), times=1)

    result.delete()

    expected_delete_event = SpyEvent(
        spy_id=1,
        spy_name="my_spy",
        payload=SpyPropAccess(prop_name="my_prop",
                              access_type=PropAccessType.DELETE),
    )
    decoy.verify(spy_log.push(expected_delete_event), times=1)