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

Add status endpoint (#36)

Closes #34
This commit is contained in:
Emma 2019-07-12 09:34:59 -06:00 committed by GitHub
parent 1057e86177
commit 966999e93f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 37 additions and 1 deletions

View file

@ -14,7 +14,9 @@
# 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.
from flask import Blueprint, redirect, url_for from flask import Blueprint, redirect, url_for, request, jsonify
from humulus.couch import get_db
bp = Blueprint('home', __name__) bp = Blueprint('home', __name__)
@ -23,3 +25,13 @@ bp = Blueprint('home', __name__)
def index(): def index():
"""Renders the homepage template""" """Renders the homepage template"""
return redirect(url_for('recipes.index')) return redirect(url_for('recipes.index'))
@bp.route('/status')
def status():
if request.args.get('couch', default=False):
if get_db().exists():
return jsonify({'ping': 'ok', 'couch': 'ok'}), 200
else:
return jsonify({'ping': 'ok', 'couch': 'not_exist'}), 500
return jsonify({'ping': 'ok'}), 200

View file

@ -16,3 +16,27 @@
def test_home(client): def test_home(client):
response = client.get('/') response = client.get('/')
assert response.status_code == 302 assert response.status_code == 302
def test_status(client, monkeypatch):
class MockDBTrue:
def exists(self):
return True
class MockDBFalse:
def exists(self):
return False
response = client.get('/status')
assert response.status_code == 200
assert response.get_json() == {'ping': 'ok'}
monkeypatch.setattr('humulus.home.get_db', MockDBTrue)
response = client.get('/status?couch=y')
assert response.status_code == 200
assert response.get_json() == {'ping': 'ok', 'couch': 'ok'}
monkeypatch.setattr('humulus.home.get_db', MockDBFalse)
response = client.get('/status?couch=y')
assert response.status_code == 500
assert response.get_json() == {'ping': 'ok', 'couch': 'not_exist'}