resolve confict

This commit is contained in:
Cayo Puigdefabregas 2020-09-30 09:30:17 +02:00
commit cac9206dc9
12 changed files with 112 additions and 10 deletions

View File

@ -49,7 +49,7 @@ jobs:
pip install virtualenv pip install virtualenv
virtualenv env virtualenv env
source env/bin/activate source env/bin/activate
pip install flake8 pytest pip install flake8 pytest coverage
pip install -r requirements.txt pip install -r requirements.txt
- name: Prepare database - name: Prepare database
@ -67,5 +67,7 @@ jobs:
- name: Run Tests - name: Run Tests
run: | run: |
source env/bin/activate source env/bin/activate
pytest -m mvp --maxfail=5 tests/ coverage run --source='ereuse_devicehub' env/bin/pytest -m mvp --maxfail=5 tests/
coverage report --include='ereuse_devicehub/*'
coverage xml

3
.gitignore vendored
View File

@ -113,3 +113,6 @@ ENV/
.vscode/ .vscode/
.DS_Store .DS_Store
/app.py /app.py
# Environment
.env

View File

@ -37,6 +37,11 @@ Create a PostgreSQL database called *devicehub* by running
- In MacOS: ``bash examples/create-db.sh devicehub dhub``, and password - In MacOS: ``bash examples/create-db.sh devicehub dhub``, and password
``ereuse``. ``ereuse``.
Configure project using environment file (you can use provided example as quickstart):
.. code:: bash
$ cp examples/env.example .env
Using the `dh` tool for set up with one or multiple inventories. Using the `dh` tool for set up with one or multiple inventories.
Create the tables in the database by executing: Create the tables in the database by executing:

View File

@ -0,0 +1 @@
__version__ = "1.0a1"

View File

@ -1,6 +1,7 @@
from distutils.version import StrictVersion from distutils.version import StrictVersion
from itertools import chain from itertools import chain
from typing import Set from typing import Set
from decouple import config
from teal.auth import TokenAuth from teal.auth import TokenAuth
from teal.config import Config from teal.config import Config
@ -12,6 +13,7 @@ from ereuse_devicehub.resources import action, agent, deliverynote, inventory, \
from ereuse_devicehub.resources.device import definitions from ereuse_devicehub.resources.device import definitions
from ereuse_devicehub.resources.documents import documents from ereuse_devicehub.resources.documents import documents
from ereuse_devicehub.resources.enums import PriceSoftware from ereuse_devicehub.resources.enums import PriceSoftware
from ereuse_devicehub.resources.versions import versions
class DevicehubConfig(Config): class DevicehubConfig(Config):
@ -24,10 +26,20 @@ class DevicehubConfig(Config):
import_resource(deliverynote), import_resource(deliverynote),
import_resource(proof), import_resource(proof),
import_resource(documents), import_resource(documents),
import_resource(inventory)), import_resource(inventory),
import_resource(versions)),
) )
PASSWORD_SCHEMES = {'pbkdf2_sha256'} # type: Set[str] PASSWORD_SCHEMES = {'pbkdf2_sha256'} # type: Set[str]
SQLALCHEMY_DATABASE_URI = 'postgresql://dhub:ereuse@localhost/devicehub' # type: str DB_USER = config('DB_USER', 'dhub')
DB_PASSWORD = config('DB_PASSWORD', 'ereuse')
DB_HOST = config('DB_HOST', 'localhost')
DB_DATABASE = config('DB_DATABASE', 'devicehub')
SQLALCHEMY_DATABASE_URI = 'postgresql://{user}:{pw}@{host}/{db}'.format(
user=DB_USER,
pw=DB_PASSWORD,
host=DB_HOST,
db=DB_DATABASE,
) # type: str
MIN_WORKBENCH = StrictVersion('11.0a1') # type: StrictVersion MIN_WORKBENCH = StrictVersion('11.0a1') # type: StrictVersion
"""The minimum version of ereuse.org workbench that this devicehub """The minimum version of ereuse.org workbench that this devicehub
accepts. we recommend not changing this value. accepts. we recommend not changing this value.

View File

@ -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)

4
examples/env.example Normal file
View File

@ -0,0 +1,4 @@
DB_USER='dhub'
DB_PASSWORD='ereuse'
DB_HOST='localhost'
DB_DATABASE='devicehub'

View File

@ -34,3 +34,5 @@ weasyprint==44
psycopg2-binary==2.8.3 psycopg2-binary==2.8.3
sortedcontainers==2.1.0 sortedcontainers==2.1.0
tqdm==4.32.2 tqdm==4.32.2
python-decouple==3.3
python-dotenv==0.14.0

View File

@ -1,6 +1,7 @@
from pathlib import Path from pathlib import Path
from setuptools import find_packages, setup from setuptools import find_packages, setup
from ereuse_devicehub import __version__
test_requires = [ test_requires = [
'pytest', 'pytest',
@ -9,10 +10,10 @@ test_requires = [
setup( setup(
name='ereuse-devicehub', name='ereuse-devicehub',
version='1.0a1', version=__version__,
url='https://github.com/ereuse/devicehub-teal', url='https://github.com/ereuse/devicehub-teal',
project_urls={ project_urls={
'Documentation': 'http://devicheub.ereuse.org', 'Documentation': 'http://devicehub.ereuse.org',
'Code': 'http://github.com/ereuse/devicehub-teal', 'Code': 'http://github.com/ereuse/devicehub-teal',
'Issue tracker': 'https://tree.taiga.io/project/ereuseorg-devicehub/issues?q=rules' 'Issue tracker': 'https://tree.taiga.io/project/ereuseorg-devicehub/issues?q=rules'
}, },

View File

@ -99,7 +99,8 @@ def test_api_docs(client: Client):
'/video-scalers/{id}/merge/', '/video-scalers/{id}/merge/',
'/videoconferences/{id}/merge/', '/videoconferences/{id}/merge/',
'/videos/{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['info'] == {'title': 'Devicehub', 'version': '0.2'}
assert docs['components']['securitySchemes']['bearerAuth'] == { assert docs['components']['securitySchemes']['bearerAuth'] == {

View File

@ -1,8 +1,15 @@
import pytest import pytest
from ereuse_devicehub import __version__
from ereuse_devicehub.client import Client
@pytest.mark.mvp
def test_get_version(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