Best Flask open-source libraries and packages

Sbr ui

A user interface for the Statistical Business Register using Flask
Updated 5 years ago

sbr-ui

phase license

A proof of concept of the Statistical Business Register User Interface using Flask.

Previous repository: https://github.com/ONSdigital/sbr-react-ui

Table of Contents

1. Environment Setup
2. Running Instructions
3. Environment Variables
4. Testing
5. Dependencies
6. Troubleshooting
7. Contributing
8. License

Environment Setup

Firstly, install Python 3:

brew install python

Create a virtual environment (from inside the cloned repository):

python3 -m venv venv

Running Instructions

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 Variables

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.

Testing

Server Tests

To run the pytest tests, use the following command:

ENVIRONMENT=TEST pytest --ignore=tests/selenium

User Interface Selenium Tests

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 in USE_FAKE_DATA=True

If you want to run the Selenium tests in headless mode, pass in SELENIUM_HEADLESS=True.

Test Coverage

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.

Dependencies

Troubleshooting

If your updates to static files aren't registering, reset the cache (shift + press refresh in Chrome).

Contributing

See CONTRIBUTING for details.

License

Copyright ©‎ 2018, Office for National Statistics (https://www.ons.gov.uk)

Released under MIT license, see LICENSE for details.