treeherder/tests
beatrice-acasandrei dfa4b04f55
Bug 1902029 - Search input criteria of 12-40 characters is too restrictive (#8258)
* Add new field author_contains to PushViewSet

* Add iexact to the existing author param

* Add test coverage
2024-11-15 12:09:13 +02:00
..
autoclassify Bug 1823654 - Introduce pyupgrade (#7904) 2024-02-02 21:02:10 +01:00
changelog New Black changes 2023-06-20 10:58:40 +02:00
client Bug 1823654 - Mostly use double quotes (#7900) 2024-01-31 16:59:20 +01:00
e2e Bug 1823654 - Introduce pyupgrade (#7904) 2024-02-02 21:02:10 +01:00
etl WIP - add new_failure field to TextLogError and update when we have a new failure. (#8254) 2024-10-23 13:41:41 -07:00
intermittents_commenter Bug 1823654 - Introduce pyupgrade (#7904) 2024-02-02 21:02:10 +01:00
jest Use babel config 2022-05-19 15:36:14 +02:00
log_parser Look up push ID in push table for faster query 2024-06-17 23:56:46 +02:00
model Bug 1906258 - make bug suggestion generation for failure case-insensitive 2024-07-05 00:03:11 +02:00
perf Update Django from 4.2 to 5.1 (#8218) 2024-10-07 16:04:32 +02:00
perfalert Revert "Bug 1919588 - Add a new testing alert table, along with new fields. (#8200)" for uniqueness failure 2024-10-16 20:15:22 +02:00
push_health Bug 1823654 - Introduce pyupgrade (#7904) 2024-02-02 21:02:10 +01:00
sample_data Fix bug suggestions with PostgreSQL (#7988) 2024-03-26 16:59:06 +01:00
services N802: Function name should be lowercase 2024-03-05 16:17:10 +01:00
test_worker N818: Exception name should be named with an Error suffix 2024-03-05 16:17:10 +01:00
ui Bug 1837998 - File regression bugs using the API (#8048) 2024-07-26 15:36:19 +03:00
utils N802: Function name should be lowercase 2024-03-05 16:17:10 +01:00
webapp Bug 1902029 - Search input criteria of 12-40 characters is too restrictive (#8258) 2024-11-15 12:09:13 +02:00
README.md Remove MySQL integration and dedicated code (#7814) 2024-05-30 15:19:56 +02:00
__init__.py fix RefDataManager and add firts working test on it 2013-04-17 17:13:24 +01:00
conftest.py Allow for bugzilla management to use a minimum threshold for 'reopened bugs' (#8144) 2024-08-05 17:48:55 -07:00
env.bat Remove MySQL integration and dedicated code (#7814) 2024-05-30 15:19:56 +02:00
sample_data_generator.py Bug 1823654 - Mostly use double quotes (#7900) 2024-01-31 16:59:20 +01:00
sampledata.py Bug 1823654 - Introduce pyupgrade (#7904) 2024-02-02 21:02:10 +01:00
settings.py Bug 1823654 - Mostly use double quotes (#7900) 2024-01-31 16:59:20 +01:00
test_dockerflow.py Bug 1823654 - Introduce pyupgrade (#7904) 2024-02-02 21:02:10 +01:00
test_middleware.py Bug 1823654 - Mostly use double quotes (#7900) 2024-01-31 16:59:20 +01:00
test_setup.py Bug 1823654 - Mostly use double quotes (#7900) 2024-01-31 16:59:20 +01:00
test_utils.py Bug 1823654 - Introduce pyupgrade (#7904) 2024-02-02 21:02:10 +01:00

README.md

Backend development

The backend test suite can be run outside the Docker container.

Start the services

We need all but the main backend service running. Since multiple backend instances are allowed, we will simply start everything up

# ENSURE THE IMAGES ARE CLEAN
docker rm "/postgres"
docker rm "/frontend"
docker rm "/rabbitmq" 
docker rm "/redis"
docker rm "/backend"
docker-compose down
docker volume rm treeherder_postgres_data 

# SETUP ALL IMAGES
docker-compose up --build

Install into virtual environment

Treeherder requires specific library versions that will likely interfere with what you have installed. It is best to setup a virtual environment to contain the quirks it introduces.

Be sure you are in the treeherder main directory

python -m venv .venv             # IMPORTANT: Notice the dot in the name
source .venv/bin/activate
pip install --no-deps -r requirements/dev.txt
pip install --no-deps -r requirements/common.txt

...or Windows...

python -m pip install virtualenv  # venv is buggy on Windows
REM IMPORTANT: Notice the dot in `.venv`
python -m virtualenv .venv             
.venv\Scripts\activate
pip install --no-deps -r requirements\dev.txt
pip install --no-deps -r requirements\common.txt

... or MacOS

python -m venv .venv             # IMPORTANT: Notice the dot in the name
source .venv/bin/activate
pip install --no-deps -r requirements/dev.txt
pip install --no-deps -r requirements/common.txt

The pip install order is important: We want the common requirements to overwrite the dev requirements (in the event there are conflicts)

Set environment variables

For Windows, Treeherder requires a number of environment variables that point to the services. In our case, those services are in local docker containers.

.\tests\env.bat

If you plan to use an IDE, here is the same, as a very long line

BROKER_URL=localhost//guest:guest@rabbitmq//;DATABASE_URL=psql://postgres:mozilla1234@postgres:5432/treeherder;REDIS_URL=redis://localhost:6379;SITE_URL=http://backend:8000/;TREEHERDER_DEBUG=True;TREEHERDER_DJANGO_SECRET_KEY=secret-key-of-at-least-50-characters-to-pass-check-deploy;NEW_RELIC_DEVELOPER_MODE=True

Ensure everything is working

Django can perform a number of checks to ensure you are configured correctly

./manage.py check

Running tests

Be sure docker-compose is up, you are in the treeherder main directory, your virtual environment is activated, and your environment variables are set:

Linux/MacOS

source .venv/bin/activate

Windows

.venv\Script\activate

Followed by either one of the two commands below.

All tests

pytest tests

Start TDD-enhanced test runner in the background

Whenever code changes are detected within the project, command below will run only the associated tests. Test runs will be triggered for either application or tests code changes.

This workflow ensures a considerably faster feedback loop for those wanting to do test driven development.

ptw --runner "pytest --testmon" --clear

Pre commit checks

If you made some changes, and want to submit a pull request; run the ./runtests.sh script (found in the main directory). It will run some linters to check your submission.

For Windows, you can run the checks in a container (see below)

Run tests in container

After docker-compose up, you may spin up any number of backend containers. You may want to run ingestion tasks, go exploring, or run the tests.

docker-compose exec backend bash

docker-compose has three execution modes

  • exec - run just the service, and assume the others are running
  • run - run all the services, but do not open their ports
  • up - run all the services with ports open

More can be read here: docker-composes up vs run vs exec

Inside this container

pytest tests

Setup git pre-commit hook

Running checks locally will allow you to catch linting errors faster. We put the git pre-commit hook into the virtual environment to avoid polluting your dev machine

.venv\Scripts\activate
pip install pre-commit
pre-commit install