Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

client_manager test function #156

Open
wants to merge 3 commits into
base: client
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions tests/test_client_manager.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import pytest
import os
from copy import deepcopy, copy

from pydatarecognition.database import connect
from pydatarecognition.runcontrol import DEFAULT_RC, load_rcfile


def test_collection_retrieval_python(make_mixed_db):
def all_docs_from_collection(client, collname, copy=True):
"""Yield all entries in all collections of a given name in a given
database. """
yield from client.all_documents(collname, copy=copy)

if make_mixed_db is False:
pytest.skip("Mongoclient failed to start")
else:
repo, fs_coll, mongo_coll = make_mixed_db
os.chdir(repo)
rc = copy(DEFAULT_RC)
rc._update(load_rcfile("pydr_rc.json"))
with connect(rc) as rc.client:
fs_test_dict = dict(list(all_docs_from_collection(rc.client, "abstracts"))[0])
mongo_test_dict = dict(list(all_docs_from_collection(rc.client, "assignments"))[0])
fs_expected_dict = deepcopy(EXEMPLARS[fs_coll])
mongo_expected_dict = deepcopy(EXEMPLARS[mongo_coll])
assert fs_test_dict == fs_expected_dict
assert mongo_test_dict == mongo_expected_dict