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

Add status endpoint

This commit is contained in:
Emma 2019-07-12 09:31:08 -06:00
parent 1057e86177
commit bf1577a0ce
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
# 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__)
@ -23,3 +25,13 @@ bp = Blueprint('home', __name__)
def index():
"""Renders the homepage template"""
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):
response = client.get('/')
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'}