Skip to content
Snippets Groups Projects
Commit bbbc77d1 authored by Erik Reid's avatar Erik Reid
Browse files

return latch info in version response

parent e674e20b
No related branches found
No related tags found
No related merge requests found
import pkg_resources import pkg_resources
from flask import Blueprint, jsonify from flask import Blueprint, jsonify, current_app
from inventory_provider.routes import common from inventory_provider.routes import common
from inventory_provider.tasks.common import get_current_redis, get_latch
routes = Blueprint("inventory-data-default-routes", __name__) routes = Blueprint("inventory-data-default-routes", __name__)
...@@ -16,8 +17,11 @@ def after_request(resp): ...@@ -16,8 +17,11 @@ def after_request(resp):
@routes.route("/version", methods=['GET', 'POST']) @routes.route("/version", methods=['GET', 'POST'])
@common.require_accepts_json @common.require_accepts_json
def version(): def version():
config = current_app.config["INVENTORY_PROVIDER_CONFIG"]
return jsonify({ return jsonify({
'api': API_VERSION, 'api': API_VERSION,
'module': 'module':
pkg_resources.get_distribution('inventory_provider').version pkg_resources.get_distribution('inventory_provider').version,
'latch': get_latch(get_current_redis(config))
}) })
...@@ -79,7 +79,9 @@ class MockedRedis(object): ...@@ -79,7 +79,9 @@ class MockedRedis(object):
MockedRedis.db['db:latch'] = json.dumps({ MockedRedis.db['db:latch'] = json.dumps({
'current': 0, 'current': 0,
'next': 0, 'next': 0,
'this': 0 'this': 0,
'pending': False,
'failure': False
}) })
def set(self, name, value): def set(self, name, value):
...@@ -139,6 +141,15 @@ def flask_config_filename(): ...@@ -139,6 +141,15 @@ def flask_config_filename():
@pytest.fixture @pytest.fixture
def mocked_redis(mocker): def mocked_redis(mocker):
MockedRedis().db['db:latch'] = json.dumps({
'current': 0,
'next': 0,
'this': 0,
'pending': False,
'failure': False
})
mocker.patch( mocker.patch(
'inventory_provider.tasks.common.redis.StrictRedis', 'inventory_provider.tasks.common.redis.StrictRedis',
MockedRedis) MockedRedis)
......
...@@ -7,9 +7,26 @@ DEFAULT_REQUEST_HEADERS = { ...@@ -7,9 +7,26 @@ DEFAULT_REQUEST_HEADERS = {
} }
def test_version_request(client): def test_version_request(client, mocked_redis):
version_schema = { version_schema = {
"$schema": "http://json-schema.org/draft-07/schema#", "$schema": "http://json-schema.org/draft-07/schema#",
"definitions": {
"latch": {
"type": "object",
"properties": {
"current": {"type": "integer"},
"next": {"type": "integer"},
"this": {"type": "integer"},
"failure": {"type": "boolean"},
"pending": {"type": "boolean"},
},
"required": ["current", "next", "this", "pending", "failure"],
"additionalProperties": False
}
},
"type": "object", "type": "object",
"properties": { "properties": {
"api": { "api": {
...@@ -19,7 +36,8 @@ def test_version_request(client): ...@@ -19,7 +36,8 @@ def test_version_request(client):
"module": { "module": {
"type": "string", "type": "string",
"pattern": r'\d+\.\d+' "pattern": r'\d+\.\d+'
} },
"latch": {"$ref": "#/definitions/latch"}
}, },
"required": ["api", "module"], "required": ["api", "module"],
"additionalProperties": False "additionalProperties": False
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment