-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from builder555/master
fetch only specific keys from all data
- Loading branch information
Showing
3 changed files
with
82 additions
and
2 deletions.
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
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,63 @@ | ||
import json | ||
import pytest | ||
from pysondb.db import PysonDB | ||
from pysondb.errors import UnknownKeyError | ||
|
||
|
||
TEST_DATA = { | ||
'version': 2, | ||
'keys': ['age', 'name', 'toy'], | ||
'data': { | ||
'2352346': { | ||
'age': 4, | ||
'name': 'mathew_first', | ||
'toy': 'car', | ||
}, | ||
'1234567': { | ||
'age': 9, | ||
'name': 'new_user', | ||
'toy': 'ball', | ||
} | ||
} | ||
} | ||
|
||
|
||
def test_get_all_select_keys(tmpdir): | ||
f = tmpdir.join('test.json') | ||
f.write(json.dumps(TEST_DATA)) | ||
|
||
db = PysonDB(f.strpath) | ||
assert db.get_all_select_keys(['age']) == { | ||
'2352346': { | ||
'age': 4, | ||
}, | ||
'1234567': { | ||
'age': 9, | ||
} | ||
} | ||
assert db.get_all_select_keys(['name', 'toy']) == { | ||
'2352346': { | ||
'name': 'mathew_first', | ||
'toy': 'car', | ||
}, | ||
'1234567': { | ||
'name': 'new_user', | ||
'toy': 'ball', | ||
} | ||
} | ||
|
||
|
||
def test_get_all_select_keys_empty_file(tmpdir): | ||
f = tmpdir.join('test.json') | ||
f.write(json.dumps({'version': 2, 'keys': [], 'data': {}})) | ||
|
||
db = PysonDB(f.strpath) | ||
assert db.get_all_select_keys([]) == {} | ||
|
||
def test_get_all_select_keys_wrong_key(tmpdir): | ||
f = tmpdir.join('test.json') | ||
f.write(json.dumps(TEST_DATA)) | ||
|
||
db = PysonDB(f.strpath) | ||
with pytest.raises(UnknownKeyError): | ||
db.get_all_select_keys(['wrong_key']) |