-
Notifications
You must be signed in to change notification settings - Fork 1k
Comprehensive Integration Test Suite #140
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
Merged
cyclotruc
merged 12 commits into
coderamp-labs:main
from
RyanL2004:flow-integration-tests
Jan 24, 2025
Merged
Changes from 5 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
b5ffa5f
Refactor CLI to wrap async logic with a sync command function (#136)
filipchristiansen 885b57e
Merge branch 'main' into flow-integration-tests
RyanL2004 ddc9382
Merge branch 'main' of https://github.com/RyanL2004/gitingest into fl…
RyanL2004 1846cb7
fix: Correct static directory path for serving static files
RyanL2004 26fc51e
Merge branch 'flow-integration-tests' of https://github.com/RyanL2004…
RyanL2004 c19a379
fix: Correct static directory path for StaticFiles mount
RyanL2004 98f59a0
refactor: Skipping static file mount if Static file not found
RyanL2004 d07d476
Merge branch 'main' into flow-integration-tests
RyanL2004 4951728
Merge branch 'main' into flow-integration-tests
RyanL2004 d943081
Update: Branch
RyanL2004 254ff37
Merge branch 'main' of https://github.com/RyanL2004/gitingest into fl…
RyanL2004 73a2ba4
chore: adapt PR to refactored codebase and resolve conflicts
RyanL2004 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,145 @@ | ||
| """ | ||
| Integration tests for GitIngest. | ||
| These tests cover core functionalities, edge cases, and concurrency handling. | ||
| """ | ||
|
|
||
| import shutil | ||
| from concurrent.futures import ThreadPoolExecutor | ||
| from pathlib import Path | ||
| from unittest.mock import patch | ||
|
|
||
| import pytest | ||
| from fastapi.testclient import TestClient | ||
|
|
||
| from main import app | ||
|
|
||
| BASE_DIR = Path(__file__).resolve().parent.parent | ||
| TEMPLATE_DIR = BASE_DIR / "src" / "templates" | ||
|
|
||
|
|
||
| @pytest.fixture(scope="module") | ||
| def test_client(): | ||
| """Create a test client fixture.""" | ||
| with TestClient(app) as client: | ||
| client.headers.update({"Host": "localhost"}) | ||
| yield client | ||
|
|
||
|
|
||
| @pytest.fixture(scope="module", autouse=True) | ||
| def mock_templates(): | ||
| """Mock Jinja2 template rendering to bypass actual file loading.""" | ||
| with patch("starlette.templating.Jinja2Templates.TemplateResponse") as mock_template: | ||
| mock_template.return_value = "Mocked Template Response" | ||
| yield mock_template | ||
|
|
||
|
|
||
| def cleanup_temp_directories(): | ||
| temp_dir = Path("/tmp/gitingest") | ||
| if temp_dir.exists(): | ||
| try: | ||
| shutil.rmtree(temp_dir) | ||
| except PermissionError as e: | ||
| print(f"Error cleaning up {temp_dir}: {e}") | ||
|
|
||
|
|
||
| @pytest.fixture(scope="module", autouse=True) | ||
| def cleanup(): | ||
| """Cleanup temporary directories after tests.""" | ||
| yield | ||
| cleanup_temp_directories() | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_remote_repository_analysis(test_client): # pylint: disable=redefined-outer-name | ||
| """Test the complete flow of analyzing a remote repository.""" | ||
| form_data = { | ||
| "input_text": "https://github.com/octocat/Hello-World", | ||
| "max_file_size": "243", | ||
| "pattern_type": "exclude", | ||
| "pattern": "", | ||
| } | ||
|
|
||
| response = test_client.post("/", data=form_data) | ||
| assert response.status_code == 200, f"Form submission failed: {response.text}" | ||
| assert "Mocked Template Response" in response.text | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_invalid_repository_url(test_client): # pylint: disable=redefined-outer-name | ||
| """Test handling of an invalid repository URL.""" | ||
| form_data = { | ||
| "input_text": "https://github.com/nonexistent/repo", | ||
| "max_file_size": "243", | ||
| "pattern_type": "exclude", | ||
| "pattern": "", | ||
| } | ||
|
|
||
| response = test_client.post("/", data=form_data) | ||
| assert response.status_code == 200, f"Request failed: {response.text}" | ||
| assert "Mocked Template Response" in response.text | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_large_repository(test_client): # pylint: disable=redefined-outer-name | ||
| """Simulate analysis of a large repository with nested folders.""" | ||
| form_data = { | ||
| "input_text": "https://github.com/large/repo-with-many-files", | ||
| "max_file_size": "243", | ||
| "pattern_type": "exclude", | ||
| "pattern": "", | ||
| } | ||
|
|
||
| response = test_client.post("/", data=form_data) | ||
| assert response.status_code == 200, f"Request failed: {response.text}" | ||
| assert "Mocked Template Response" in response.text | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_concurrent_requests(test_client): # pylint: disable=redefined-outer-name | ||
| """Test handling of multiple concurrent requests.""" | ||
|
|
||
| def make_request(): | ||
| form_data = { | ||
| "input_text": "https://github.com/octocat/Hello-World", | ||
| "max_file_size": "243", | ||
| "pattern_type": "exclude", | ||
| "pattern": "", | ||
| } | ||
| response = test_client.post("/", data=form_data) | ||
| assert response.status_code == 200, f"Request failed: {response.text}" | ||
| assert "Mocked Template Response" in response.text | ||
|
|
||
| with ThreadPoolExecutor(max_workers=5) as executor: | ||
| futures = [executor.submit(make_request) for _ in range(5)] | ||
| for future in futures: | ||
| future.result() | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_large_file_handling(test_client): # pylint: disable=redefined-outer-name | ||
| """Test handling of repositories with large files.""" | ||
| form_data = { | ||
| "input_text": "https://github.com/octocat/Hello-World", | ||
| "max_file_size": "1", | ||
| "pattern_type": "exclude", | ||
| "pattern": "", | ||
| } | ||
|
|
||
| response = test_client.post("/", data=form_data) | ||
| assert response.status_code == 200, f"Request failed: {response.text}" | ||
| assert "Mocked Template Response" in response.text | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_repository_with_patterns(test_client): # pylint: disable=redefined-outer-name | ||
| """Test repository analysis with include/exclude patterns.""" | ||
| form_data = { | ||
| "input_text": "https://github.com/octocat/Hello-World", | ||
| "max_file_size": "243", | ||
| "pattern_type": "include", | ||
| "pattern": "*.md", | ||
| } | ||
|
|
||
| response = test_client.post("/", data=form_data) | ||
| assert response.status_code == 200, f"Request failed: {response.text}" | ||
| assert "Mocked Template Response" in response.text |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.