Exemple #1
0
def test_client_with_montydb_uri(gettempdir):
    URI_SCHEME_PREFIX
    # Faltfile
    tmp_dir = os.path.join(gettempdir, "flatfile")
    uri = URI_SCHEME_PREFIX + tmp_dir

    set_storage(repository=uri, storage="flatfile")
    client = montydb.MontyClient(uri)

    assert client.address == tmp_dir

    # SQLite
    tmp_dir = os.path.join(gettempdir, "sqlite")
    uri = URI_SCHEME_PREFIX + tmp_dir

    set_storage(repository=uri, storage="sqlite")
    client = montydb.MontyClient(uri)

    assert client.address == tmp_dir

    # Memory
    uri = URI_SCHEME_PREFIX + MEMORY_REPOSITORY
    client = montydb.MontyClient(uri)

    assert client.address == MEMORY_REPOSITORY
Exemple #2
0
def monty_client(storage, tmp_monty_repo):
    if os.path.isdir(tmp_monty_repo):
        shutil.rmtree(tmp_monty_repo)

    if storage == "memory":
        return montydb.MontyClient(":memory:")
    elif storage == "sqlite":
        montydb.set_storage(tmp_monty_repo, storage)
    elif storage == "flatfile":
        montydb.set_storage(tmp_monty_repo, storage)
    else:
        pytest.fail("Unknown storage engine: {!r}".format(storage), False)

    client = montydb.MontyClient(tmp_monty_repo)
    # purge_all_db
    for db in client.database_names():
        client.drop_database(db)
    return client
Exemple #3
0
def test_no_duplicated_docs_in_next_session(monty_client):
    db_name = "test_client"
    col_name = "no_duplicated_docs"

    doc = {"pet": "cat", "name": ["mai-mai", "jo-jo"]}
    find = {"pet": "cat"}
    update = {"$push": {"name": "na-na"}}

    col_1 = monty_client[db_name][col_name]
    col_1.insert_one(doc)
    assert col_1.count_documents(find) == 1

    new_client = montydb.MontyClient(monty_client.address)
    col_2 = new_client[db_name][col_name]
    col_2.update_one(find, update)
    assert col_2.count_documents(find) == 1
Exemple #4
0
def monty_client(request, tmp_monty_repo, mongo_version, use_bson):
    if os.path.isdir(tmp_monty_repo):
        shutil.rmtree(tmp_monty_repo)

    mongo_ver = "%d.%d" % (mongo_version[0], mongo_version[1])

    if request.param == "memory":
        tmp_monty_repo = ":memory:"

    montydb.set_storage(tmp_monty_repo,
                        request.param,
                        mongo_version=mongo_ver,
                        use_bson=use_bson)

    client = montydb.MontyClient(tmp_monty_repo)
    # purge_all_db
    for db in client.list_database_names():
        client.drop_database(db)
    return client
Exemple #5
0
import montydb

client = montydb.MontyClient('cafe')

db = client.ingrediente

db.ingrediente.insert_one({'nome': 'café'}, {'$set': {'unidade_medida': 'kg'}})

for documento in db.ingrediente.find({'nome': 'café'}):
    print(documento)

print(documento['nome'])
Exemple #6
0
def test_client_ne(monty_client, gettempdir):
    other_client = montydb.MontyClient(gettempdir + "/other_address")
    assert monty_client != other_client
Exemple #7
0
def test_client_eq(monty_client):
    other_client = montydb.MontyClient(monty_client.address)
    assert monty_client == other_client
Exemple #8
0
def test_client_wtimeout_type_error(monty_client):
    with pytest.raises(TypeError):
        montydb.MontyClient(monty_client.address, wtimeout=0.5)
Exemple #9
0
def test_client_context(monty_client, gettempdir):
    with montydb.MontyClient(gettempdir + "/address"):
        pass
Exemple #10
0
def test_client_ne(monty_client, tmp_monty_repo):
    other_client = montydb.MontyClient(tmp_monty_repo + "/other_address")
    assert monty_client != other_client
Exemple #11
0
def test_client_context(monty_client, tmp_monty_repo):
    with montydb.MontyClient(tmp_monty_repo + "/address"):
        pass