Files
Anthias/tests/test_app.py
dependabot[bot] 84e05e2f45 chore(deps): bump the npm group across 1 directory with 24 updates (#2448)
* chore(deps): bump the npm group across 1 directory with 24 updates

Bumps the npm group with 23 updates in the / directory:

| Package | From | To |
| --- | --- | --- |
| [@reduxjs/toolkit](https://github.com/reduxjs/redux-toolkit) | `2.5.1` | `2.8.2` |
| [bootstrap](https://github.com/twbs/bootstrap) | `4.6.2` | `5.3.7` |
| [react](https://github.com/facebook/react/tree/HEAD/packages/react) | `19.0.0` | `19.1.1` |
| [@types/react](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/react) | `19.1.8` | `19.1.10` |
| [react-dom](https://github.com/facebook/react/tree/HEAD/packages/react-dom) | `19.0.0` | `19.1.1` |
| [@types/react-dom](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/react-dom) | `19.1.6` | `19.1.7` |
| [react-icons](https://github.com/react-icons/react-icons) | `5.4.0` | `5.5.0` |
| [react-router](https://github.com/remix-run/react-router/tree/HEAD/packages/react-router) | `7.7.1` | `7.8.0` |
| [react-router-dom](https://github.com/remix-run/react-router/tree/HEAD/packages/react-router-dom) | `7.7.1` | `7.8.0` |
| [@babel/core](https://github.com/babel/babel/tree/HEAD/packages/babel-core) | `7.27.7` | `7.28.3` |
| [@babel/preset-env](https://github.com/babel/babel/tree/HEAD/packages/babel-preset-env) | `7.26.7` | `7.28.3` |
| [@testing-library/jest-dom](https://github.com/testing-library/jest-dom) | `6.6.4` | `6.7.0` |
| [@typescript-eslint/eslint-plugin](https://github.com/typescript-eslint/typescript-eslint/tree/HEAD/packages/eslint-plugin) | `8.39.0` | `8.39.1` |
| [eslint](https://github.com/eslint/eslint) | `8.57.1` | `9.33.0` |
| [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react) | `7.37.4` | `7.37.5` |
| [jest](https://github.com/jestjs/jest/tree/HEAD/packages/jest) | `30.0.3` | `30.0.5` |
| [mini-css-extract-plugin](https://github.com/webpack-contrib/mini-css-extract-plugin) | `2.9.2` | `2.9.4` |
| [msw](https://github.com/mswjs/msw) | `2.10.2` | `2.10.5` |
| [sass](https://github.com/sass/dart-sass) | `1.83.4` | `1.90.0` |
| [sass-loader](https://github.com/webpack-contrib/sass-loader) | `16.0.4` | `16.0.5` |
| [ts-jest](https://github.com/kulshekhar/ts-jest) | `29.4.0` | `29.4.1` |
| [webpack](https://github.com/webpack/webpack) | `5.97.1` | `5.101.2` |
| [webpack-cli](https://github.com/webpack/webpack-cli) | `5.1.4` | `6.0.1` |



Updates `@reduxjs/toolkit` from 2.5.1 to 2.8.2
- [Release notes](https://github.com/reduxjs/redux-toolkit/releases)
- [Commits](https://github.com/reduxjs/redux-toolkit/compare/v2.5.1...v2.8.2)

Updates `bootstrap` from 4.6.2 to 5.3.7
- [Release notes](https://github.com/twbs/bootstrap/releases)
- [Commits](https://github.com/twbs/bootstrap/compare/v4.6.2...v5.3.7)

Updates `react` from 19.0.0 to 19.1.1
- [Release notes](https://github.com/facebook/react/releases)
- [Changelog](https://github.com/facebook/react/blob/main/CHANGELOG.md)
- [Commits](https://github.com/facebook/react/commits/v19.1.1/packages/react)

Updates `@types/react` from 19.1.8 to 19.1.10
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/react)

Updates `react-dom` from 19.0.0 to 19.1.1
- [Release notes](https://github.com/facebook/react/releases)
- [Changelog](https://github.com/facebook/react/blob/main/CHANGELOG.md)
- [Commits](https://github.com/facebook/react/commits/v19.1.1/packages/react-dom)

Updates `@types/react-dom` from 19.1.6 to 19.1.7
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/react-dom)

Updates `react-icons` from 5.4.0 to 5.5.0
- [Release notes](https://github.com/react-icons/react-icons/releases)
- [Commits](https://github.com/react-icons/react-icons/compare/v5.4.0...v5.5.0)

Updates `react-router` from 7.7.1 to 7.8.0
- [Release notes](https://github.com/remix-run/react-router/releases)
- [Changelog](https://github.com/remix-run/react-router/blob/main/packages/react-router/CHANGELOG.md)
- [Commits](https://github.com/remix-run/react-router/commits/react-router@7.8.0/packages/react-router)

Updates `react-router-dom` from 7.7.1 to 7.8.0
- [Release notes](https://github.com/remix-run/react-router/releases)
- [Changelog](https://github.com/remix-run/react-router/blob/main/packages/react-router-dom/CHANGELOG.md)
- [Commits](https://github.com/remix-run/react-router/commits/react-router-dom@7.8.0/packages/react-router-dom)

Updates `@babel/core` from 7.27.7 to 7.28.3
- [Release notes](https://github.com/babel/babel/releases)
- [Changelog](https://github.com/babel/babel/blob/main/CHANGELOG.md)
- [Commits](https://github.com/babel/babel/commits/v7.28.3/packages/babel-core)

Updates `@babel/preset-env` from 7.26.7 to 7.28.3
- [Release notes](https://github.com/babel/babel/releases)
- [Changelog](https://github.com/babel/babel/blob/main/CHANGELOG.md)
- [Commits](https://github.com/babel/babel/commits/v7.28.3/packages/babel-preset-env)

Updates `@testing-library/jest-dom` from 6.6.4 to 6.7.0
- [Release notes](https://github.com/testing-library/jest-dom/releases)
- [Changelog](https://github.com/testing-library/jest-dom/blob/main/CHANGELOG.md)
- [Commits](https://github.com/testing-library/jest-dom/compare/v6.6.4...v6.7.0)

Updates `@types/react` from 19.1.8 to 19.1.10
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/react)

Updates `@types/react-dom` from 19.1.6 to 19.1.7
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/react-dom)

Updates `@typescript-eslint/eslint-plugin` from 8.39.0 to 8.39.1
- [Release notes](https://github.com/typescript-eslint/typescript-eslint/releases)
- [Changelog](https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/CHANGELOG.md)
- [Commits](https://github.com/typescript-eslint/typescript-eslint/commits/v8.39.1/packages/eslint-plugin)

Updates `@typescript-eslint/parser` from 8.39.0 to 8.39.1
- [Release notes](https://github.com/typescript-eslint/typescript-eslint/releases)
- [Changelog](https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/parser/CHANGELOG.md)
- [Commits](https://github.com/typescript-eslint/typescript-eslint/commits/v8.39.1/packages/parser)

Updates `eslint` from 8.57.1 to 9.33.0
- [Release notes](https://github.com/eslint/eslint/releases)
- [Changelog](https://github.com/eslint/eslint/blob/main/CHANGELOG.md)
- [Commits](https://github.com/eslint/eslint/compare/v8.57.1...v9.33.0)

Updates `eslint-plugin-react` from 7.37.4 to 7.37.5
- [Release notes](https://github.com/jsx-eslint/eslint-plugin-react/releases)
- [Changelog](https://github.com/jsx-eslint/eslint-plugin-react/blob/master/CHANGELOG.md)
- [Commits](https://github.com/jsx-eslint/eslint-plugin-react/compare/v7.37.4...v7.37.5)

Updates `jest` from 30.0.3 to 30.0.5
- [Release notes](https://github.com/jestjs/jest/releases)
- [Changelog](https://github.com/jestjs/jest/blob/main/CHANGELOG.md)
- [Commits](https://github.com/jestjs/jest/commits/v30.0.5/packages/jest)

Updates `mini-css-extract-plugin` from 2.9.2 to 2.9.4
- [Release notes](https://github.com/webpack-contrib/mini-css-extract-plugin/releases)
- [Changelog](https://github.com/webpack-contrib/mini-css-extract-plugin/blob/master/CHANGELOG.md)
- [Commits](https://github.com/webpack-contrib/mini-css-extract-plugin/compare/v2.9.2...v2.9.4)

Updates `msw` from 2.10.2 to 2.10.5
- [Release notes](https://github.com/mswjs/msw/releases)
- [Changelog](https://github.com/mswjs/msw/blob/main/CHANGELOG.md)
- [Commits](https://github.com/mswjs/msw/compare/v2.10.2...v2.10.5)

Updates `sass` from 1.83.4 to 1.90.0
- [Release notes](https://github.com/sass/dart-sass/releases)
- [Changelog](https://github.com/sass/dart-sass/blob/main/CHANGELOG.md)
- [Commits](https://github.com/sass/dart-sass/compare/1.83.4...1.90.0)

Updates `sass-loader` from 16.0.4 to 16.0.5
- [Release notes](https://github.com/webpack-contrib/sass-loader/releases)
- [Changelog](https://github.com/webpack-contrib/sass-loader/blob/master/CHANGELOG.md)
- [Commits](https://github.com/webpack-contrib/sass-loader/compare/v16.0.4...v16.0.5)

Updates `ts-jest` from 29.4.0 to 29.4.1
- [Release notes](https://github.com/kulshekhar/ts-jest/releases)
- [Changelog](https://github.com/kulshekhar/ts-jest/blob/main/CHANGELOG.md)
- [Commits](https://github.com/kulshekhar/ts-jest/compare/v29.4.0...v29.4.1)

Updates `webpack` from 5.97.1 to 5.101.2
- [Release notes](https://github.com/webpack/webpack/releases)
- [Commits](https://github.com/webpack/webpack/compare/v5.97.1...v5.101.2)

Updates `webpack-cli` from 5.1.4 to 6.0.1
- [Release notes](https://github.com/webpack/webpack-cli/releases)
- [Changelog](https://github.com/webpack/webpack-cli/blob/master/CHANGELOG.md)
- [Commits](https://github.com/webpack/webpack-cli/compare/webpack-cli@5.1.4...webpack-cli@6.0.1)

---
updated-dependencies:
- dependency-name: "@reduxjs/toolkit"
  dependency-version: 2.8.2
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: npm
- dependency-name: bootstrap
  dependency-version: 5.3.7
  dependency-type: direct:production
  update-type: version-update:semver-major
  dependency-group: npm
- dependency-name: react
  dependency-version: 19.1.1
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: npm
- dependency-name: "@types/react"
  dependency-version: 19.1.10
  dependency-type: direct:development
  update-type: version-update:semver-patch
  dependency-group: npm
- dependency-name: react-dom
  dependency-version: 19.1.1
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: npm
- dependency-name: "@types/react-dom"
  dependency-version: 19.1.7
  dependency-type: direct:development
  update-type: version-update:semver-patch
  dependency-group: npm
- dependency-name: react-icons
  dependency-version: 5.5.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: npm
- dependency-name: react-router
  dependency-version: 7.8.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: npm
- dependency-name: react-router-dom
  dependency-version: 7.8.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: npm
- dependency-name: "@babel/core"
  dependency-version: 7.28.3
  dependency-type: direct:development
  update-type: version-update:semver-minor
  dependency-group: npm
- dependency-name: "@babel/preset-env"
  dependency-version: 7.28.3
  dependency-type: direct:development
  update-type: version-update:semver-minor
  dependency-group: npm
- dependency-name: "@testing-library/jest-dom"
  dependency-version: 6.7.0
  dependency-type: direct:development
  update-type: version-update:semver-minor
  dependency-group: npm
- dependency-name: "@types/react"
  dependency-version: 19.1.10
  dependency-type: direct:development
  update-type: version-update:semver-patch
  dependency-group: npm
- dependency-name: "@types/react-dom"
  dependency-version: 19.1.7
  dependency-type: direct:development
  update-type: version-update:semver-patch
  dependency-group: npm
- dependency-name: "@typescript-eslint/eslint-plugin"
  dependency-version: 8.39.1
  dependency-type: direct:development
  update-type: version-update:semver-patch
  dependency-group: npm
- dependency-name: "@typescript-eslint/parser"
  dependency-version: 8.39.1
  dependency-type: direct:development
  update-type: version-update:semver-patch
  dependency-group: npm
- dependency-name: eslint
  dependency-version: 9.33.0
  dependency-type: direct:development
  update-type: version-update:semver-major
  dependency-group: npm
- dependency-name: eslint-plugin-react
  dependency-version: 7.37.5
  dependency-type: direct:development
  update-type: version-update:semver-patch
  dependency-group: npm
- dependency-name: jest
  dependency-version: 30.0.5
  dependency-type: direct:development
  update-type: version-update:semver-patch
  dependency-group: npm
- dependency-name: mini-css-extract-plugin
  dependency-version: 2.9.4
  dependency-type: direct:development
  update-type: version-update:semver-patch
  dependency-group: npm
- dependency-name: msw
  dependency-version: 2.10.5
  dependency-type: direct:development
  update-type: version-update:semver-patch
  dependency-group: npm
- dependency-name: sass
  dependency-version: 1.90.0
  dependency-type: direct:development
  update-type: version-update:semver-minor
  dependency-group: npm
- dependency-name: sass-loader
  dependency-version: 16.0.5
  dependency-type: direct:development
  update-type: version-update:semver-patch
  dependency-group: npm
- dependency-name: ts-jest
  dependency-version: 29.4.1
  dependency-type: direct:development
  update-type: version-update:semver-patch
  dependency-group: npm
- dependency-name: webpack
  dependency-version: 5.101.2
  dependency-type: direct:development
  update-type: version-update:semver-minor
  dependency-group: npm
- dependency-name: webpack-cli
  dependency-version: 6.0.1
  dependency-type: direct:development
  update-type: version-update:semver-major
  dependency-group: npm
...

Signed-off-by: dependabot[bot] <support@github.com>

* fix: resolve build errors

* fix: remove deprecated Bootstrap class names

* fix: get rid of underline in navbar links

* fix: homepage styles

* chore: refactor `_tooltip.scss` by nesting the existing styles

* fix: sort out the layout of `AddAssetModal`

* fix: make the progress bar yellow

* fix: sort out the layout of `EditAssetModal`

* fix: homepage and app-level themes

* fix: layout issues in the settings page

* test: fix Python integration tests

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: nicomiguelino <nicomiguelino2014@gmail.com>
2025-08-15 20:49:56 -07:00

415 lines
13 KiB
Python

import os
import shutil
import tempfile
from datetime import timedelta
from time import sleep
from unittest import TestCase, skip
from django.test import tag
from django.utils import timezone
from selenium import webdriver
from selenium.common.exceptions import ElementNotVisibleException
from splinter import Browser
from anthias_app.models import Asset
from settings import settings
main_page_url = 'http://localhost:8080'
settings_url = 'http://foo:bar@localhost:8080/settings'
system_info_url = 'http://foo:bar@localhost:8080/system_info'
asset_x = {
'mimetype': 'web',
'asset_id': '4c8dbce552edb5812d3a866cfe5f159d',
'name': 'WireLoad',
'uri': 'http://www.wireload.net',
'start_date': timezone.now() - timedelta(days=1),
'end_date': timezone.now() + timedelta(days=1),
'duration': 5,
'is_enabled': 0,
'nocache': 0,
'play_order': 1,
'skip_asset_check': 0
}
asset_y = {
'mimetype': 'image',
'asset_id': '7e978f8c1204a6f70770a1eb54a76e9b',
'name': 'Google',
'uri': 'https://www.google.com/images/srpr/logo3w.png',
'start_date': timezone.now() - timedelta(days=1),
'end_date': timezone.now() + timedelta(days=1),
'duration': 6,
'is_enabled': 1,
'nocache': 0,
'play_order': 0,
'skip_asset_check': 0
}
class TemporaryCopy(object):
def __init__(self, original_path, base_path):
self.original_path = original_path
self.base_path = base_path
def __enter__(self):
temp_dir = tempfile.gettempdir()
self.path = os.path.join(temp_dir, self.base_path)
shutil.copy2(self.original_path, self.path)
return self.path
def __exit__(self, exc_type, exc_val, exc_tb):
os.remove(self.path)
def get_browser():
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--headless')
chrome_options.add_argument('--disable-dev-shm-usage')
return Browser('chrome', headless=True, options=chrome_options)
def wait_for_and_do(browser, query, callback):
not_filled = True
n = 0
while not_filled:
try:
callback(browser.find_by_css(query).first)
not_filled = False
except ElementNotVisibleException as e:
if n > 20:
raise e
n += 1
@tag('integration')
class WebTest(TestCase):
def setUp(self):
Asset.objects.all().delete()
def test_add_asset_url(self):
with get_browser() as browser:
browser.visit(main_page_url)
wait_for_and_do(
browser, '#add-asset-button', lambda btn: btn.click())
sleep(1)
wait_for_and_do(
browser, 'input[name="uri"]',
lambda field: field.fill('https://example.com'))
sleep(1)
wait_for_and_do(browser, '#tab-uri', lambda form: form.click())
sleep(1) # Wait for the new-asset panel animation.
wait_for_and_do(browser, '#save-asset', lambda btn: btn.click())
sleep(3) # The backend needs time to process the request.
assets = Asset.objects.all()
self.assertEqual(len(assets), 1)
asset = assets.first()
self.assertEqual(asset.name, 'https://example.com')
self.assertEqual(asset.uri, 'https://example.com')
self.assertEqual(asset.mimetype, 'webpage')
self.assertEqual(asset.duration, settings['default_duration'])
@skip('migrate to React-based tests')
def test_edit_asset(self):
asset = Asset.objects.create(**asset_x)
with get_browser() as browser:
browser.visit(main_page_url)
wait_for_and_do(
browser, '.edit-asset-button', lambda btn: btn.click())
sleep(1)
wait_for_and_do(
browser, 'input[name="duration"]',
lambda field: field.fill('333'))
sleep(1)
wait_for_and_do(browser, '#edit-form', lambda form: form.click())
sleep(3)
wait_for_and_do(
browser,
'.edit-asset-modal #save-asset',
lambda btn: btn.click()
)
sleep(3)
assets = Asset.objects.all()
self.assertEqual(len(assets), 1)
asset = assets.first()
self.assertEqual(asset.duration, 333)
def test_add_asset_image_upload(self):
image_file = '/tmp/image.png'
with get_browser() as browser:
browser.visit(main_page_url)
browser.find_by_id('add-asset-button').click()
sleep(1)
wait_for_and_do(
browser, '.nav-link.upload-asset-tab', lambda tab: tab.click())
wait_for_and_do(
browser, 'input[name="file_upload"]',
lambda input: input.fill(image_file))
sleep(1)
sleep(3)
assets = Asset.objects.all()
self.assertEqual(len(assets), 1)
asset = assets.first()
self.assertEqual(asset.name, 'image.png')
self.assertEqual(asset.mimetype, 'image')
self.assertEqual(asset.duration, settings['default_duration'])
def test_add_asset_video_upload(self):
with (
TemporaryCopy('tests/assets/asset.mov', 'video.mov') as video_file
):
with get_browser() as browser:
browser.visit(main_page_url)
browser.find_by_id('add-asset-button').click()
sleep(1)
wait_for_and_do(
browser, '.nav-link.upload-asset-tab',
lambda tab: tab.click())
wait_for_and_do(
browser, 'input[name="file_upload"]',
lambda input: input.fill(video_file))
sleep(1) # Wait for the new-asset panel animation.
sleep(3) # The backend needs time to process the request.
assets = Asset.objects.all()
self.assertEqual(len(assets), 1)
asset = assets.first()
self.assertEqual(asset.name, 'video.mov')
self.assertEqual(asset.mimetype, 'video')
self.assertEqual(asset.duration, 5)
def test_add_two_assets_upload(self):
with (
TemporaryCopy('tests/assets/asset.mov', 'video.mov') as video_file,
TemporaryCopy(
'static/img/standby.png', 'standby.png') as image_file,
):
with get_browser() as browser:
browser.visit(main_page_url)
browser.find_by_id('add-asset-button').click()
sleep(1)
wait_for_and_do(
browser, '.nav-link.upload-asset-tab',
lambda tab: tab.click())
wait_for_and_do(
browser, 'input[name="file_upload"]',
lambda input: input.fill(image_file))
wait_for_and_do(
browser, 'input[name="file_upload"]',
lambda input: input.fill(video_file))
sleep(3)
assets = Asset.objects.all()
self.assertEqual(len(assets), 2)
self.assertEqual(assets[0].name, 'standby.png')
self.assertEqual(assets[0].mimetype, 'image')
self.assertEqual(
assets[0].duration, settings['default_duration'])
self.assertEqual(assets[1].name, 'video.mov')
self.assertEqual(assets[1].mimetype, 'video')
self.assertEqual(assets[1].duration, 5)
@skip('fixme')
def test_add_asset_streaming(self):
with get_browser() as browser:
browser.visit(main_page_url)
wait_for_and_do(
browser, '#add-asset-button', lambda btn: btn.click())
sleep(1)
wait_for_and_do(
browser, 'input[name="uri"]',
lambda field: field.fill('rtsp://localhost:8091/asset.mov'))
sleep(1)
wait_for_and_do(browser, '#add-form', lambda form: form.click())
sleep(1)
wait_for_and_do(browser, '#save-asset', lambda btn: btn.click())
sleep(10)
assets = Asset.objects.all()
self.assertEqual(len(assets), 1)
asset = assets.first()
self.assertEqual(asset.name, 'rtsp://localhost:8091/asset.mov')
self.assertEqual(asset.uri, 'rtsp://localhost:8091/asset.mov')
self.assertEqual(asset.mimetype, 'streaming')
self.assertEqual(
asset.duration, settings['default_streaming_duration'])
@skip('migrate to React-based tests')
def test_remove_asset(self):
Asset.objects.create(**asset_x)
with get_browser() as browser:
browser.visit(main_page_url)
wait_for_and_do(
browser, '.delete-asset-button', lambda btn: btn.click())
wait_for_and_do(
browser, '.confirm-delete', lambda btn: btn.click())
sleep(3)
self.assertEqual(Asset.objects.count(), 0)
def test_enable_asset(self):
Asset.objects.create(**asset_x)
with get_browser() as browser:
browser.visit(main_page_url)
sleep(2) # Wait for React to render
# Find the toggle element and scroll it into view
toggle_element = browser.find_by_css(
'.is_enabled-toggle input[type="checkbox"]'
).first
browser.execute_script(
"arguments[0].scrollIntoView(true);",
toggle_element._element
)
sleep(1)
# Click the label to trigger the toggle
label_element = browser.find_by_css('.is_enabled-toggle').first
browser.execute_script(
"arguments[0].click();", label_element._element)
sleep(2)
# Re-find the element after React re-renders it
toggle_element_after = browser.find_by_css(
'.is_enabled-toggle input[type="checkbox"]').first
browser.execute_script(
"return arguments[0].checked;", toggle_element_after._element)
# Wait longer for API call to complete
sleep(5)
assets = Asset.objects.all()
self.assertEqual(len(assets), 1)
asset = assets.first()
self.assertEqual(asset.is_enabled, True)
def test_disable_asset(self):
# Clear any existing assets first
Asset.objects.all().delete()
Asset.objects.create(**{
**asset_x,
'is_enabled': 1
})
with get_browser() as browser:
browser.visit(main_page_url)
sleep(2) # Wait for React to render
# Find the toggle element and scroll it into view
toggle_element = browser.find_by_css(
'.is_enabled-toggle input[type="checkbox"]').first
browser.execute_script(
"arguments[0].scrollIntoView(true);", toggle_element._element)
sleep(1)
# Click the label to trigger the toggle
label_element = browser.find_by_css('.is_enabled-toggle').first
browser.execute_script(
"arguments[0].click();", label_element._element)
sleep(2)
# Re-find the element after React re-renders it
toggle_element_after = browser.find_by_css(
'.is_enabled-toggle input[type="checkbox"]').first
browser.execute_script(
"return arguments[0].checked;",
toggle_element_after._element
)
# Wait longer for API call to complete
sleep(5)
assets = Asset.objects.all()
self.assertEqual(len(assets), 1)
asset = assets.first()
self.assertEqual(asset.is_enabled, False)
@skip('migrate to React-based tests')
def test_reorder_asset(self):
Asset.objects.create(**{
**asset_x,
'is_enabled': 1
})
Asset.objects.create(**asset_y)
with get_browser() as browser:
browser.visit(main_page_url)
asset_x_for_drag = browser.find_by_id(asset_x['asset_id'])
sleep(1)
asset_y_to_reorder = browser.find_by_id(asset_y['asset_id'])
asset_x_for_drag.drag_and_drop(asset_y_to_reorder)
sleep(3)
x = Asset.objects.get(asset_id=asset_x['asset_id'])
y = Asset.objects.get(asset_id=asset_y['asset_id'])
self.assertEqual(x.play_order, 0)
self.assertEqual(y.play_order, 1)
def test_settings_page_should_work(self):
with get_browser() as browser:
browser.visit(settings_url)
self.assertEqual(
(
'Error: 500 Internal Server Error' in browser.html or
'Error: 504 Gateway Time-out' in browser.html or
'Error: 504 Gateway Timeout' in browser.html
),
False,
'5xx: not expected'
)
def test_system_info_page_should_work(self):
with get_browser() as browser:
browser.visit(system_info_url)
self.assertEqual(
browser.is_text_present('Error: 500 Internal Server Error'),
False,
'500: internal server error not expected',
)