Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 31, 2025

Added 47 tests (32 backend + 15 web) covering all previously untested backend functions and web application routes, increasing total test count from 4 to 51.

Coverage Added

Backend Functions (32 tests):

user_handler.py (13 tests)

  • Password hashing/verification and validation logic
  • User retrieval by ID and username
  • User deletion and team membership management
  • Input validation and duplicate handling

team_handler.py (6 tests)

  • Team CRUD operations (create, get by ID/name, delete)
  • Not-found scenarios

table_operations.py (8 tests)

  • Table lifecycle (create, delete) with error cases
  • Cell value operations (set, get, update, delete)

table_permissions.py (5 tests)

  • Permission management (set, update, get, delete by range/all)

Web Application (15 tests):

test_web_routes.py

  • Index/homepage rendering
  • Login/logout functionality (GET and POST)
  • Dashboard access control
  • Error pages (403, 404, 500)
  • Static file serving (CSS, images)
  • Session middleware functionality
  • Custom request headers and middleware

Backend API Improvements

Fixed UUID Handling:

  • Updated create_table, set_cell_value, and get_cell_value in table_handler.py to accept project_id: UUID directly
  • Eliminated need for str(project_id) conversions throughout codebase
  • Functions now handle UUID-to-string conversion internally where needed for SQL queries
  • Makes the API more type-safe and consistent with other backend functions

Implementation

All tests follow existing patterns:

  • Use @pytest.mark.user_creation, @pytest.mark.data_db, and @pytest.mark.web markers for CI test selection
  • Leverage transaction fixtures for test isolation
  • Handle async/await properly with @pytest.mark.asyncio
  • Web tests use AsyncClient from httpx for FastAPI endpoint testing

Test Organization & Clarity Improvements

Structured Test Files:

  • Split large test file into focused modules: test_table_operations.py and test_table_permissions.py
  • Added test_web_routes.py for comprehensive web application testing
  • Each test file has clear, single responsibility

Enhanced Debugging:

  • Added descriptive assertion messages to all tests for easier failure diagnosis
  • Example: assert user is not None, f"User {user_id} should be found"
  • Failed tests now provide specific context about what went wrong

Helper Fixtures:

  • Added test_user, test_project, and test_table fixtures in conftest.py
  • Reduces code duplication and improves maintainability

New Pytest Markers:

  • @pytest.mark.table_operations - For table and cell operation tests
  • @pytest.mark.table_permissions - For permission management tests
  • @pytest.mark.web - For web route and UI tests
  • Enables selective test execution: pytest -m table_operations or pytest -m web

Documentation:

  • Comprehensive tests/README.md documenting test structure, markers, best practices, and debugging guidance
  • Includes examples for running specific test groups

Example test structure:

@pytest.mark.table_operations
@pytest.mark.data_db
@pytest.mark.asyncio
async def test_set_and_get_cell_value(user_db_transaction, data_db_transaction):
    user_id = await create_user(...)
    project_id = await create_project(...)
    await create_table(data_db_transaction, "test_table", project_id)
    
    test_value = "Test Value"
    await set_cell_value(data_db_transaction, project_id, "test_table", 1, 1, test_value)
    value = await get_cell_value(data_db_transaction, project_id, "test_table", 1, 1)
    
    assert value == test_value, f"Cell value should be '{test_value}', got '{value}'"

Tests are ready for CI execution with existing database setup.

Original prompt

Add tests for all untested code please


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits December 31, 2025 13:44
Co-authored-by: realMorgon <81616308+realMorgon@users.noreply.github.com>
- Add tests for user_handler functions (password verification, user retrieval, deletion, team membership)
- Add tests for team_handler functions (team retrieval by ID/name, deletion)
- Add tests for table_handler functions (table creation/deletion, cell operations, permissions)

Co-authored-by: realMorgon <81616308+realMorgon@users.noreply.github.com>
set_permission, get_all_user_permissions, delete_all_user_permissions,
delete_permission_range
)
from backend.data_management.project_handler import create_project, delete_project
Copilot AI and others added 3 commits December 31, 2025 13:51
- Remove duplicate pytest marker
- Fix UUID conversion logic to use UUID() constructor instead of uuid4()

Co-authored-by: realMorgon <81616308+realMorgon@users.noreply.github.com>
- Fix error message pattern to include 'in schema'
- Fix delete_table to use actual project_id instead of random UUID

Co-authored-by: realMorgon <81616308+realMorgon@users.noreply.github.com>
- Ensure all tests use consistent marker order: data_db first, asyncio second
- Matches existing test pattern in test_projects.py

Co-authored-by: realMorgon <81616308+realMorgon@users.noreply.github.com>
Copilot AI changed the title [WIP] Add tests for all untested code Add comprehensive test coverage for untested backend functions Dec 31, 2025
Copilot AI requested a review from realMorgon December 31, 2025 13:56
@realMorgon
Copy link
Member

