Exemplo n.º 1
0
def test_update():
    bck = DictBackend()
    evt = Event(GenericEventType(), dict(foo='bar'))
    bck.create(evt)
    assert len(bck._db) == 1

    # updating nothing leads to an exception
    with pytest.raises(AssertionError):
        bck.update(None)
        pytest.fail()

    # updating events with null id is idempotent
    former_evt0_id = evt.id
    evt.id = None
    bck.update(evt)
    assert len(bck._db) == 1
    result = bck.read(former_evt0_id)
    assert result == evt  # event was unchanged
    assert result.owner is None

    # actual update
    evt.owner = 'me'
    bck.update(evt)
    assert len(bck._db) == 1
    result = bck.read(former_evt0_id)
    assert result.owner == 'me'
Exemplo n.º 2
0
def test_create():
    bck = DictBackend()
    assert len(bck._db) == 0

    # adding nothing leads to an exception
    with pytest.raises(AssertionError):
        bck.create(None)
        pytest.fail()

    # adding events with null id
    evt0 = Event(GenericEventType(), dict(foo='bar'))
    evt0.id = None
    bck.create(evt0)
    assert len(bck._db) == 0

    # fresh add
    evt1 = Event(GenericEventType(), dict(foo='bar'))
    bck.create(evt1)
    assert len(bck._db) == 1

    # adding twice the same event is idempotent
    bck.create(evt1)
    assert len(bck._db) == 1