Skip to content

Commit 1fdf204

Browse files
tests: add custom color profile
Assisted-by: Codex
1 parent d4c72c5 commit 1fdf204

2 files changed

Lines changed: 48 additions & 11 deletions

File tree

tests/live/test_live_convert_colors.py

Lines changed: 48 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@
1414
tuple[PdfColorProfile, ...],
1515
get_args(PdfColorProfile),
1616
)
17-
PRESET_COLOR_PROFILES: tuple[PdfColorProfile, ...] = tuple(
18-
color_profile for color_profile in ALL_COLOR_PROFILES if color_profile != "custom"
19-
)
2017

2118

2219
@pytest.fixture(scope="module")
@@ -32,34 +29,60 @@ def uploaded_pdf_for_color_conversion(
3229
return client.files.create_from_paths([resource])[0]
3330

3431

32+
def _upload_custom_profile_for_color_conversion(
33+
pdfrest_api_key: str,
34+
pdfrest_live_base_url: str,
35+
) -> PdfRestFile:
36+
resource = get_test_resource_path("custom.icc")
37+
with PdfRestClient(
38+
api_key=pdfrest_api_key,
39+
base_url=pdfrest_live_base_url,
40+
) as client:
41+
return client.files.create_from_paths([resource])[0]
42+
43+
3544
@pytest.mark.parametrize(
3645
"color_profile",
3746
[
3847
pytest.param(color_profile, id=f"color-profile-{color_profile}")
39-
for color_profile in PRESET_COLOR_PROFILES
48+
for color_profile in ALL_COLOR_PROFILES
4049
],
4150
)
42-
def test_live_convert_colors_presets_success(
51+
def test_live_convert_colors_color_profiles_success(
4352
pdfrest_api_key: str,
4453
pdfrest_live_base_url: str,
4554
uploaded_pdf_for_color_conversion: PdfRestFile,
4655
color_profile: PdfColorProfile,
4756
) -> None:
57+
kwargs: dict[str, PdfColorProfile | PdfRestFile] = {"color_profile": color_profile}
58+
custom_profile: PdfRestFile | None = None
59+
if color_profile == "custom":
60+
custom_profile = _upload_custom_profile_for_color_conversion(
61+
pdfrest_api_key,
62+
pdfrest_live_base_url,
63+
)
64+
kwargs["profile"] = custom_profile
65+
4866
with PdfRestClient(
4967
api_key=pdfrest_api_key,
5068
base_url=pdfrest_live_base_url,
5169
) as client:
5270
response = client.convert_colors(
5371
uploaded_pdf_for_color_conversion,
54-
color_profile=color_profile,
72+
**kwargs,
5573
)
5674

5775
assert response.output_files
5876
output_file = response.output_file
5977
assert output_file.type == "application/pdf"
6078
assert output_file.size > 0
6179
assert response.warning is None
62-
assert str(response.input_id) == str(uploaded_pdf_for_color_conversion.id)
80+
input_ids = {str(file_id) for file_id in response.input_ids}
81+
assert str(uploaded_pdf_for_color_conversion.id) in input_ids
82+
if custom_profile is not None:
83+
assert str(custom_profile.id) in input_ids
84+
else:
85+
assert str(response.input_id) == str(uploaded_pdf_for_color_conversion.id)
6386

6487

6588
@pytest.mark.parametrize(
@@ -102,30 +125,44 @@ def test_live_convert_colors_output_prefix(
102125
"color_profile",
103126
[
104127
pytest.param(color_profile, id=f"color-profile-{color_profile}")
105-
for color_profile in PRESET_COLOR_PROFILES
128+
for color_profile in ALL_COLOR_PROFILES
106129
],
107130
)
108-
async def test_live_async_convert_colors_presets_success(
131+
async def test_live_async_convert_colors_color_profiles_success(
109132
pdfrest_api_key: str,
110133
pdfrest_live_base_url: str,
111134
uploaded_pdf_for_color_conversion: PdfRestFile,
112135
color_profile: PdfColorProfile,
113136
) -> None:
137+
kwargs: dict[str, PdfColorProfile | PdfRestFile] = {"color_profile": color_profile}
138+
custom_profile: PdfRestFile | None = None
139+
if color_profile == "custom":
140+
custom_profile = _upload_custom_profile_for_color_conversion(
141+
pdfrest_api_key,
142+
pdfrest_live_base_url,
143+
)
144+
kwargs["profile"] = custom_profile
145+
114146
async with AsyncPdfRestClient(
115147
api_key=pdfrest_api_key,
116148
base_url=pdfrest_live_base_url,
117149
) as client:
118150
response = await client.convert_colors(
119151
uploaded_pdf_for_color_conversion,
120-
color_profile=color_profile,
152+
**kwargs,
121153
)
122154

123155
assert response.output_files
124156
output_file = response.output_file
125157
assert output_file.type == "application/pdf"
126158
assert output_file.size > 0
127159
assert response.warning is None
128-
assert str(response.input_id) == str(uploaded_pdf_for_color_conversion.id)
160+
input_ids = {str(file_id) for file_id in response.input_ids}
161+
assert str(uploaded_pdf_for_color_conversion.id) in input_ids
162+
if custom_profile is not None:
163+
assert str(custom_profile.id) in input_ids
164+
else:
165+
assert str(response.input_id) == str(uploaded_pdf_for_color_conversion.id)
129166

130167

131168
@pytest.mark.asyncio

tests/resources/custom.icc

912 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)