Ejemplo n.º 1
0
def test_non_nullable_fields_cannot_be_saved_with_null_values():
    instance = Example(pk=1)
    instance.defaulted_field = None
    session = Session({})
    session.add(instance)

    with pytest.raises(ValueError):
        session.flush()
Ejemplo n.º 2
0
def test_add_with_field():
    data = {}
    session = Session(data)
    ex1 = Example(pk=1, name="Paul")
    session.add(ex1)
    session.flush()

    assert data == {"examples/1": {"name": "Paul"}}
Ejemplo n.º 3
0
def test_add():
    data = {}
    session = Session(data)
    ex1 = Example(pk=1)
    session.add(ex1)
    session.flush()

    assert data == {"examples/1": {}}
Ejemplo n.º 4
0
def test_error_when_adding_instance_to_two_sessions():
    session1, session2 = Session({}), Session({})

    ex1 = Example(pk=1, name="Horse")

    session1.add(ex1)
    with pytest.raises(RuntimeError):
        session2.add(ex1)
Ejemplo n.º 5
0
def test_sessions_are_not_global():
    instance_session1 = Example(pk=1)
    session = Session({})
    session.add(instance_session1)
    session.flush()

    session2 = Session({})
    with pytest.raises(KeyError):
        instance_session2 = session2.get(Example, 1)
Ejemplo n.º 6
0
def test_add_then_remove_entity_has_no_effect():
    data = {}
    session = Session(data)

    ex1 = Example(pk=1, name="Horse")
    session.add(ex1)
    session.remove(ex1)
    session.flush()

    assert data == {}
Ejemplo n.º 7
0
def test_error_when_instantiating_with_duplicate_id():
    session = Session({})

    session.add(Example(pk=1))
    with pytest.raises(RuntimeError):
        session.add(Example(pk=1))