Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 99 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ on:
- 'src/backend-api/**/*.py'
- 'src/backend-api/pyproject.toml'
- 'src/backend-api/pytest.ini'
- 'src/processor/**/*.py'
- 'src/processor/pyproject.toml'
- '.github/workflows/test.yml'
pull_request:
types:
Expand All @@ -23,6 +25,8 @@ on:
- 'src/backend-api/**/*.py'
- 'src/backend-api/pyproject.toml'
- 'src/backend-api/pytest.ini'
- 'src/processor/**/*.py'
- 'src/processor/pyproject.toml'
- '.github/workflows/test.yml'

permissions:
Expand All @@ -48,7 +52,7 @@ jobs:
python -m pip install --upgrade pip
cd src/backend-api
pip install -e .
pip install pytest pytest-cov
pip install pytest pytest-cov pytest-asyncio

- name: Check if Backend Test Files Exist
id: check_backend_tests
Expand All @@ -71,9 +75,26 @@ jobs:
--cov=src/app \
--cov-report=term-missing \
--cov-report=xml:reports/coverage.xml \
--cov-fail-under=82 \
--junitxml=pytest.xml \
-v

- name: Prefix coverage XML filenames with repo-root path
if: env.skip_backend_tests == 'false'
run: |
python <<'PY'
import xml.etree.ElementTree as ET
path = "src/backend-api/reports/coverage.xml"
prefix = "src/backend-api/src/app/"
tree = ET.parse(path)
root = tree.getroot()
for cls in root.iter("class"):
fname = cls.attrib.get("filename", "")
if fname and not fname.startswith(prefix):
cls.attrib["filename"] = prefix + fname
Comment on lines +88 to +94
tree.write(path, xml_declaration=True, encoding="utf-8")
PY

- name: Pytest Coverage Comment
if: |
always() &&
Expand All @@ -90,3 +111,80 @@ jobs:
if: env.skip_backend_tests == 'true'
run: |
echo "Skipping backend tests because no test files were found."

processor_tests:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v5

- name: Set up Python
uses: actions/setup-python@v6
Comment on lines +120 to +123
with:
python-version: "3.12"

- name: Install Processor Dependencies
run: |
python -m pip install --upgrade pip
cd src/processor
pip install -e .
pip install pytest pytest-cov pytest-asyncio

- name: Check if Processor Test Files Exist
id: check_processor_tests
run: |
if [ -z "$(find src/processor/src/tests -type f -name 'test_*.py' 2>/dev/null)" ]; then
echo "No processor test files found, skipping processor tests."
echo "skip_processor_tests=true" >> $GITHUB_ENV
else
echo "Processor test files found, running tests."
echo "skip_processor_tests=false" >> $GITHUB_ENV
fi

- name: Run Processor Tests with Coverage
if: env.skip_processor_tests == 'false'
run: |
cd src/processor
pytest src/tests \
Comment thread
Shreyas-Microsoft marked this conversation as resolved.
--cov=src \
--cov-report=term-missing \
--cov-report=xml:reports/coverage.xml \
--cov-fail-under=82 \
--junitxml=pytest.xml \
-v
Comment thread
Shreyas-Microsoft marked this conversation as resolved.

- name: Prefix coverage XML filenames with repo-root path
if: env.skip_processor_tests == 'false'
run: |
python <<'PY'
import xml.etree.ElementTree as ET
path = "src/processor/reports/coverage.xml"
prefix = "src/processor/src/"
tree = ET.parse(path)
root = tree.getroot()
for cls in root.iter("class"):
fname = cls.attrib.get("filename", "")
if fname and not fname.startswith(prefix):
cls.attrib["filename"] = prefix + fname
Comment on lines +163 to +169
tree.write(path, xml_declaration=True, encoding="utf-8")
PY

- name: Pytest Coverage Comment (Processor)
if: |
always() &&
github.event_name == 'pull_request' &&
github.event.pull_request.head.repo.fork == false &&
env.skip_processor_tests == 'false'
uses: MishaKav/pytest-coverage-comment@26f986d2599c288bb62f623d29c2da98609e9cd4 # v1.6.0
with:
pytest-xml-coverage-path: src/processor/reports/coverage.xml
junitxml-path: src/processor/pytest.xml
title: Processor Coverage Report
unique-id-for-comment: processor
report-only-changed-files: true

- name: Skip Processor Tests
if: env.skip_processor_tests == 'true'
run: |
echo "Skipping processor tests because no test files were found."
5 changes: 4 additions & 1 deletion src/backend-api/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ dependencies = [
]

[dependency-groups]
dev = ["pytest>=9.0.3", "pytest-cov>=6.2.1"]
dev = ["pytest>=9.0.3", "pytest-cov>=6.2.1", "pytest-asyncio>=0.23.0"]

Comment thread
Shreyas-Microsoft marked this conversation as resolved.
[tool.coverage.run]
omit = ["src/tests/*"]

[tool.uv]
override-dependencies = [
Expand Down
38 changes: 38 additions & 0 deletions src/backend-api/src/tests/application/test_application.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
"""Tests for application.Application bootstrap."""

from application import Application
from libs.base.typed_fastapi import TypedFastAPI
from libs.services.interfaces import IDataService, IHttpService, ILoggerService
from libs.services.process_services import ProcessService


def test_application_initializes_typed_fastapi():
app = Application()
assert isinstance(app.app, TypedFastAPI)
assert app.app.title == "FastAPI Application"
assert app.app.version == "1.0.0"


def test_application_sets_app_context_on_app():
app = Application()
assert app.app.app_context is app.application_context


def test_application_registers_core_services():
app = Application()
ctx = app.application_context
assert ctx.get_service(ILoggerService) is not None
assert ctx.get_service(IHttpService) is not None
assert ctx.get_service(IDataService) is not None
assert ctx.get_service(ProcessService) is not None


def test_application_includes_routers():
app = Application()
paths = {route.path for route in app.app.routes}
# router_files
assert "/api/file/upload" in paths
# router_process
assert "/api/process/create" in paths
# http_probes
assert "/health" in paths
Loading
Loading