From c9639a5eb83f111ca1600da82f70ce844b91de0e Mon Sep 17 00:00:00 2001 From: Xavier Bustamante Talavera Date: Sun, 16 Sep 2018 13:53:07 +0200 Subject: [PATCH] Enhance installation --- README.md | 30 +++++++++--------------------- {example => examples}/README.md | 0 {example => examples}/apache.conf | 0 {example => examples}/app.py | 0 examples/create-db.sh | 8 ++++++++ {example => examples}/wsgi.wsgi | 0 setup.py | 1 - 7 files changed, 17 insertions(+), 22 deletions(-) rename {example => examples}/README.md (100%) rename {example => examples}/apache.conf (100%) rename {example => examples}/app.py (100%) create mode 100644 examples/create-db.sh rename {example => examples}/wsgi.wsgi (100%) diff --git a/README.md b/README.md index 7e7e0a87..b4293312 100644 --- a/README.md +++ b/README.md @@ -29,22 +29,14 @@ The requirements are: Install Devicehub with *pip*: `pip3 install ereuse-devicehub -U --pre`. ## Running -Download, or copy the contents, of [this file](example/app.py), and +Download, or copy the contents, of [this file](examples/app.py), and call the new file ``app.py``. -Create a PostgreSQL database called *devicehub*: - -```bash -sudo su - postgres # Change to Postgres main user -postgres $ createdb devicehub # Create main database -postgres $ psql devicehub # Access to the database -postgres $ CREATE USER dhub WITH PASSWORD 'ereuse'; # Create user devicehub uses to access db -postgres $ GRANT ALL PRIVILEGES ON DATABASE devicehub TO dhub; # Give access to the db -postgres $ CREATE EXTENSION pgcrypto SCHEMA public; # Enable pgcrypto -postgres $ CREATE EXTENSION ltree SCHEMA public; # Enable ltree -postgres $ \q -exit -``` +Create a PostgreSQL database called *devicehub* by running +[create-db](examples/create-db.sh): + +- In Debian 9: `sudo su - postgres; examples/create-db.sh devicehub` +- In MacOS: `examples/create-db.sh devicehub`. Create the tables in the database by executing in the same directory where `app.py` is: @@ -89,13 +81,9 @@ Use postman as an example of how to use the API. 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 dh_test`. - 3. `postgres $ GRANT ALL PRIVILEGES ON DATABASE dh_test TO dhub;`. - 4. `CREATE EXTENSION pgcrypto SCHEMA public;` - 5. `CREATE EXTENSION ltree SCHEMA public;` +2. Create a database for testing executing `create-db.sh` like + the normal installation but changing the first parameter + from `devicehub` to `dh_test`: `create-db.sh dh_test`. 3. Execute at the root folder of the project `python3 setup.py test`. ## Generating the docs diff --git a/example/README.md b/examples/README.md similarity index 100% rename from example/README.md rename to examples/README.md diff --git a/example/apache.conf b/examples/apache.conf similarity index 100% rename from example/apache.conf rename to examples/apache.conf diff --git a/example/app.py b/examples/app.py similarity index 100% rename from example/app.py rename to examples/app.py diff --git a/examples/create-db.sh b/examples/create-db.sh new file mode 100644 index 00000000..72fa38b1 --- /dev/null +++ b/examples/create-db.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env bash +# Creates a database, user, and extensions to use Devicehub + +createdb $1 # Create main database +psql -d $1 -c "CREATE USER dhub WITH PASSWORD 'ereuse';" # Create user devicehub uses to access db +psql -d $1 -c "GRANT ALL PRIVILEGES ON DATABASE devicehub TO dhub;" # Give access to the db +psql -d $1 -c "CREATE EXTENSION pgcrypto SCHEMA public;" # Enable pgcrypto +psql -d $1 -c "CREATE EXTENSION ltree SCHEMA public;" # Enable ltree diff --git a/example/wsgi.wsgi b/examples/wsgi.wsgi similarity index 100% rename from example/wsgi.wsgi rename to examples/wsgi.wsgi diff --git a/setup.py b/setup.py index de1b4ec9..7d429ae8 100644 --- a/setup.py +++ b/setup.py @@ -11,7 +11,6 @@ with open('ereuse_devicehub/__init__.py', 'rt', encoding='utf8') as f: test_requires = [ 'pytest', - 'pytest-datadir', 'requests_mock' ]