mirror of
https://github.com/shouptech/humulus.git
synced 2026-02-03 15:59:43 +00:00
66 lines
1.9 KiB
Python
66 lines
1.9 KiB
Python
# Copyright 2019 Mike Shoup
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
# you may not use this file except in compliance with the License.
|
|
# You may obtain a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
# See the License for the specific language governing permissions and
|
|
# limitations under the License.
|
|
|
|
import uuid
|
|
|
|
from humulus.couch import get_doc, put_doc, update_doc
|
|
|
|
|
|
def test_put_doc(app):
|
|
with app.app_context():
|
|
data = {'foo': 'bar'}
|
|
response = put_doc(data)
|
|
assert '_id' in response
|
|
assert 'created' in response
|
|
|
|
response = put_doc({'name': 'test'})
|
|
assert response['_id'] == 'test'
|
|
|
|
response = put_doc({'name': 'test'})
|
|
assert response['_id'] == 'test-1'
|
|
|
|
response = put_doc({'name': 'test'})
|
|
assert response['_id'] == 'test-2'
|
|
|
|
|
|
def test_update_doc(app):
|
|
with app.app_context():
|
|
doc = get_doc('awesome-lager')
|
|
rev = doc['_rev']
|
|
doc['test'] = 'update'
|
|
update_doc(doc)
|
|
|
|
updated_doc = get_doc('awesome-lager')
|
|
assert doc['_id'] == updated_doc['_id']
|
|
assert rev < updated_doc['_rev']
|
|
assert updated_doc['test'] == 'update'
|
|
assert 'updated' in updated_doc
|
|
|
|
|
|
def test_build_couch_command(runner, monkeypatch):
|
|
class Recorder(object):
|
|
called = False
|
|
|
|
def fake_build_couch():
|
|
Recorder.called = True
|
|
|
|
monkeypatch.setattr('humulus.couch.build_couch', fake_build_couch)
|
|
result = runner.invoke(args=['build-couch'])
|
|
assert 'Built a couch. Please have a seat.' in result.output
|
|
assert Recorder.called
|
|
|
|
|
|
def test_get_doc(app):
|
|
with app.app_context():
|
|
assert get_doc('foobar')['data'] == 'test'
|