Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix integration and unit tests #912

Merged
merged 9 commits into from
Jan 22, 2025
Merged

Fix integration and unit tests #912

merged 9 commits into from
Jan 22, 2025

Conversation

tianjing-li
Copy link
Collaborator

@tianjing-li tianjing-li commented Jan 17, 2025

AI Description

This PR introduces several changes to the backend codebase, primarily focusing on database operations, deployment handling, and testing.

  • Database Operations:
    • The seed_default_organization and delete_default_organization functions are introduced in src/backend/database_models/seeders/organization_seed.py, replacing the previous deployments_models_seed and delete_default_models functions. These new functions handle seeding and deleting default organizations, addressing an issue with seed data and invalid config data.
    • The DATABASE_URL environment variable is updated in various test files (src/backend/tests/integration/conftest.py, src/backend/tests/unit/conftest.py) to use a default value of postgresql://postgres:postgres@localhost:5433 if not set.
  • Deployment Handling:
    • The DeploymentNotFoundError exception is now caught in src/backend/chat/custom/utils.py and src/backend/services/request_validators.py, ensuring proper handling of deployment-related errors.
    • The create_db_deployment function in src/backend/services/deployment.py now returns the created deployment definition, allowing for further processing if needed.
    • The test_create_agent_deployment_not_in_db function in src/backend/tests/integration/routers/test_agent.py now checks if the cohere_deployment exists before deleting it.
  • Testing:
    • The test_search_conversations and test_search_conversations_no_conversations functions in src/backend/tests/integration/routers/test_conversation.py are now skipped if the COHERE_API_KEY environment variable is not set, ensuring that tests requiring the API key are not run without it.
    • The test_set_env_vars_with_invalid_deployment_name function in src/backend/tests/unit/routers/test_deployment.py now uses session_client instead of client to make the HTTP request, aligning with the updated exception handling.
    • The test_get_deployment_definition_by_name_no_db_deployments function in src/backend/tests/unit/routers/test_chat.py now includes additional assertions to verify the returned deployment definition's name, models, class name, and config, ensuring a more comprehensive test.
  • Miscellaneous:
    • The run-integration-tests target in Makefile now uses poetry run pytest instead of docker compose run --rm --build backend poetry run pytest, simplifying the command and removing the need for Docker.
    • The DATABASE_URL in src/backend/pytest_integration.ini is updated to use postgresql://postgres:postgres@localhost:5433, aligning with the changes in the test files.
    • The default_deployment in src/backend/tests/unit/configuration.yaml is now set to cohere_platform.
    • A new engine_chat fixture is added in src/backend/tests/unit/conftest.py to provide a SQLAlchemy engine for chat-related tests, ensuring proper isolation and setup for chat-specific database operations.

@tianjing-li tianjing-li changed the title Fix integration and unit tests [WIP] Fix integration and unit tests Jan 17, 2025
@codecov-commenter
Copy link

codecov-commenter commented Jan 22, 2025

Codecov Report

Attention: Patch coverage is 88.23529% with 6 lines in your changes missing coverage. Please review.

Project coverage is 77.23%. Comparing base (ae21b64) to head (20ca1bc).

Files with missing lines Patch % Lines
...ckend/database_models/seeders/organization_seed.py 72.72% 3 Missing ⚠️
...s/2024_08_01_117f0d9b1d3d_seed_deployments_data.py 66.66% 1 Missing ⚠️
src/backend/chat/custom/utils.py 0.00% 1 Missing ⚠️
src/backend/tests/unit/conftest.py 95.83% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #912      +/-   ##
==========================================
+ Coverage   76.75%   77.23%   +0.48%     
==========================================
  Files         272      281       +9     
  Lines       10638    11461     +823     
==========================================
+ Hits         8165     8852     +687     
- Misses       2473     2609     +136     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Collaborator

@EugeneLightsOn EugeneLightsOn left a comment

Choose a reason for hiding this comment

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

lgtm

@tianjing-li tianjing-li changed the title [WIP] Fix integration and unit tests Fix integration and unit tests Jan 22, 2025
@tianjing-li tianjing-li merged commit d966233 into main Jan 22, 2025
9 checks passed
@tianjing-li tianjing-li deleted the fix-integration-tests branch January 22, 2025 14:36
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.

3 participants