mirror of
https://github.com/shouptech/humulus.git
synced 2026-02-03 17:09:44 +00:00
Add ability to put a document from a file
This commit is contained in:
parent
17bf2ff722
commit
cc4ed2bef9
3 changed files with 25 additions and 1 deletions
|
|
@ -15,6 +15,7 @@
|
|||
# limitations under the License.
|
||||
|
||||
from datetime import datetime
|
||||
import json
|
||||
import uuid
|
||||
|
||||
import click
|
||||
|
|
@ -118,3 +119,13 @@ def get_doc_or_404(id):
|
|||
except KeyError:
|
||||
abort(404)
|
||||
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
|
||||
|
|
|
|||
4
tests/assets/test_doc.json
Normal file
4
tests/assets/test_doc.json
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"_id": "testfile",
|
||||
"foo": "bar"
|
||||
}
|
||||
|
|
@ -12,9 +12,10 @@
|
|||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import pathlib
|
||||
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):
|
||||
|
|
@ -64,3 +65,11 @@ def test_build_couch_command(runner, monkeypatch):
|
|||
def test_get_doc(app):
|
||||
with app.app_context():
|
||||
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'
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue