Skip to content

Commit 58bf507

Browse files
♻️(backend) rename convert_markdown to convert (#1114)
Renamed the `convert_markdown` method to `convert` to prepare for an all-purpose conversion endpoint, enabling support for multiple formats and simplifying future extension. Signed-off-by: Stephan Meijer <[email protected]>
1 parent e148c23 commit 58bf507

File tree

4 files changed

+20
-22
lines changed

4 files changed

+20
-22
lines changed

src/backend/core/api/serializers.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -408,9 +408,7 @@ def create(self, validated_data):
408408
language = user.language or language
409409

410410
try:
411-
document_content = YdocConverter().convert_markdown(
412-
validated_data["content"]
413-
)
411+
document_content = YdocConverter().convert(validated_data["content"])
414412
except ConversionError as err:
415413
raise serializers.ValidationError(
416414
{"content": ["Could not convert content"]}

src/backend/core/services/converter_services.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def auth_header(self):
3434
# Note: Yprovider microservice accepts only raw token, which is not recommended
3535
return settings.Y_PROVIDER_API_KEY
3636

37-
def convert_markdown(self, text):
37+
def convert(self, text):
3838
"""Convert a Markdown text into our internal format using an external microservice."""
3939

4040
if not text:

src/backend/core/tests/documents/test_api_documents_create_for_owner.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@
2323

2424
@pytest.fixture
2525
def mock_convert_md():
26-
"""Mock YdocConverter.convert_markdown to return a converted content."""
26+
"""Mock YdocConverter.convert to return a converted content."""
2727
with patch.object(
2828
YdocConverter,
29-
"convert_markdown",
29+
"convert",
3030
return_value="Converted document content",
3131
) as mock:
3232
yield mock

src/backend/core/tests/test_services_converter_services.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ def test_auth_header(settings):
2121
assert converter.auth_header == "test-key"
2222

2323

24-
def test_convert_markdown_empty_text():
24+
def test_convert_empty_text():
2525
"""Should raise ValidationError when text is empty."""
2626
converter = YdocConverter()
2727
with pytest.raises(ValidationError, match="Input text cannot be empty"):
28-
converter.convert_markdown("")
28+
converter.convert("")
2929

3030

3131
@patch("requests.post")
32-
def test_convert_markdown_service_unavailable(mock_post):
32+
def test_convert_service_unavailable(mock_post):
3333
"""Should raise ServiceUnavailableError when service is unavailable."""
3434
converter = YdocConverter()
3535

@@ -39,11 +39,11 @@ def test_convert_markdown_service_unavailable(mock_post):
3939
ServiceUnavailableError,
4040
match="Failed to connect to conversion service",
4141
):
42-
converter.convert_markdown("test text")
42+
converter.convert("test text")
4343

4444

4545
@patch("requests.post")
46-
def test_convert_markdown_http_error(mock_post):
46+
def test_convert_http_error(mock_post):
4747
"""Should raise ServiceUnavailableError when HTTP error occurs."""
4848
converter = YdocConverter()
4949

@@ -55,11 +55,11 @@ def test_convert_markdown_http_error(mock_post):
5555
ServiceUnavailableError,
5656
match="Failed to connect to conversion service",
5757
):
58-
converter.convert_markdown("test text")
58+
converter.convert("test text")
5959

6060

6161
@patch("requests.post")
62-
def test_convert_markdown_invalid_json_response(mock_post):
62+
def test_convert_invalid_json_response(mock_post):
6363
"""Should raise InvalidResponseError when response is not valid JSON."""
6464
converter = YdocConverter()
6565

@@ -71,11 +71,11 @@ def test_convert_markdown_invalid_json_response(mock_post):
7171
InvalidResponseError,
7272
match="Could not parse conversion service response",
7373
):
74-
converter.convert_markdown("test text")
74+
converter.convert("test text")
7575

7676

7777
@patch("requests.post")
78-
def test_convert_markdown_missing_content_field(mock_post, settings):
78+
def test_convert_missing_content_field(mock_post, settings):
7979
"""Should raise MissingContentError when response is missing required field."""
8080

8181
settings.CONVERSION_API_CONTENT_FIELD = "expected_field"
@@ -90,11 +90,11 @@ def test_convert_markdown_missing_content_field(mock_post, settings):
9090
MissingContentError,
9191
match="Response missing required field: expected_field",
9292
):
93-
converter.convert_markdown("test text")
93+
converter.convert("test text")
9494

9595

9696
@patch("requests.post")
97-
def test_convert_markdown_full_integration(mock_post, settings):
97+
def test_convert_full_integration(mock_post, settings):
9898
"""Test full integration with all settings."""
9999

100100
settings.Y_PROVIDER_API_BASE_URL = "http://test.com/"
@@ -110,7 +110,7 @@ def test_convert_markdown_full_integration(mock_post, settings):
110110
mock_response.json.return_value = {"content": expected_content}
111111
mock_post.return_value = mock_response
112112

113-
result = converter.convert_markdown("test markdown")
113+
result = converter.convert("test markdown")
114114

115115
assert result == expected_content
116116
mock_post.assert_called_once_with(
@@ -126,7 +126,7 @@ def test_convert_markdown_full_integration(mock_post, settings):
126126

127127

128128
@patch("requests.post")
129-
def test_convert_markdown_timeout(mock_post):
129+
def test_convert_timeout(mock_post):
130130
"""Should raise ServiceUnavailableError when request times out."""
131131
converter = YdocConverter()
132132

@@ -136,12 +136,12 @@ def test_convert_markdown_timeout(mock_post):
136136
ServiceUnavailableError,
137137
match="Failed to connect to conversion service",
138138
):
139-
converter.convert_markdown("test text")
139+
converter.convert("test text")
140140

141141

142-
def test_convert_markdown_none_input():
142+
def test_convert_none_input():
143143
"""Should raise ValidationError when input is None."""
144144
converter = YdocConverter()
145145

146146
with pytest.raises(ValidationError, match="Input text cannot be empty"):
147-
converter.convert_markdown(None)
147+
converter.convert(None)

0 commit comments

Comments
 (0)