Skip to main content

Run unit tests

This tutorial will walk you through how to run unit tests on a Tator deployment. Unit tests in Tator include tator-py unit tests, REST unit tests, and front end unit tests.

Dependencies​

The following will install all dependencies needed for all tests:

sudo apt-get install python3-pip ffmpeg wget unzip tesseract-ocr
pip3 install pytest pandas playwright==1.27.1 pytest-playwright==0.3.0 pytesseract==0.3.9 pytest-rerunfailures==10.2 tator opencv-python psutil
wget http://zebulon.bok.net/Bento4/binaries/Bento4-SDK-1-6-0-632.x86_64-unknown-linux.zip
unzip Bento4-SDK-1-6-0-632.x86_64-unknown-linux.zip
sudo cp Bento4-SDK-1-6-0-632.x86_64-unknown-linux/bin/mp4dump /usr/local/bin/.
sudo chmod +x /usr/local/bin/mp4dump
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
sudo apt install ./google-chrome-stable_current_amd64.deb
export PATH=$PATH:$HOME/.local/bin:/snap/bin
playwright install

Run tator-py unit tests​

Unit tests in tator-py only require API access to a Tator deployment. They are a good way to test a deployment besides just serving as tests for the python client. Instructions below assume a node running Ubuntu 20.04 LTS.

Run the tests​

Navigate into the tator-py submodule directory and run pytest:

cd scripts/packages/tator-py
pytest test --host $HOST --token $TOKEN -s

If you would like to keep the test projects that are created for inspection, use the --keep option:

pytest test --host $HOST --token $TOKEN -s --keep

Run REST unit tests​

From a node with kubectl access to the Tator deployment, navigate to the root directory of the Tator source and run:

make test

Run front end tests​

Front end tests are accomplished primarily via a manual procedure documented in doc/front_end_test_procedure.md in the Tator source tree. The script to create a project for unit tests can be found at scripts/packages/tator-py/examples/setup_project.py. There are also automated front-end tests which can be run as described below.

Run the tests​

Use pytest to run the tests from the root Tator source tree. The CLI accepts the hostname of Tator, login credentials, and a location to store videos of the tests being performed. A subdirectory will be created to store videos each time the tests are run.

The front end tests require a secure context (see blog post) to work properly. We can achieve this by either using a host with HTTPS enabled, or by forwarding requests to localhost to the Tator host via SSH. In the latter case, this can be achieved using ssh -N -L 8080:$HOST:80 $HOST or similar port forwarding command depending on your configuration, then passing http://localhost:8080 as the --base-url of the unit tests. The port forward command should be run on the same node that is running the unit tests.

pytest test -s \
--base-url=$HOST \
--browser=chromium \
--username=$TATOR_USER \
--password=$TATOR_PASS \
--videos=$HOME