diff options
Diffstat (limited to 'tests/test_json.py')
-rw-r--r-- | tests/test_json.py | 33 |
1 files changed, 30 insertions, 3 deletions
diff --git a/tests/test_json.py b/tests/test_json.py index 74b00ea..9faf0ae 100644 --- a/tests/test_json.py +++ b/tests/test_json.py @@ -1396,11 +1396,38 @@ def test_custom_decoder(client): @pytest.mark.redismod def test_set_file(client): - import tempfile import json + import tempfile + obj = {"hello": "world"} jsonfile = tempfile.NamedTemporaryFile(suffix=".json") - with open(jsonfile.name, 'w+') as fp: + with open(jsonfile.name, "w+") as fp: + fp.write(json.dumps(obj)) + + nojsonfile = tempfile.NamedTemporaryFile() + nojsonfile.write(b"Hello World") + + assert client.json().set_file("test", Path.rootPath(), jsonfile.name) + assert client.json().get("test") == obj + with pytest.raises(json.JSONDecodeError): + client.json().set_file("test2", Path.rootPath(), nojsonfile.name) + + +@pytest.mark.redismod +def test_set_path(client): + import json + import os + import tempfile + + root = tempfile.mkdtemp() + sub = tempfile.mkdtemp(dir=root) + ospointer, jsonfile = tempfile.mkstemp(suffix=".json", dir=sub) + ospointer2, nojsonfile = tempfile.mkstemp(dir=root) + + with open(jsonfile, "w+") as fp: fp.write(json.dumps({"hello": "world"})) + open(nojsonfile, "a+").write("hello") - assert client.json().set("test", Path.rootPath(), jsonfile.name)
\ No newline at end of file + result = {"/private" + jsonfile: True, "/private" + nojsonfile: False} + assert client.json().set_path(Path.rootPath(), os.path.realpath(root)) == result + assert client.json().get("/private" + jsonfile.rsplit(".")[0]) == {"hello": "world"} |