@copilot You may also create new test markers or new testfiles. Make it a priority that tests are easy to understand and if failed the reason is easy to find. You may also edit my tests if there is a need for that.

- Add helper fixtures to conftest.py for common test setup
- Add descriptive assertion messages to all tests for easier debugging
- Split large test_table_handler.py into focused files:
  * test_table_operations.py for table/cell operations
  * test_table_permissions.py for permission management
- Add new pytest markers (table_operations, table_permissions)
- Add comprehensive tests/README.md documenting test organization

Co-authored-by: realMorgon <81616308+realMorgon@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Dec 31, 2025

@copilot You may also create new test markers or new testfiles. Make it a priority that tests are easy to understand and if failed the reason is easy to find. You may also edit my tests if there is a ...

I've improved the test organization and clarity in commit d785bee:

Test Organization:

  • Split the 490-line test_table_handler.py into two focused files: test_table_operations.py (table/cell operations) and test_table_permissions.py (permission management)
  • Added new pytest markers: @pytest.mark.table_operations and @pytest.mark.table_permissions for selective test execution
  • Created tests/README.md documenting test structure, markers, and best practices

Improved Clarity:

  • Added descriptive assertion messages to all tests. Example: assert user is not None, f"User {user_id} should be found"
  • Added helper fixtures (test_user, test_project, test_table) in conftest.py to reduce duplication
  • Enhanced docstrings to clearly explain what each test does

Easier Failure Diagnosis:
When tests fail, the assertion messages now provide specific context:

  • What was expected
  • What was received
  • Relevant IDs and values

You can now run focused test groups: pytest -m table_operations or pytest -m table_permissions

async def test_valid_password_with_username(user_db_transaction):
"""Test password validation with username."""
# Create a test user
user_id = await create_user(
async def test_valid_password_with_email(user_db_transaction):
"""Test password validation with email."""
# Create a test user
user_id = await create_user(
@realMorgon
Copy link
Member

@copilot Are the tests still in a way the db is reset after?

Copy link
Contributor Author

Copilot AI commented Dec 31, 2025

@copilot Are the tests still in a way the db is reset after?

Yes, the database is still reset after each test. All tests use the user_db_transaction and data_db_transaction fixtures which automatically rollback all changes in their finally block (lines 36 and 66 in conftest.py).

This includes:

  • All original tests
  • All new tests I added (test_user_handler.py, test_team_handler.py, test_table_operations.py, test_table_permissions.py)
  • The new helper fixtures (test_user, test_project, test_table) - they also use the transaction fixtures, so their changes are rolled back too

Each test runs in complete isolation with a clean database state.

@realMorgon
Copy link
Member

@copilot I see you are using much "str(project_id)". It seems i didn't change all the functions to use UUIDs as parameters. Please take care of this.
Also: Is there a way to test the website part of the project? If so implement it please

- Update table_handler.py functions to accept UUID directly instead of string
  * create_table now takes project_id: UUID
  * set_cell_value now takes project_id: UUID
  * get_cell_value now takes project_id: UUID
- Remove str(project_id) calls from all test files
- Add comprehensive web route tests (test_web_routes.py)
  * Index/homepage tests
  * Login/logout functionality
  * Dashboard access control
  * Error page tests (403, 404, 500)
  * Static file serving
  * Middleware and headers
- Add @pytest.mark.web marker for web tests
- Update tests/README.md with web test documentation

Co-authored-by: realMorgon <81616308+realMorgon@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Dec 31, 2025

@copilot I see you are using much "str(project_id)". It seems i didn't change all the functions to use UUIDs as parameters. Please take care of this.
Also: Is there a way to test the website part of t...

Fixed in commit d3deb5f:

UUID Handling:

  • Updated create_table, set_cell_value, and get_cell_value in table_handler.py to accept project_id: UUID directly
  • Removed all str(project_id) calls from test files
  • Functions now handle UUID-to-string conversion internally where needed for SQL queries
  • This makes the API more type-safe and consistent

Web Tests:

  • Added test_web_routes.py with 15 tests covering:
    • Homepage and login pages
    • Login/logout functionality
    • Dashboard access control
    • Error pages (403, 404, 500)
    • Static file serving
    • Session middleware and custom headers
  • Added @pytest.mark.web marker for selective test execution
  • Run with: pytest -m web

Total test count increased from 36 to 51 tests.

from httpx import AsyncClient
from fastapi import status
from Main import app
from backend.user_management.user_handler import create_user
Copilot AI changed the title Add comprehensive test coverage for untested backend functions Add comprehensive test coverage for untested backend functions and web routes Dec 31, 2025
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