Fix inventory not nesting devices

This commit is contained in:
Xavier Bustamante Talavera 2018-07-17 20:57:29 +02:00
parent 6f3ea001fe
commit c12d304adb
5 changed files with 95 additions and 10 deletions

View File

@ -28,17 +28,9 @@ The requirements are:
Install Devicehub with *pip*: `pip3 install ereuse-devicehub -U --pre`. Install Devicehub with *pip*: `pip3 install ereuse-devicehub -U --pre`.
## Running ## Running
Create a python file with the following and call it `app.py`: Download, or copy the contents, of [this file](example/app.py), and
```python call the new file ``app.py``.
from ereuse_devicehub.devicehub import Devicehub
from ereuse_devicehub.config import DevicehubConfig
class MyConfig(DevicehubConfig):
ORGANIZATION_NAME = 'My org'
ORGANIZATION_TAX_ID = 'foo-bar'
app = Devicehub(MyConfig())
```
Create a PostgreSQL database called *devicehub*: Create a PostgreSQL database called *devicehub*:
```bash ```bash
@ -89,3 +81,14 @@ interactive).
Use postman as an example of how to use the API. Use postman as an example of how to use the API.
[![Run in Postman](https://run.pstmn.io/button.svg)](https://documenter.getpostman.com/view/254251/RWEnmFPs) [![Run in Postman](https://run.pstmn.io/button.svg)](https://documenter.getpostman.com/view/254251/RWEnmFPs)
## Testing
To run the tests you will need to:
1. `git clone` this project.
2. Create a database for testing. By default the database used is
`dh_test`. Execute to create it:
1. `postgres $ createdb dh_test`.
2. `postgres $ psql devicehub`.
3. `postgres $ GRANT ALL PRIVILEGES ON DATABASE dh_test TO dhub;`.
3. Execute at the root folder of the project ``python3 setup.py test``.

8
example/README.md Normal file
View File

@ -0,0 +1,8 @@
Example stuff
=============
Example configurations useful for Devicehub.
You can use [App.py](./app.py), [Apache.conf](./apache.conf),
and [wsgi.wsgi](./wsgi.wsgi) to configure Apache with Devicehub. Look
at each files to know what to configure.

30
example/apache.conf Normal file
View File

@ -0,0 +1,30 @@
# Apache configuration for a Devicehub
# It uses plain HTTP
# Change the following variables:
Define servername api.devicetag.io
# The domain used to access the server
Define appdir /path/to/app/dir
# The path where the app directory is. Apache must have access to this folder.
Define wsgipath ${appdir}/wsgi.wsgi
# The location of the .wsgi file
<VirtualHost *:80>
ServerName ${servername}
WSGIDaemonProcess "${servername}" threads=5 lang='en_US.UTF-8' locale='en_US.UTF-8'
WSGIScriptAlias / ${wsgipath}
# pass the required headers through to the application
WSGIPassAuthorization On
<Directory ${appdir}>
WSGIProcessGroup "${servername}"
WSGIApplicationGroup %{GLOBAL}
Require all granted
</Directory>
# mod_deflate
SetOutputFilter DEFLATE
SetEnvIfNoCase Request_URI "\.(?:gif|jpe?g|png|deb|exe|dmg)$" no-gzip
</VirtualHost>

View File

@ -1,6 +1,12 @@
from ereuse_devicehub.config import DevicehubConfig from ereuse_devicehub.config import DevicehubConfig
from ereuse_devicehub.devicehub import Devicehub from ereuse_devicehub.devicehub import Devicehub
"""
Example app with minimal configuration.
Use this as a starting point.
"""
class MyConfig(DevicehubConfig): class MyConfig(DevicehubConfig):
ORGANIZATION_NAME = 'My org' ORGANIZATION_NAME = 'My org'

38
example/wsgi.wsgi Normal file
View File

@ -0,0 +1,38 @@
"""
An exemplifying Apache python WSGI to a Devicehub app.
Based in http://flask.pocoo.org/docs/0.12/deploying/mod_wsgi/
You only need to modify ``app_dir`` and ``venv``.
"""
from pathlib import Path
import sys
app_dir = Path(__file__).parent
"""
The **directory** where app.py is located.
Change this accordingly.
"""
assert app_dir.is_dir(), 'app_dir must point to a directory: {}'.format(app_dir)
app_dir = str(app_dir.resolve())
venv = Path(__file__).parent.parent / 'venv' / 'bin' / 'activate_this.py'
"""
The location of the ``activate_this.py`` file of the virtualenv.
Change this accordingly.
"""
assert venv.is_file(), 'venv must point to a file: {}'.format(venv)
venv = str(venv.resolve())
# Load the virtualenv
# -------------------
_globals = dict(__file__=venv)
exec(open(venv).read(), _globals)
# Load the app
# ------------
sys.path.insert(0, str(app_dir))
# noinspection PyUnresolvedReferences
from app import app as application