Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 31, 2025

Tests in test_table_operations.py and test_table_permissions.py were duplicating user/project/table creation logic instead of using the test_user, test_project, and test_table fixtures from conftest.py.

Changes

  • test_table_operations.py: Use test_project and test_table fixtures (280→161 lines, -42%)
  • test_table_permissions.py: Use test_user and test_project fixtures (263→187 lines, -29%)
  • tests/README.md: Document fixture usage patterns and when to prefer manual creation

Example

Before:

async def test_set_and_get_cell_value(user_db_transaction, data_db_transaction):
    user_id = await create_user(
        user_connection=user_db_transaction,
        userName="cell_test_user",
        email="cell@test.com",
        password="SecurePass123!",
        lastName="Cell",
        firstName="Test"
    )
    
    project_id = await create_project(
        user_connection=user_db_transaction,
        data_connection=data_db_transaction,
        project_name="Cell Test Project",
        owner_id=user_id
    )
    
    table_name = "cell_test_table"
    await create_table(data_db_transaction, table_name, project_id)
    
    await set_cell_value(data_db_transaction, project_id, table_name, 1, 1, "Test Value")
    value = await get_cell_value(data_db_transaction, project_id, table_name, 1, 1)
    assert value == "Test Value"

After:

async def test_set_and_get_cell_value(data_db_transaction, test_table):
    table_name, project_id = test_table
    
    await set_cell_value(data_db_transaction, project_id, table_name, 1, 1, "Test Value")
    value = await get_cell_value(data_db_transaction, project_id, table_name, 1, 1)
    assert value == "Test Value"

Not Changed

test_user_handler.py and test_team_handler.py continue manual creation - they validate creation functions and require specific user properties per test.

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>
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
Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>
Copilot AI and others added 2 commits January 29, 2026 11:49
- Update test_table_operations.py to use test_project and test_table fixtures
  - Reduces code duplication by ~20 lines per test
  - Makes tests more concise and focused on what they're testing

- Update test_table_permissions.py to use test_user and test_project fixtures
  - Still creates second user manually since tests need two distinct users
  - Eliminates repetitive project creation code

Benefits:
- Tests are now ~50% shorter and easier to read
- Reduced boilerplate setup code
- Better maintainability - fixture changes propagate automatically
- Consistent test data across tests using fixtures

Co-authored-by: realMorgon <81616308+realMorgon@users.noreply.github.com>
- Add section on when to use fixtures vs manual creation
- Include example showing fixture usage
- Document the helper fixtures with their dependencies
- Provide clear guidance for test writers

This completes the refactoring to use helper fixtures consistently.

Co-authored-by: realMorgon <81616308+realMorgon@users.noreply.github.com>
Copilot AI changed the title Add comprehensive test coverage for untested backend functions and web routes Refactor tests to use helper fixtures, eliminating 195 lines of boilerplate Jan 29, 2026
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