To effectively run tests for the Screenly Anthias project, follow the outlined steps below. This guide includes detailed code examples to assist in executing the tests accurately.

Prerequisites

Ensure that you have Docker and Poetry installed on your machine.

Step 1: Build and Start Containers

Begin by building and starting the required containers. Run the following command in your terminal:

$ poetry run python tools/image_builder \
--dockerfiles-only \
--disable-cache-mounts \
--service celery \
--service redis \
--service test

$ docker compose \
-f docker-compose.test.yml up -d --build

This command builds the Docker containers necessary for the testing environment, using Poetry to manage dependencies.

Step 2: Prepare the Test Environment

Prepare the environment for testing by running:

$ docker compose \
-f docker-compose.test.yml \
exec anthias-test bash ./bin/prepare_test_environment.sh -s

This step ensures that all required test configurations are in place before executing the tests.

Step 3: Run Unit Tests

Unit tests can be executed via the manage.py script. Execute the following command to run the unit tests excluding integration tests:

$ docker compose \
-f docker-compose.test.yml \
exec anthias-test ./manage.py test --exclude-tag=integration

Next, to run integration tests, use this command:

$ docker compose \
-f docker-compose.test.yml \
exec anthias-test ./manage.py test --tag=integration

It’s important to run integration and non-integration tests separately due to potential conflicts between the two.

Additional Testing

Aside from the automated tests, manual testing is also vital. While the unit tests will catch many issues, manual testing provides a broader evaluation of functionality. Below are some manual testing steps:

  1. Ensure the device is connected to the internet (e.g., via Ethernet).
  2. Activate the device and verify that the splash page appears correctly.
  3. Access the web UI home page by entering the provided IP address into a browser.
  4. Add various assets (images, videos, or webpages) and activate them with the toggle switch to check their display on the screen.
  5. Disable the assets and verify that the screen shows the Anthias standby page.
  6. Adjust the display duration of an asset and confirm it reflects the specified time.
  7. Test changing the start and end dates of assets for accurate display based on timing.
  8. Enable some assets and modify their order visually to confirm correct arrangement.
  9. Attempt to rename any asset to validate the renaming functionality works as intended.

Example Test Code for Unit Testing

Unit tests are defined in Python, as illustrated in the example below, which tests viewer functionality:

import unittest
from unittest import mock
from viewer import Viewer

class ViewerTestCase(unittest.TestCase):
    def setUp(self):
        self.original_splash_delay = Viewer.SPLASH_DELAY
        Viewer.SPLASH_DELAY = 0
        
        self.viewer_instance = Viewer()
        self.m_scheduler = mock.Mock(name='m_scheduler')
        self.p_scheduler = mock.patch.object(self.viewer_instance, 'Scheduler', self.m_scheduler)

    def tearDown(self):
        Viewer.SPLASH_DELAY = self.original_splash_delay
    
    def test_load_browser(self):
        self.m_cmd.return_value.return_value.process.stdout = (
            b'Screenly service start'
        )
        self.p_cmd.start()
        self.viewer_instance.load_browser()
        self.p_cmd.stop()
        self.m_cmd.assert_called_once_with('ScreenlyWebview')

if __name__ == '__main__':
    unittest.main()

This code snippet demonstrates the use of unittest and mock to create isolated tests for the viewer functionality within the application.

Following these steps ensures that both automated and manual testing is comprehensive and effective in maintaining code quality.