Skip to content

Add unit tests for RobotDashboard#219

Open
timdegroot1996 wants to merge 6 commits intomainfrom
python-unit-tests
Open

Add unit tests for RobotDashboard#219
timdegroot1996 wants to merge 6 commits intomainfrom
python-unit-tests

Conversation

@timdegroot1996
Copy link
Collaborator

  • Created test_robotdashboard.py to cover various functionalities of the RobotDashboard class, including initialization, output processing, and dashboard creation.
  • Implemented tests for handling outputs, including error scenarios for invalid XML and duplicate logs.
  • Added tests for the print_runs, remove_outputs, and create_dashboard methods to ensure correct behavior under different configurations.
  • Developed test_server.py to test the ApiServer class and its FastAPI endpoints, utilizing MagicMock for the RobotDashboard instance.
  • Covered authentication, output addition, log management, and error handling in the server tests.
  • Ensured comprehensive coverage of both successful and failure scenarios for all endpoints.

- Created `test_robotdashboard.py` to cover various functionalities of the RobotDashboard class, including initialization, output processing, and dashboard creation.
- Implemented tests for handling outputs, including error scenarios for invalid XML and duplicate logs.
- Added tests for the `print_runs`, `remove_outputs`, and `create_dashboard` methods to ensure correct behavior under different configurations.
- Developed `test_server.py` to test the ApiServer class and its FastAPI endpoints, utilizing MagicMock for the RobotDashboard instance.
- Covered authentication, output addition, log management, and error handling in the server tests.
- Ensured comprehensive coverage of both successful and failure scenarios for all endpoints.
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a comprehensive Python unit test suite (pytest + coverage) for the robotframework_dashboard package and integrates it into CI ahead of the existing Robot acceptance tests. It also includes a few small runtime/compatibility tweaks (notably SQLite datetime handling for Python 3.12+ and safer file reads in the FastAPI server).

Changes:

  • Add extensive unit tests under tests/ (server endpoints, CLI/main orchestration, database, processors, dashboard generation, dependencies, arguments).
  • Add unit-test runner scripts + CI workflow job to run pytest with coverage and upload the report artifact.
  • Make small production changes to improve resource handling/coverage annotations and SQLite datetime compatibility.

Reviewed changes

Copilot reviewed 22 out of 53 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
tests/test_server.py New FastAPI ApiServer endpoint tests via TestClient + mocked RobotDashboard
tests/test_robotdashboard.py New tests for RobotDashboard core workflow methods
tests/test_processors.py New tests for OutputProcessor and legacy RF compatibility processors
tests/test_main.py New tests for main() orchestration and server-start branch
tests/test_dependencies.py New tests for dependency inlining/CDN blocks
tests/test_database.py New tests for DatabaseProcessor CRUD, migration, and compat branches
tests/test_dashboard.py New tests for dashboard generation and helpers
tests/test_arguments.py New tests for CLI argument parsing/normalization and dotdict
tests/conftest.py Shared fixtures for XML outputs, processors, and DB setup
scripts/unittests.sh Linux/macOS unit test + coverage runner script
scripts/unittests.bat Windows unit test + coverage runner script
robotframework_dashboard/server.py Use context managers for file reads; adjust coverage pragmas
robotframework_dashboard/main.py Mark __main__ guard as not coverable
robotframework_dashboard/dependencies.py Mark an error branch as not coverable
robotframework_dashboard/database.py Register SQLite adapter for datetime; clear connection on close
robotframework_dashboard/abstractdb.py Add # pragma: no cover to abstract/optional methods
requirements-dev.txt Add dev dependencies needed for unit tests and server tests
pyproject.toml Add pytest warning filter configuration
atest/testsuites/00_cli.robot Update acceptance-test output path to shared testdata/outputs
atest/resources/keywords/general-keywords.resource Update CLI invocation paths to shared testdata/outputs
.gitignore Ignore coverage file
.github/workflows/tests.yml Add unit-tests job and gate robot tests on it
.github/skills/unit-tests.md Document unit test layout, execution, and CI integration

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +88 to +93
def test_get_admin_page_no_autoupdate_true_hides_refresh_card():
server = _make_server(no_autoupdate=True)
html = server._get_admin_page()
# When no_autoupdate=True the placeholder is replaced with "" (visible)
assert "hidden" not in html or "placeholder_refresh_card_visibility" not in html

Comment on lines +446 to +448
def test_remove_outputs_all_empty_database():
"""When all=True and database is empty, remove_outputs should not be called."""
server = _make_server()
#!/usr/bin/env bash
set -e

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
@@ -0,0 +1,3 @@
set COVERAGE_FILE=results/.coverage
set PYTHONPATH=%~dp0..
python -m pytest tests/ --cov=robotframework_dashboard --cov-report=term-missing --cov-report=html:results/coverage
Comment on lines +437 to +439
def test_get_data_null_run_alias_generates_auto_alias(db):
"""get_data() assigns 'Alias 0' when run_alias is NULL (pre-0.6.0 compat)."""
db.open_database()
Comment on lines +323 to +327
def test_remove_by_run_start(populated_db):
populated_db.open_database()
data = populated_db.get_data()
run_start = data["runs"][0]["run_start"]
populated_db.remove_runs([f"run_start={run_start}"])
admin_html = open(admin_file, "r").read()
with open(admin_file, "r", encoding="utf-8") as _f:
admin_html = _f.read()
admin_html = admin_html.replace('"placeholder_version"', __version__)
Comment on lines +9 to +14
import gzip
import io
import pytest
from pathlib import Path
from unittest.mock import MagicMock, patch, call
from fastapi.testclient import TestClient
Comment on lines +1 to +3
import shutil
import pytest
from datetime import datetime
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants