Merged in issue-34-add-git-info-to-status (pull request #18)
Issue 34 add git info to status Approved-by: Dorian Pula
This commit is contained in:
commit
a59e942c0f
|
@ -17,3 +17,4 @@ cover/
|
|||
.cache
|
||||
|
||||
.saucelabs
|
||||
**/git-info
|
||||
|
|
7
Makefile
7
Makefile
|
@ -4,12 +4,15 @@
|
|||
# Global values for Rookeries components
|
||||
DB_CONNECTION = "postgresql+psycopg2://admin:password@db:5432/rookeries"
|
||||
|
||||
build-git-tag:
|
||||
scripts/gen_git_info.sh
|
||||
|
||||
# Build the API image
|
||||
build-api:
|
||||
build-api: build-git-tag
|
||||
docker build --tag rookeries/api:build api
|
||||
|
||||
# Build the webapp image
|
||||
build-webapp:
|
||||
build-webapp: build-git-tag
|
||||
docker build --tag rookeries/webapp:build webapp
|
||||
|
||||
# Build all the images
|
||||
|
|
|
@ -2,10 +2,12 @@
|
|||
Changelog
|
||||
=========
|
||||
|
||||
* :feature:`30` Add support to create, modify and delete sites, menus and pages via API.
|
||||
|
||||
* :support:`34` Add git revision to the status endpoint to enable easier tracking.
|
||||
* :feature:`27` Add support to create, modify and delete users with different roles.
|
||||
* :support:`0` Develop the top-level concepts for Rookeries.
|
||||
* :support:`32` Upgrade API to use latest stable versions of Python 3.6.
|
||||
* :feature:`30` Add support to create, modify and delete sites, menus and pages via API.
|
||||
* :feature:`30` Link pages to individual sites.
|
||||
* :support:`0` Convert rote build infrastructure to use simpler Makefile and scripts setup.
|
||||
* :support:`28` Make invoke the main entry point for everything in the API server.
|
||||
|
|
|
@ -5,7 +5,9 @@ Core web application views.
|
|||
:license: AGPL v3+
|
||||
"""
|
||||
|
||||
import io
|
||||
import logging
|
||||
import os
|
||||
|
||||
import flask
|
||||
|
||||
|
@ -14,6 +16,17 @@ from rookeries.main import rookeries_app
|
|||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
GIT_REVISION_INFO_FILE = 'git-info'
|
||||
|
||||
|
||||
def get_git_revision():
|
||||
if not os.path.exists(GIT_REVISION_INFO_FILE):
|
||||
return 'UNKNOWN'
|
||||
|
||||
with io.open(GIT_REVISION_INFO_FILE) as git_info:
|
||||
revision_info = git_info.readlines()[0].strip()
|
||||
return revision_info or 'UNKNOWN'
|
||||
|
||||
|
||||
@rookeries_app.route('/status')
|
||||
def app_status():
|
||||
|
@ -21,6 +34,7 @@ def app_status():
|
|||
app_status_info = {
|
||||
'app': 'rookeries',
|
||||
'version': rookeries.__version__,
|
||||
'gitRevision': get_git_revision(),
|
||||
}
|
||||
|
||||
return flask.jsonify(app_status_info)
|
||||
|
|
|
@ -6,26 +6,21 @@ Unit tests for the app status view.
|
|||
"""
|
||||
|
||||
import http
|
||||
from unittest import mock
|
||||
|
||||
import pytest
|
||||
import requests
|
||||
|
||||
import rookeries
|
||||
from tests import utils
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def flask_test_app():
|
||||
return rookeries.make_rookeries_app().test_client()
|
||||
|
||||
|
||||
def test_app_status_view_returns_app_info_as_a_json(flask_test_app):
|
||||
def test_app_status_view_returns_app_info_as_a_json(api_base_uri):
|
||||
expected_info = {
|
||||
'app': 'rookeries',
|
||||
'version': rookeries.__version__,
|
||||
'gitRevision': mock.ANY,
|
||||
}
|
||||
|
||||
actual = flask_test_app.get('/status')
|
||||
actual = requests.get(f'{api_base_uri}/status')
|
||||
|
||||
assert actual.status_code == http.HTTPStatus.OK
|
||||
actual_json = utils.convert_response_into_json(actual)
|
||||
assert actual_json == expected_info
|
||||
assert actual.json() == expected_info
|
||||
|
|
|
@ -5,26 +5,11 @@ Utilities for testing.
|
|||
:license: AGPL v3+
|
||||
"""
|
||||
|
||||
import json
|
||||
|
||||
import sqlalchemy
|
||||
from werkzeug import security, wrappers
|
||||
from werkzeug import security
|
||||
from rookeries.users import models
|
||||
|
||||
|
||||
def convert_response_into_json(response: wrappers.Response) -> dict:
|
||||
"""
|
||||
Converts a Flask Response into a working dict.
|
||||
:param response: The response to convert.
|
||||
:return: A dictionary representing the JSON.
|
||||
"""
|
||||
content_type = response.content_type.lower()
|
||||
if content_type != "application/json":
|
||||
raise ValueError(f"Expected a JSON response. Got \"{content_type}\" instead.")
|
||||
json_text = response.get_data(as_text=True)
|
||||
return json.loads(json_text)
|
||||
|
||||
|
||||
def create_test_user(db_engine, username, password, role=models.UserRole.subscriber, full_name='Test User',
|
||||
email_address='test@test.rookeries.org'):
|
||||
"""
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
#!/bin/bash
|
||||
|
||||
GIT_INFO=$(git rev-parse --short HEAD)
|
||||
if [[ ! -z $(git diff --shortstat) ]]
|
||||
then
|
||||
GIT_INFO=${GIT_INFO}"-dirty"
|
||||
fi
|
||||
|
||||
echo "${GIT_INFO}" > api/rookeries/git-info
|
Loading…
Reference in New Issue