- Python 3
- Git
- pip
eg, on Ubuntu:
sudo apt-get install git python3 python3-pip
Assume we have a user account at /home/username
/home/username
└── sites
└── PROJECT
├── database
├── source
├── static_files
└── virtualenv
-
Create directory structure in ~/sites
mkdir -p PROJECT/database mkdir -p PROJECT/source mkdir -p PROJECT/static_files mkdir -p PROJECT/virtualenv
-
Pull down source code into folder named source
git clone https://github.com/ProteinsWebTeam/interpro7-api.git PROJECT/source cd PROJECT/source
From now on all the command assume you are in the
PROJECT/source
directory. -
Start the virtual env in the assigned folder:
python -m venv virtualenv
-
Install requirements in the virtual environment
../virtualenv/bin/pip install -r requirements.txt
-
Install requirements for development
```bash ../virtualenv/bin/pip install -r dev_requirements.txt ```
-
Create a local configuration file in
config/interpro.local.yml
. In this file you can overwite any of the settings included in the read-only fileconfig/interpro.yml
. Below is an example of the local config that will run in debug mode using the test DB with SQLite, a local instance of elasticsearch without redis:use_test_db: false debug: true allowed_host: ["localhost", "127.0.0.1"] searcher_path: "https://localhost:9200" searcher_index: "test" searcher_user: "elastic" searcher_password: "password" api_url: "http://localhost:8007/api/" static_url: "api/static_files/" searcher_test_path: "https://localhost:9200" searcher_test_password: "password"
- This configuration assumes a running instance of elasticsearch in port 9200. For details on how to install elasticsearch go HERE
-
Migrate the database models (For SQLite)
../virtualenv/bin/python manage.py migrate
If anything goes wrong check that the database directory exists
ls ../database
-
Collect the static files. Only necessary for server deployment.
../virtualenv/bin/python manage.py collectstatic --noinput
-
Load the fixture data into the SQLite DB.
../virtualenv/bin/python manage.py loaddata webfront/tests/fixtures_*.json
-
Install Elasticsearch and load index. Currently running version 8.12 with authentication by password
e.g for OSX: brew install elasticsearch@8.12
curl -XPUT 'localhost:9200/test?pretty' -H 'Content-Type: application/json' -d @config/elastic_mapping.json
-
Run the tests. When running the tests, the API loads the fixtures in the existing elasticsearch instance, which is necessary to run the server with fixtures.
../virtualenv/bin/python manage.py test
-
Start the server
../virtualenv/bin/python manage.py runserver 0.0.0.0:8000
-
[Optional] Install precommit, black and the pre-commit hook, to enable the formatting of files before each commit.
../virtualenv/bin/pip install pre-commit black ../virtualenv/bin/pre-commit install
Note 1:It is important to run the test in Python 3.8 because the VMs where the API runs use that version.
The unit tests are located in [project]/source/webfront/tests/
.
To run unit tests use
../virtualenv/bin/python manage.py test webfront
The functional test are in [project]/functional_tests
and are configured to Google Chrome (or Chromium), so you need to have it installed in your machine.
To run functional tests use
export BROWSER_TEST="chrome"
# Only required if ChromeDriver is not in your PATH
# or if its binary is not `chromedriver` (e.g. `chromium.chromedriver`)
export BROWSER_TEST_PATH="/path/to/chromedriver"
../virtualenv/bin/python manage.py test functional_tests
As a reference HERE is a graphic describing the fixtures.
All the test can be run at the same time:
../virtualenv/bin/python manage.py test
For the next steps you need an installation of MySQL with a database compatible with the defined model.
-
Remove the line
use_test_db: true
from theconfig/interpro.local.yml
file. You could also set the value to false, but given that false is the default value, you can just remove it. -
Edit the same
config/interpro.local.yml
file, changing thesearcher_path
setting for one with the elastic search instance that corresponds with the data in MySQL. -
Copy the template mysql configuration file into
config/mysql.yml
and edit the file with your data.cp config/mysql.template.yml config/mysql.yml
-
Start the server
../virtualenv/bin/python manage.py runserver 0.0.0.0:8000