Skip to content

Commit

Permalink
removes django web server side; rewrites as react client-only app now…
Browse files Browse the repository at this point in the history
… the deciphon/rest exists (#3)
  • Loading branch information
SandyRogers authored Jan 21, 2022
1 parent 1906685 commit 95228b3
Show file tree
Hide file tree
Showing 66 changed files with 28,110 additions and 1,865 deletions.
8 changes: 0 additions & 8 deletions .coveragerc

This file was deleted.

26 changes: 8 additions & 18 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,11 @@ jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: '3.9'
- uses: nanasess/setup-chromedriver@master
- name: install dependencies
run: pip install -r requirements.txt
- name: testing
run: pytest
- name: upload coverage
uses: actions/upload-artifact@v2
with:
name: pytest-coverage
path: test-results
- name: upload coverage to Codecov
uses: codecov/codecov-action@v2
with:
files: ./test-results/coverage.xml
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: '14'
- run: npm install
- run: npm test -- --coverage
- name: upload coverage to Codecov
uses: codecov/codecov-action@v2
30 changes: 24 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,25 @@
.idea/
databases/
downloads/
static_files/
test-results/
.pytest_cache/
.coverage

.coverage

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# production
/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
public
1 change: 1 addition & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
98 changes: 21 additions & 77 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,97 +2,41 @@
[![codecov](https://codecov.io/gh/EBI-Metagenomics/deciphon_web/branch/master/graph/badge.svg?token=X15S9LH10H)](https://codecov.io/gh/EBI-Metagenomics/deciphon_web)

# Deciphon Web
The web server and client for submitting queries to [Deciphon](https://github.com/EBI-Metagenomics/deciphon).

# Architecture
This is a Django app.
Deciphon interacts with an sqlite3 database to pull in job, run their queries, and store results.
Deciphon Web wraps this database in [unmanaged Django Models](https://docs.djangoproject.com/en/3.2/ref/models/options/#django.db.models.Options.managed).
It uses Django templates to present a web interface to submit jobs (consisting of queries), and poll for the results.
We use [Django-Unicorn](https://www.django-unicorn.com) to handle frontend/backend model tying,
and to do simple partial upsets of the page when polling for job completion.

## Databases
### `default`
A standard Django database in sqlite3.
This is used for boilerplate Django things like app tables and admin users.
The web client for submitting queries to [Deciphon](https://github.com/EBI-Metagenomics/deciphon) and viewing results.

### `deciphon`
The sqlite3 database managed by deciphon itself.
A [Django DB Router](https://docs.djangoproject.com/en/3.2/topics/db/multi-db/#multiple-databases) makes sure that any `deciphon.models` model read/writes from this database rather than `default`.
# Architecture

**Note** when unit testing, a single database is used so that transactional tests can be used.
This is a React app.
Deciphon Web interacts with Deciphon via [Deciphon's REST client](https://github.com/EBI-Metagenomics/deciphon/tree/main/rest).

# Development
## The basics
- Check out the repository.
- Create and activate a virtualenv or conda env for the project.
- `pip install -r requirements.txt`
- `export DJANGO_SECRET_KEY=<anythingyoulike>`
- `export DECIPHON_WEB_CONFIG=configs/local.yaml`
- `python manage.py migrate`
- `python manage.py collectstatic --noinput`
- `python manage.py runserver 8000`

You can create a new `config.yaml` or modify `configs/local.yaml` to point at different sqlite db files.
E.g. set `django_db_location: /path/to/wherever/deciphon/is/running/deciphon.db`

## The basics

## Admin interface
The app has Django Admin installed, so you can browse the database models.
- `python manage.py createsuperuser`
- [log in to the admin console](http://127.0.0.1:8000/admin)
- Check out the repository.
- Install `npm` if you haven't got it. e.g. `brew install node`
- You will need either Deciphon running, to use its REST API, or mock the API using e.g. [Postman](https://www.postman.com).
- Check the config in `./config/config.json` to set the API URL.
- `npm install` to install the dependencies.

## Style
Use [Black](https://black.rtfd.io) to format code before committing.

E.g. `black .` in the repository’s base directory.
Use [Prettier](https://prettier.io) to format code before committing.

E.g. `npx prettier --write .` in the repository’s base directory.

# Testing
`pytest` will run the test suite.

### Selenium integrtation test
`pytest` runs unit tests, as well as a [Selenium](https://pypi.org/project/selenium/) based test of the UI using a browser.
For this test to not fail, you need Chrome and the [Chromedriver](https://chromedriver.chromium.org) installed.
E.g. on a Mac use Homebrew
`brew install --cask chromedriver`
(MacOS will probably complain about launching an unsigned app the first time...
`open /usr/local/Caskroom/chromedriver` to find the chromedriver executable in Finder and then open it once from there to accept the warning.)
TODO
`npm test`

# Use
## Web interface
Browse to [the web interface](http://127.0.0.1:8000).

## Rest API
POST an API request, e.g.
```shell
curl --location --request POST '127.0.0.1:8000/rest/jobs' \
--header 'Content-Type: application/json' \
--data-raw '{
"job": {
"target_db": {"name": "pfam"},
"queries": [
{
"name": "mywonderfulquery",
"data": "ACGTACGT"
}
]
}
}'
```
JSON will be returned, including an `ID` (which is a UUID so that Jobs cannot be enumerated).

Poll the Job detail endpoint to find the current status:
```shell
curl --location --request GET '127.0.0.1:8000/rest/jobs/<some-uuid-returned-by-job-submission>'
```

The response will include `job.state`, which will be `pend` until it is `done` or `fail`.
It also includes a `result_urls` object.

To find the IDs/names of possible target DBs, list:
```shell
curl --location --request GET '127.0.0.1:8000/rest/dbs'
```

`npm start`

Browse to [the web interface](http://127.0.0.1:3000).

# Deployment

`npm run build`
4 changes: 0 additions & 4 deletions configs/local.yaml

This file was deleted.

Empty file removed deciphon/__init__.py
Empty file.
41 changes: 0 additions & 41 deletions deciphon/admin.py

This file was deleted.

6 changes: 0 additions & 6 deletions deciphon/apps.py

This file was deleted.

85 changes: 0 additions & 85 deletions deciphon/migrations/0001_initial.py

This file was deleted.

Empty file removed deciphon/migrations/__init__.py
Empty file.
Loading

0 comments on commit 95228b3

Please sign in to comment.