A proof of concept of the Statistical Business Register User Interface using Flask.
Previous repository: https://github.com/ONSdigital/sbr-react-ui
1. Environment Setup
2. Running Instructions
3. Environment Variables
4. Testing
5. Dependencies
6. Troubleshooting
7. Contributing
8. License
Firstly, install Python 3:
brew install python
Create a virtual environment (from inside the cloned repository):
python3 -m venv venv
Activate the virtual environment:
source venv/bin/activate
Install dependencies from the requirements.txt
file:
pip install -r requirements.txt
Run the server in development mode, with hot-reloading:
FLASK_APP=run.py FLASK_DEBUG=1 ENVIRONMENT=DEV python3 -m flask run
Note: USE_FAKE_DATA=True
can be passed in to allow the application to run without sbr-api
. The test data is held here.
The user interface can be accessed on http://localhost:5000.
With the default ENVIRONMENT
(DEV
), login with admin/admin
Environment Variable | Default Value |
---|---|
ENVIRONMENT | DEV |
USE_FAKE_DATA | False |
LOG_LEVEL | INFO |
API_TIMEOUT | 2 (seconds) |
AUTH_TIMEOUT | 2 (seconds) |
AUTH_URL | http://localhost:3002/auth |
API_URL | http://localhost:9000 |
SECRET_KEY | change_me |
The server will not start unless you have set ENVIRONMENT
to one of DEV
/TEST
/PROD
.
In PROD
mode, the server will only start if you have set AUTH_URL
, API_URL
and SECRET_KEY
.
To run the pytest
tests, use the following command:
ENVIRONMENT=TEST pytest --ignore=tests/selenium
To run the Selenium tests, use the following command:
pytest tests/selenium/
For the Selenium user interface tests to work, you will need to do the following:
- Install Firefox
- Install the
geckodriver
used by Selenium:brew install geckodriver
- Run
sbr-ui
, making sure to pass inUSE_FAKE_DATA=True
If you want to run the Selenium tests in headless mode, pass in SELENIUM_HEADLESS=True
.
To generate test coverage using pytest-cov
, use the following command:
ENVIRONMENT=TEST pytest --cov-report html --cov=sbr_ui --ignore=tests/selenium
Coverage reports are saved to ./htmlcov
. Open ./htmlcov/index.html
in a browser to inspect the results.
If your updates to static files aren't registering, reset the cache (shift + press refresh in Chrome).
See CONTRIBUTING for details.
Copyright ยฉโ 2018, Office for National Statistics (https://www.ons.gov.uk)
Released under MIT license, see LICENSE for details.