-
Notifications
You must be signed in to change notification settings - Fork 1.4k
feat: add image aspect ratio setting #184
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| """ | ||
| Settings API unit tests | ||
| """ | ||
|
|
||
| import pytest | ||
|
|
||
| from conftest import assert_success_response, assert_error_response | ||
|
|
||
|
|
||
| class TestSettingsAspectRatio: | ||
| """Image aspect ratio settings tests""" | ||
|
|
||
| def test_get_settings_includes_image_aspect_ratio(self, client): | ||
| response = client.get("/api/settings") | ||
| data = assert_success_response(response) | ||
| assert data["data"]["image_aspect_ratio"] == "16:9" | ||
|
|
||
| def test_update_settings_persists_image_aspect_ratio(self, client): | ||
| response = client.put("/api/settings", json={"image_aspect_ratio": "4:3"}) | ||
| data = assert_success_response(response) | ||
| assert data["data"]["image_aspect_ratio"] == "4:3" | ||
| assert client.application.config["DEFAULT_ASPECT_RATIO"] == "4:3" | ||
|
|
||
| response = client.get("/api/settings") | ||
| data = assert_success_response(response) | ||
| assert data["data"]["image_aspect_ratio"] == "4:3" | ||
|
|
||
| def test_update_settings_normalizes_image_aspect_ratio(self, client): | ||
| response = client.put("/api/settings", json={"image_aspect_ratio": "1920:1080"}) | ||
| data = assert_success_response(response) | ||
| assert data["data"]["image_aspect_ratio"] == "16:9" | ||
|
|
||
| @pytest.mark.parametrize( | ||
| "value", | ||
| [ | ||
| "", | ||
| None, | ||
| "16x9", | ||
| "16:0", | ||
| "0:16", | ||
| "abc", | ||
| "1:1000", | ||
| "1000:1", | ||
| ], | ||
| ) | ||
| def test_update_settings_rejects_invalid_image_aspect_ratio(self, client, value): | ||
| response = client.put("/api/settings", json={"image_aspect_ratio": value}) | ||
| assert_error_response(response, expected_status=400) | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,6 +15,7 @@ dependencies = [ | |
| "python-pptx>=1.0.0", | ||
| "python-dotenv>=1.0.1", | ||
| "reportlab>=4.1.0", | ||
| "requests>=2.0.0", | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The integration tests ( |
||
| "werkzeug>=3.0.1", | ||
| "markitdown[all]", | ||
| "tenacity>=9.0.0", | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The check
len(normalized) > 10seems arbitrary and could lead to valid, simplified aspect ratios being rejected. For example, a ratio like10000:1would simplify to10000:1(length 7) but100000:1would simplify to100000:1(length 8). If a user inputs1000000000:1, it would simplify to1000000000:1(length 10), which is fine. However, if a ratio like1234567890:1is simplified to1234567890:1(length 11), it would be rejected. Given that custom ratios are allowed, this length check might be too restrictive and not directly related to the validity or extremity of the ratio itself. Consider removing this check or basing it on a more logical constraint if there's a specific reason for it.