-
Notifications
You must be signed in to change notification settings - Fork 6
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
Fs insert one new #166
Open
sl5035
wants to merge
16
commits into
Billingegroup:client
Choose a base branch
from
sl5035:fs_insert_one_new
base: client
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Fs insert one new #166
Changes from 14 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
93d02c9
init for new fs_insert_one
sl5035 7929b81
insert_one test function passes
sl5035 1123853
bug fix for test_open and test_close
sl5035 1a01b94
output false
sl5035 6f3f475
global rc
sl5035 0766efa
test_insert_one now passes with invalid case
sl5035 068a03a
runcontrol test bug fix
sl5035 142e7c4
test insert one now passes with bad test case
sl5035 0f305dd
test insert one split into two
sl5035 4acd773
return error info back to the client
sl5035 3a97060
test_insert_one_bad with return info
sl5035 d43a7dc
first draft
sl5035 72b4dea
second draft
sl5035 96b7659
third draft
sl5035 ffd5961
fsclient logic implemented
sl5035 f8569b6
test connect_db skip
sl5035 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
**Added:** | ||
|
||
* function for inserting one document to the filesystem database | ||
|
||
**Changed:** | ||
|
||
* <news item> | ||
|
||
**Deprecated:** | ||
|
||
* <news item> | ||
|
||
**Removed:** | ||
|
||
* <news item> | ||
|
||
**Fixed:** | ||
|
||
* <news item> | ||
|
||
**Security:** | ||
|
||
* <news item> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
pydr_rc = { | ||
"groupname": "Billinge Group", | ||
"databases": [ | ||
{ | ||
"name": "local", | ||
"url": ".", | ||
"public": False, | ||
"path": "db", | ||
"local": True | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,15 @@ | ||
from collections import defaultdict | ||
from pathlib import Path | ||
from testfixtures import TempDirectory | ||
|
||
import pytest | ||
import os | ||
import json | ||
|
||
from pydatarecognition.fsclient import FileSystemClient | ||
from pydatarecognition.runcontrol import connect_db | ||
from tests.inputs.pydr_rc import pydr_rc | ||
from tests.inputs.exemplars import EXEMPLARS | ||
|
||
# | ||
# def test_dump_json(): | ||
|
@@ -18,48 +25,40 @@ | |
# actual = f.read() | ||
# assert actual == json_doc | ||
|
||
# todo: | ||
# build a runcontrol object as in regolith. have it created globally in the | ||
# tests for reuse in all the tests (look for DEFAULT_RC in regoith tests) | ||
# for now: | ||
# DEFAULT_RC = RunControl( | ||
# _validators=DEFAULT_VALIDATORS, | ||
# builddir="_build", | ||
# mongodbpath=property(lambda self: os.path.join(self.builddir, "_dbpath")), | ||
# user_config=os.path.expanduser("~/.config/regolith/user.json"), | ||
# force=False, | ||
# database=None | ||
# ) | ||
DEFAULT_RC = {} | ||
rc = DEFAULT_RC | ||
|
||
|
||
# FileSystemClient methods tested here | ||
def test_is_alive(): | ||
def test_is_alive(rc): | ||
expected = True # filesystem is always alive! | ||
fsc = FileSystemClient(rc) | ||
actual = fsc.is_alive() | ||
|
||
assert actual == expected | ||
|
||
|
||
def test_open(): | ||
def test_open(rc): | ||
fsc = FileSystemClient(rc) | ||
fsc.open() | ||
|
||
# assert fsc.dbs == rc.databases | ||
actual = fsc.dbs | ||
expected = connect_db(rc)[1] | ||
assert actual == expected | ||
|
||
assert isinstance(fsc.dbs, type(defaultdict(lambda: defaultdict(dict)))) | ||
assert isinstance(fsc.chained_db, type(dict())) | ||
assert not fsc.closed | ||
|
||
|
||
def test_close(): | ||
def test_close(rc): | ||
fsc = FileSystemClient(rc) | ||
assert fsc.open | ||
# assert fsc.dbs == rc.databases | ||
|
||
actual = fsc.dbs | ||
expected = connect_db(rc)[1] | ||
assert actual == expected | ||
|
||
assert isinstance(fsc.dbs, type(defaultdict(lambda: defaultdict(dict)))) | ||
|
||
actual = fsc.close() | ||
fsc.close() | ||
assert fsc.dbs is None | ||
assert fsc.closed | ||
|
||
|
@@ -119,9 +118,45 @@ def test_all_documents(): | |
pass | ||
|
||
|
||
@pytest.mark.skip("Not written") | ||
def test_insert_one(): | ||
pass | ||
test_insert_json = [({'intensity': [], 'q': [], 'ttheta': [], 'wavelength': 0.111111, '_id': 'ts1129'}, | ||
{'intensity': [], 'q': [], 'ttheta': [], 'wavelength': 0.111111, '_id': 'ts1129'})] | ||
@pytest.mark.parametrize('input, result', test_insert_json) | ||
def test_insert_one(rc, input, result): | ||
client = FileSystemClient(rc) | ||
client.open() | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the code below seems to be testing connect_db, which should be tested in |
||
collname = 'calculated' | ||
|
||
path = pydr_rc['databases'][0]['url'] + f'/db/{collname}.json' | ||
|
||
len_bef = 0 | ||
len_after = 0 | ||
|
||
with open(path, 'r+') as file: | ||
len_bef = len(json.load(file)) | ||
|
||
client.insert_one(path, input) | ||
|
||
with open(path, 'r+') as file: | ||
len_after = len(json.load(file)) | ||
|
||
assert len_after == len_bef + 1 | ||
|
||
|
||
test_insert_json_bad = [{'bad_case_test_dict': 'bad'}, 'bad_case_test_str'] | ||
def test_insert_one_bad(rc): | ||
client = FileSystemClient(rc) | ||
client.open() | ||
|
||
collname = 'calculated' | ||
|
||
path = pydr_rc['databases'][0]['url'] + f'/db/{collname}.json' | ||
|
||
with pytest.raises(KeyError, match=r"Bad value in database entry key bad_entry_key"): | ||
client.insert_one(path, test_insert_json_bad[0]) | ||
|
||
with pytest.raises(TypeError, match=r"Wrong document format bad_doc_format"): | ||
client.insert_one(path, test_insert_json_bad[1]) | ||
|
||
|
||
@pytest.mark.skip("Not written") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we know why this takes
filename
and doesn't take dbname and collname? Doesn't htis break the api, because theinsert_one
will have a different signature for the different clients (mongo vs fs).I may be wrong here, so let me know if so, but I htink the idea is that
insert_one
has the same signature regardless of the client, but it has different behavior depending on the backend. In general, we want to insert something into a particular collection in a particular database. If that collection is in a mongo db the client will need a URL and login credentials and so on of the db, if it is in a file on a filesystem it will need to know the file-name and where in the directory structure it is located, but this is handled by therc.databases
at runtime.