-
Notifications
You must be signed in to change notification settings - Fork 10
Fix inter-service communication patterns #585
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
chrisaddy
merged 24 commits into
master
from
06-02-fix_inter-service_communication_patterns
Jun 6, 2025
Merged
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
8373092
Fix inter-service communication patterns
forstmeier 22a9c60
Update application/positionmanager/src/positionmanager/clients.py
chrisaddy 2887ceb
Merge branch 'master' into 06-02-fix_inter-service_communication_patt…
chrisaddy 00ffd1d
Integrate predictionengine into the workflows
forstmeier 49b392f
Merge pull request #588 from pocketsizefund/06-04-integrate_predictio…
chrisaddy a1c7e64
Merge branch 'master' into 06-02-fix_inter-service_communication_patt…
chrisaddy b870adf
rebasing master
chrisaddy 3b05fa4
Various fixes
forstmeier c329c4b
Add basic tests for datamanager
forstmeier 3e4f77c
Merge pull request #590 from pocketsizefund/06-04-add_basic_tests_for…
chrisaddy 8f42c14
Merge branch 'master' into 06-02-fix_inter-service_communication_patt…
forstmeier f872aae
Remove Flox environment variables to fix breaking tests
forstmeier dc37574
Merge branch 'master' into 06-02-fix_inter-service_communication_patt…
forstmeier 14a6984
fix some linting issues
chrisaddy 43af2da
Fix inter-service communication patterns
forstmeier 0be3104
Integrate predictionengine into the workflows
forstmeier 7a2cb67
fix some linting issues
chrisaddy 3a43f98
fix linting
chrisaddy a75adf0
Fix inter-service communication patterns
forstmeier 494b0a5
Integrate predictionengine into the workflows
forstmeier 973ad6b
remove vars
chrisaddy 19107c0
Merge pull request #591 from pocketsizefund/fix/linting
chrisaddy 70739d6
Add linting fixes
forstmeier e0bbcb6
Fix CodeRabbit feedback
forstmeier 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
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 |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| FROM python:3.12 | ||
| FROM python:3.12.10 | ||
|
|
||
| COPY --from=ghcr.io/astral-sh/uv:latest /uv /bin/uv | ||
|
|
||
|
|
||
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
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,93 @@ | ||
| import unittest | ||
| from datetime import date | ||
| from unittest.mock import MagicMock, patch | ||
|
|
||
| from fastapi import status | ||
| from fastapi.testclient import TestClient | ||
|
|
||
| from application.datamanager.src.datamanager.main import application | ||
| from application.datamanager.src.datamanager.models import BarsSummary, SummaryDate | ||
|
|
||
| client = TestClient(application) | ||
|
|
||
|
|
||
| def test_health_check() -> None: | ||
| response = client.get("/health") | ||
| assert response.status_code == status.HTTP_200_OK | ||
|
|
||
|
|
||
| class TestDataManagerModels(unittest.TestCase): | ||
| def test_summary_date_default(self) -> None: | ||
| summary_date = SummaryDate() | ||
| assert isinstance(summary_date.date, date) | ||
|
|
||
| def test_summary_date_with_date(self) -> None: | ||
| test_date = date(2023, 1, 1) | ||
| summary_date = SummaryDate(date=test_date) | ||
| assert summary_date.date == test_date | ||
|
|
||
| def test_summary_date_string_parsing(self) -> None: | ||
| summary_date = SummaryDate(date="2023-01-01") # type: ignore | ||
| assert summary_date.date == date(2023, 1, 1) | ||
|
|
||
| def test_bars_summary_creation(self) -> None: | ||
| bars_summary = BarsSummary(date="2023-01-01", count=100) | ||
| assert bars_summary.date == "2023-01-01" | ||
| assert bars_summary.count == 100 # noqa: PLR2004 | ||
|
|
||
|
|
||
| class TestEquityBarsEndpoints(unittest.TestCase): | ||
| def test_get_equity_bars_missing_parameters(self) -> None: | ||
| response = client.get("/equity-bars") | ||
| assert response.status_code == status.HTTP_422_UNPROCESSABLE_ENTITY | ||
|
|
||
| def test_get_equity_bars_invalid_date_format(self) -> None: | ||
| response = client.get( | ||
| "/equity-bars", | ||
| params={"start_date": "invalid-date", "end_date": "2023-01-02"}, | ||
| ) | ||
| assert response.status_code == status.HTTP_422_UNPROCESSABLE_ENTITY | ||
|
|
||
| def test_post_equity_bars_missing_body(self) -> None: | ||
| response = client.post("/equity-bars") | ||
| assert response.status_code == status.HTTP_422_UNPROCESSABLE_ENTITY | ||
|
|
||
| def test_post_equity_bars_invalid_date(self) -> None: | ||
| response = client.post("/equity-bars", json={"date": "invalid-date"}) | ||
| assert response.status_code == status.HTTP_422_UNPROCESSABLE_ENTITY | ||
|
|
||
| def test_delete_equity_bars_missing_body(self) -> None: | ||
| response = client.request("DELETE", "/equity-bars") | ||
| assert response.status_code == status.HTTP_422_UNPROCESSABLE_ENTITY | ||
|
|
||
| def test_delete_equity_bars_invalid_date(self) -> None: | ||
| response = client.request( | ||
| "DELETE", "/equity-bars", json={"date": "invalid-date"} | ||
| ) | ||
| assert response.status_code == status.HTTP_422_UNPROCESSABLE_ENTITY | ||
|
|
||
| @patch("application.datamanager.src.datamanager.main.duckdb") | ||
| def test_get_equity_bars_database_error(self, mock_duckdb: MagicMock) -> None: | ||
| from duckdb import IOException | ||
|
|
||
| mock_connection = MagicMock() | ||
| mock_connection.execute.side_effect = IOException("Database error") | ||
| mock_duckdb.connect.return_value = mock_connection | ||
|
|
||
| mock_settings = MagicMock() | ||
| mock_settings.gcp.bucket.name = "test-bucket" | ||
|
|
||
| with patch.object(application, "state") as mock_app_state: | ||
| mock_app_state.connection = mock_connection | ||
| mock_app_state.settings = mock_settings | ||
|
|
||
| response = client.get( | ||
| "/equity-bars", | ||
| params={"start_date": "2023-01-01", "end_date": "2023-01-02"}, | ||
| ) | ||
|
|
||
| assert response.status_code == status.HTTP_500_INTERNAL_SERVER_ERROR | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| unittest.main() |
131 changes: 131 additions & 0 deletions
131
application/datamanager/tests/test_datamanager_models.py
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,131 @@ | ||
| import unittest | ||
| from datetime import date | ||
|
|
||
| import pytest | ||
| from pydantic import ValidationError | ||
|
|
||
| from application.datamanager.src.datamanager.models import ( | ||
| BarsSummary, | ||
| DateRange, | ||
| SummaryDate, | ||
| ) | ||
|
|
||
|
|
||
| class TestSummaryDate(unittest.TestCase): | ||
| def test_summary_date_initialization_default(self) -> None: | ||
| summary_date = SummaryDate() | ||
| assert isinstance(summary_date.date, date) | ||
|
|
||
| def test_summary_date_initialization_with_date(self) -> None: | ||
| test_date = date(2023, 5, 15) | ||
| summary_date = SummaryDate(date=test_date) | ||
| assert summary_date.date == test_date | ||
|
|
||
| def test_summary_date_string_parsing_iso_format(self) -> None: | ||
| summary_date = SummaryDate(date="2023-5-15") # type: ignore | ||
| assert summary_date.date == date(2023, 5, 15) | ||
|
forstmeier marked this conversation as resolved.
|
||
|
|
||
| def test_summary_date_string_parsing_slash_format(self) -> None: | ||
| summary_date = SummaryDate(date="2023/05/15") # type: ignore | ||
| assert summary_date.date == date(2023, 5, 15) | ||
|
|
||
| def test_summary_date_invalid_format(self) -> None: | ||
| with pytest.raises(ValidationError, match="Invalid date format"): | ||
| SummaryDate(date="invalid-date") # type: ignore | ||
|
|
||
| def test_summary_date_invalid_date_values(self) -> None: | ||
| with pytest.raises(ValidationError): | ||
| SummaryDate(date="2023-13-01") # type: ignore | ||
|
|
||
| def test_summary_date_json_encoder(self) -> None: | ||
| test_date = date(2023, 5, 15) | ||
| summary_date = SummaryDate(date=test_date) | ||
| json_data = summary_date.model_dump(mode="json") | ||
| assert json_data["date"] == "2023/05/15" | ||
|
|
||
|
|
||
| class TestDateRange(unittest.TestCase): | ||
| def test_date_range_valid(self) -> None: | ||
| start_date = date(2023, 1, 1) | ||
| end_date = date(2023, 12, 31) | ||
| date_range = DateRange(start=start_date, end=end_date) | ||
|
|
||
| assert date_range.start == start_date | ||
| assert date_range.end == end_date | ||
|
|
||
| def test_date_range_same_dates(self) -> None: | ||
| same_date = date(2023, 5, 15) | ||
| with pytest.raises(ValidationError, match="End date must be after start date"): | ||
| DateRange(start=same_date, end=same_date) | ||
|
|
||
| def test_date_range_end_before_start(self) -> None: | ||
| start_date = date(2023, 12, 31) | ||
| end_date = date(2023, 1, 1) | ||
| with pytest.raises(ValidationError, match="End date must be after start date"): | ||
| DateRange(start=start_date, end=end_date) | ||
|
|
||
| def test_date_range_valid_one_day_apart(self) -> None: | ||
| start_date = date(2023, 5, 15) | ||
| end_date = date(2023, 5, 16) | ||
| date_range = DateRange(start=start_date, end=end_date) | ||
|
|
||
| assert date_range.start == start_date | ||
| assert date_range.end == end_date | ||
|
|
||
|
|
||
| class TestBarsSummary(unittest.TestCase): | ||
| def test_bars_summary_initialization(self) -> None: | ||
| bars_summary = BarsSummary(date="2023-05-15", count=1500) | ||
|
|
||
| assert bars_summary.date == "2023-05-15" | ||
| assert bars_summary.count == 1500 # noqa: PLR2004 | ||
|
|
||
| def test_bars_summary_zero_count(self) -> None: | ||
| bars_summary = BarsSummary(date="2023-05-15", count=0) | ||
|
|
||
| assert bars_summary.date == "2023-05-15" | ||
| assert bars_summary.count == 0 | ||
|
|
||
| def test_bars_summary_negative_count(self) -> None: | ||
| bars_summary = BarsSummary(date="2023-05-15", count=-1) | ||
|
|
||
| assert bars_summary.date == "2023-05-15" | ||
| assert bars_summary.count == -1 | ||
|
|
||
| def test_bars_summary_json_serialization(self) -> None: | ||
| bars_summary = BarsSummary(date="2023-05-15", count=1500) | ||
| json_data = bars_summary.model_dump() | ||
|
|
||
| assert json_data == {"date": "2023-05-15", "count": 1500} | ||
|
|
||
| def test_bars_summary_from_dict(self) -> None: | ||
| data = {"date": "2023-05-15", "count": 1500} | ||
| bars_summary = BarsSummary.model_validate(data) | ||
|
|
||
| assert bars_summary.date == "2023-05-15" | ||
| assert bars_summary.count == 1500 # noqa: PLR2004 | ||
|
|
||
|
|
||
| class TestModelIntegration(unittest.TestCase): | ||
| def test_summary_date_to_bars_summary(self) -> None: | ||
| summary_date = SummaryDate(date="2023-05-15") # type: ignore | ||
| bars_summary = BarsSummary( | ||
| date=summary_date.date.strftime("%Y-%m-%d"), count=100 | ||
| ) | ||
|
|
||
| assert bars_summary.date == "2023-05-15" | ||
| assert bars_summary.count == 100 # noqa: PLR2004 | ||
|
|
||
| def test_multiple_model_validation(self) -> None: | ||
| summary_date = SummaryDate(date="2023-05-15") # type: ignore | ||
| date_range = DateRange(start=date(2023, 1, 1), end=date(2023, 12, 31)) | ||
| bars_summary = BarsSummary(date="2023-05-15", count=1000) | ||
|
|
||
| assert summary_date.date == date(2023, 5, 15) | ||
| assert date_range.start == date(2023, 1, 1) | ||
| assert date_range.end == date(2023, 12, 31) | ||
| assert bars_summary.count == 1000 # noqa: PLR2004 | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| unittest.main() | ||
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
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
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.