Merge pull request #55 from eReuse/feature/54-show-version-via-api
Show version via API
This commit is contained in:
commit
bfb67b92dd
|
@ -0,0 +1 @@
|
|||
__version__ = "1.0a1"
|
|
@ -12,6 +12,7 @@ from ereuse_devicehub.resources import action, agent, deliverynote, inventory, \
|
|||
from ereuse_devicehub.resources.device import definitions
|
||||
from ereuse_devicehub.resources.documents import documents
|
||||
from ereuse_devicehub.resources.enums import PriceSoftware
|
||||
from ereuse_devicehub.resources.versions import versions
|
||||
|
||||
|
||||
class DevicehubConfig(Config):
|
||||
|
@ -24,7 +25,8 @@ class DevicehubConfig(Config):
|
|||
import_resource(deliverynote),
|
||||
import_resource(proof),
|
||||
import_resource(documents),
|
||||
import_resource(inventory)),
|
||||
import_resource(inventory),
|
||||
import_resource(versions)),
|
||||
)
|
||||
PASSWORD_SCHEMES = {'pbkdf2_sha256'} # type: Set[str]
|
||||
SQLALCHEMY_DATABASE_URI = 'postgresql://dhub:ereuse@localhost/devicehub' # type: str
|
||||
|
|
|
@ -0,0 +1,64 @@
|
|||
import flask
|
||||
import json
|
||||
import requests
|
||||
import teal.marshmallow
|
||||
|
||||
from typing import Callable, Iterable, Tuple
|
||||
from urllib.parse import urlparse
|
||||
from flask import make_response, g
|
||||
from teal.resource import Resource, View
|
||||
|
||||
from ereuse_devicehub.resources.inventory.model import Inventory
|
||||
from ereuse_devicehub import __version__
|
||||
|
||||
|
||||
def get_tag_version(app):
|
||||
"""Get version of microservice ereuse-tag."""
|
||||
|
||||
path = "/versions/version/"
|
||||
url = urlparse(Inventory.current.tag_provider.to_text())._replace(path=path)
|
||||
try:
|
||||
res = requests.get(url.geturl())
|
||||
except requests.exceptions.ConnectionError:
|
||||
app.logger.error("The microservice Tags is down!!")
|
||||
return {}
|
||||
|
||||
if res.status_code == 200:
|
||||
return json.loads(res.content)
|
||||
else:
|
||||
return {}
|
||||
|
||||
class VersionView(View):
|
||||
def get(self, *args, **kwargs):
|
||||
"""Get version of DeviceHub and ereuse-tag."""
|
||||
|
||||
tag_version = get_tag_version(self.resource_def.app)
|
||||
versions = {'devicehub': __version__, "ereuse_tag": "0.0.0"}
|
||||
versions.update(tag_version)
|
||||
return json.dumps(versions)
|
||||
|
||||
|
||||
class VersionDef(Resource):
|
||||
__type__ = 'Version'
|
||||
SCHEMA = None
|
||||
VIEW = None # We do not want to create default / documents endpoint
|
||||
AUTH = False
|
||||
|
||||
def __init__(self, app,
|
||||
import_name=__name__,
|
||||
static_folder=None,
|
||||
static_url_path=None,
|
||||
template_folder=None,
|
||||
url_prefix=None,
|
||||
subdomain=None,
|
||||
url_defaults=None,
|
||||
root_path=None,
|
||||
cli_commands: Iterable[Tuple[Callable, str or None]] = tuple()):
|
||||
super().__init__(app, import_name, static_folder, static_url_path, template_folder,
|
||||
url_prefix, subdomain, url_defaults, root_path, cli_commands)
|
||||
|
||||
d = {'devicehub': __version__, "ereuse_tag": "0.0.0"}
|
||||
get = {'GET'}
|
||||
|
||||
version_view = VersionView.as_view('VersionView', definition=self)
|
||||
self.add_url_rule('/', defaults=d, view_func=version_view, methods=get)
|
7
setup.py
7
setup.py
|
@ -1,6 +1,7 @@
|
|||
from pathlib import Path
|
||||
|
||||
from setuptools import find_packages, setup
|
||||
from ereuse_devicehub import __version__
|
||||
|
||||
|
||||
test_requires = [
|
||||
'pytest',
|
||||
|
@ -9,10 +10,10 @@ test_requires = [
|
|||
|
||||
setup(
|
||||
name='ereuse-devicehub',
|
||||
version='1.0a1',
|
||||
version=__version__,
|
||||
url='https://github.com/ereuse/devicehub-teal',
|
||||
project_urls={
|
||||
'Documentation': 'http://devicheub.ereuse.org',
|
||||
'Documentation': 'http://devicehub.ereuse.org',
|
||||
'Code': 'http://github.com/ereuse/devicehub-teal',
|
||||
'Issue tracker': 'https://tree.taiga.io/project/ereuseorg-devicehub/issues?q=rules'
|
||||
},
|
||||
|
|
|
@ -99,7 +99,8 @@ def test_api_docs(client: Client):
|
|||
'/video-scalers/{id}/merge/',
|
||||
'/videoconferences/{id}/merge/',
|
||||
'/videos/{id}/merge/',
|
||||
'/wireless-access-points/{id}/merge/'
|
||||
'/wireless-access-points/{id}/merge/',
|
||||
'/versions/'
|
||||
}
|
||||
assert docs['info'] == {'title': 'Devicehub', 'version': '0.2'}
|
||||
assert docs['components']['securitySchemes']['bearerAuth'] == {
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
import datetime
|
||||
import pytest
|
||||
|
||||
from uuid import UUID
|
||||
from flask import g
|
||||
|
||||
import pytest
|
||||
from colour import Color
|
||||
from ereuse_utils.naming import Naming
|
||||
from ereuse_utils.test import ANY
|
||||
|
@ -11,6 +12,7 @@ from sqlalchemy.util import OrderedSet
|
|||
from teal.db import ResourceNotFound
|
||||
from teal.enums import Layouts
|
||||
|
||||
from ereuse_devicehub import __version__
|
||||
from ereuse_devicehub.client import Client, UserClient
|
||||
from ereuse_devicehub.db import db
|
||||
from ereuse_devicehub.devicehub import Devicehub
|
||||
|
@ -116,6 +118,16 @@ def test_users(user: UserClient, client: Client):
|
|||
assert res.status_code == 405
|
||||
|
||||
|
||||
@pytest.mark.mvp
|
||||
def test_get_version(app: Devicehub, client: Client):
|
||||
"""Checks GETting versions of services."""
|
||||
|
||||
content, res = client.get("/versions/", None)
|
||||
|
||||
version = {'devicehub': __version__, 'ereuse_tag': '0.0.0'}
|
||||
assert res.status_code == 200
|
||||
assert content == version
|
||||
|
||||
@pytest.mark.mvp
|
||||
def test_get_device(app: Devicehub, user: UserClient, user2: UserClient):
|
||||
"""Checks GETting a d.Desktop with its components."""
|
||||
|
|
Reference in New Issue