Exemplo n.º 1
0
def test_save_adds_id(database):
    """
    Ensure _id is added to an inserted document.
    """
    doc = dict(foo='bar')
    compat.save(database.test_coll, doc)
    assert '_id' in doc
Exemplo n.º 2
0
def test_save_replace_by_id(database):
    compat.save(database.test_coll, dict(foo='bar', _id=1))

    doc = dict(foo='baz', _id=1)
    compat.save(database.test_coll, doc)
    assert database.test_coll.count_documents({}) == 1
    assert database.test_coll.find_one() == doc
Exemplo n.º 3
0
def test_save_no_id_extant_docs(database):
    """
    When no id is supplied, a new document should be created.
    """
    doc = dict(foo='bar')
    compat.save(database.test_coll, dict(doc))
    assert database.test_coll.count_documents({}) == 1
    compat.save(database.test_coll, doc)
    assert database.test_coll.count_documents({}) == 2
Exemplo n.º 4
0
def test_save_new_with_id(database):
    doc = dict(foo='bar', _id=1)
    compat.save(database.test_coll, doc)
    assert database.test_coll.find_one() == doc
Exemplo n.º 5
0
def test_save_no_id(database):
    doc = dict(foo='bar')
    compat.save(database.test_coll, doc)
    assert database.test_coll.find_one()['foo'] == 'bar'