1
0
Fork 0
mirror of https://github.com/shouptech/humulus.git synced 2026-02-03 18:19:42 +00:00

Add ability to put a document from a file

This commit is contained in:
Emma 2019-06-27 16:24:10 -06:00
parent 46c4d98163
commit 9bd0ab1caa
3 changed files with 25 additions and 1 deletions

View file

@ -15,6 +15,7 @@
# limitations under the License. # limitations under the License.
from datetime import datetime from datetime import datetime
import json
import uuid import uuid
import click import click
@ -118,3 +119,13 @@ def get_doc_or_404(id):
except KeyError: except KeyError:
abort(404) abort(404)
return doc return doc
def put_doc_from_file(filename):
"""Loads filename and stores it in couch.
The file must be valid JSON.
"""
with open(filename, 'r') as doc:
response = put_doc(json.load(doc))
return response

View file

@ -0,0 +1,4 @@
{
"_id": "testfile",
"foo": "bar"
}

View file

@ -12,9 +12,10 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import pathlib
import uuid import uuid
from humulus.couch import get_doc, put_doc, update_doc from humulus.couch import get_doc, put_doc, update_doc, put_doc_from_file
def test_put_doc(app): def test_put_doc(app):
@ -64,3 +65,11 @@ def test_build_couch_command(runner, monkeypatch):
def test_get_doc(app): def test_get_doc(app):
with app.app_context(): with app.app_context():
assert get_doc('foobar')['data'] == 'test' assert get_doc('foobar')['data'] == 'test'
def test_put_doc_from_file(app):
here = pathlib.Path(__file__).parent
with app.app_context():
response = put_doc_from_file(here/'assets'/'test_doc.json')
assert response['_id'] == 'testfile'
assert response['foo'] == 'bar'