- First Run
- I just want to run the tests!
- Using Dashboard and Panel Templates
- Give me metrics!
- Running the development server
- Generating the documentation
- Updating the translation files
- Starting clean
- Non-interactive Mode
- Environment Backups
- Environment Versioning
Horizon ships with a script called run_tests.sh at the root of the repository. This script provides many crucial functions for the project, and also makes several otherwise complex tasks trivial for you as a developer.
If you start with a clean copy of the Horizon repository, the first thing you should do is to run ./run_tests.sh from the root of the repository. This will do two things for you:
- Set up a virtual environment for both the horizon module and the openstack-dashboard project using openstack-dashboard/tools/install_venv.py.
- Run the tests for both horizon and openstack-dashboard using their respective environments and verify that evreything is working.
Setting up the environment the first time can take several minutes, but only needs to be done once. If dependencies are added in the future, updating the environments will be necessary but not as time consuming.
Running the full set of unit tests quickly and easily is the main goal of this script. All you need to do is:
Yep, that's it. However, for a quicker test run you can skip the Selenium tests by using the --skip-selenium flag:
This isn't recommended, but can be a timesaver when you only need to run the code tests and not the frontend tests during development.
Instead of running all tests, you can specify an individual directory, file, class, or method that contains test code.
To run the tests in the horizon/test/tests/tables.py file:
To run the tests in the WorkflowsTests class in horizon/test/tests/workflows:
To run just the WorkflowsTests.test_workflow_view test method:
Horizon has a set of convenient management commands for creating new dashboards and panels based on basic templates.
To create a new dashboard, run the following:
./run_tests.sh -m startdash <dash_name>
This will create a directory with the given dashboard name, a dashboard.py module with the basic dashboard code filled in, and various other common "boilerplate" code.
- --target: the directory in which the dashboard files should be created. Default: A new directory within the current directory.
To create a new panel, run the following:
./run_tests -m startpanel <panel_name> --dashboard=<dashboard_path>
This will create a directory with the given panel name, and panel.py module with the basic panel code filled in, and various other common "boilerplate" code.
- -d, --dashboard: The dotted python path to your dashboard app (the module which containers the dashboard.py file.).
- --target: the directory in which the panel files should be created. If the value is auto the panel will be created as a new directory inside the dashboard module's directory structure. Default: A new directory within the current directory.
You can generate various reports and metrics using command line arguments to run_tests.sh.
To run coverage reports:
The reports are saved to ./reports/ and ./coverage.xml.
You can check for PEP8 violations as well:
The results are saved to ./pep8.txt.
For more detailed code analysis you can run:
The output will be saved in ./pylint.txt.
This will output a total "tab count" and a list of the offending files.
As an added bonus, you can run Django's development server directly from the root of the repository with run_tests.sh like so:
This is effectively just an alias for:
./openstack-dashboard/tools/with_venv.sh ./openstack-dashboard/dashboard/manage.py runserver
You can build Horizon's documentation automatically by running:
The output is stored in ./doc/build/html/.
You can update all of the translation files for both the horizon app and openstack_dashboard project with a single command:
or, more compactly:
If you ever want to start clean with a new environment for Horizon, you can run:
That will blow away the existing environments and create new ones for you.
There is an optional flag which will run the script in a non-interactive (and eventually less verbose) mode:
This will automatically take the default action for actions which would normally prompt for user input such as installing/updating the environment.
To speed up the process of doing clean checkouts, running continuous integration tests, etc. there are options for backing up the current environment and restoring from a backup.
./run_tests.sh --restore-environment ./run_tests.sh --backup-environment
The environment backup is stored in /tmp/.horizon_environment/.
Horizon keeps track of changes to the environment by incrementing an environment_version integer at the top of run_tests.sh.
If you do anything which changes the environment (adding new dependencies or renaming directories are both great examples) be sure to increment the environment_version counter as well.