Skip to content

Commit c0da8a7

Browse files
committed
Reference the local image by its real filename in the e2e fixture
Drop the {{LOCAL_IMAGE}} placeholder in favour of a plain relative filename (local_image.png), matching a real authoring workflow. The test renders from the fixtures directory so the relative path resolves, as get_image expects.
1 parent 96b0097 commit c0da8a7

2 files changed

Lines changed: 10 additions & 9 deletions

File tree

‎tests/substack/fixtures/full_features.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ plain code block without a language
5757

5858
[![Linked image alt](https://upload.wikimedia.org/wikipedia/commons/4/47/PNG_transparency_demonstration_1.png)](https://example.com/target)
5959

60-
![A locally uploaded image]({{LOCAL_IMAGE}})
60+
![A locally uploaded image](local_image.png)
6161

6262
`inline code with [^1] inside stays literal`
6363

‎tests/substack/test_end_to_end.py‎

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@
3838
TITLE = "python-substack e2e feature test"
3939
SUBTITLE = "Automated round-trip fixture"
4040

41-
LOCAL_IMAGE_FILE = FIXTURES / "local_image.png"
42-
LOCAL_IMAGE_TOKEN = "{{LOCAL_IMAGE}}"
4341
LOCAL_IMAGE_ALT = "A locally uploaded image"
4442

4543

@@ -118,13 +116,16 @@ def walk(node):
118116
def _roundtrip(api: Api):
119117
"""Post the fixture as a draft, read it back, and return its stored content."""
120118
markdown = MARKDOWN_FILE.read_text(encoding="utf-8")
121-
# The local-image path is environment-specific, so it lives as a token in the
122-
# fixture. We resolve it to a path relative to the current directory: get_image()
123-
# uploads any path that os.path.exists(), and a relative path avoids the
124-
# leading-slash handling that from_markdown applies to web-root paths.
125-
markdown = markdown.replace(LOCAL_IMAGE_TOKEN, os.path.relpath(LOCAL_IMAGE_FILE))
126119
post = Post(TITLE, SUBTITLE, user_id=api.get_user_id())
127-
post.from_markdown(markdown, api=api)
120+
# Markdown image paths resolve relative to the working directory (this is how
121+
# get_image uploads local files), so render from the fixtures directory just as
122+
# a user authoring alongside their images would.
123+
previous_cwd = os.getcwd()
124+
os.chdir(FIXTURES)
125+
try:
126+
post.from_markdown(markdown, api=api)
127+
finally:
128+
os.chdir(previous_cwd)
128129
draft = api.post_draft(post.get_draft())
129130
draft_id = draft.get("id")
130131
try:

0 commit comments

Comments
 (0)