Skip to content

Commit

Permalink
more tests on new feature
Browse files Browse the repository at this point in the history
  • Loading branch information
alex75 committed Oct 21, 2024
1 parent a584b6e commit 9fb8b76
Showing 1 changed file with 44 additions and 3 deletions.
47 changes: 44 additions & 3 deletions tests/test_30_layout_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,21 @@ def test_manage_image_section(tmpdir, mocker: pytest_mock.MockerFixture) -> None
"alt": "alternative text",
},
}
multi_images_block = {
"id": "abstract",
"type": "thumb-markdown",
"content": "a content",
"image": [
{
"url": "overview/overview.png",
"alt": "alternative text1",
},
{
"url": "overview/overview2.png",
"alt": "alternative text2",
},
],
}
modified_image_block = {
"id": "abstract",
"type": "thumb-markdown",
Expand All @@ -211,6 +226,21 @@ def test_manage_image_section(tmpdir, mocker: pytest_mock.MockerFixture) -> None
"alt": "alternative text",
},
}
multi_images_block_uploaded = {
"id": "abstract",
"type": "thumb-markdown",
"content": "a content",
"image": [
{
"url": "http://public-storage/an url",
"alt": "alternative text1",
},
{
"url": "http://public-storage/an url",
"alt": "alternative text2",
},
],
}
section = {"id": "overview", "blocks": [no_image_block, image_block]}
images_stored: dict[str, str] = dict()

Expand All @@ -219,7 +249,7 @@ def test_manage_image_section(tmpdir, mocker: pytest_mock.MockerFixture) -> None
layout_manager.manage_image_section(
str(tmpdir), section, images_stored, resource, oss
)
# url is already a link: no change
# url is already uploaded: no change
image_block_already_url = {
"id": "abstract",
"type": "thumb-markdown",
Expand All @@ -241,7 +271,9 @@ def test_manage_image_section(tmpdir, mocker: pytest_mock.MockerFixture) -> None
overview_file_path = os.path.join(overview_path, "overview.png")
with open(overview_file_path, "w") as fp:
fp.write("hello! I am an image")

overview2_file_path = os.path.join(overview_path, "overview2.png")
with open(overview2_file_path, "w") as fp:
fp.write("hello! I am an image2")
# 1 image block
section = {"id": "overview", "blocks": [no_image_block, image_block]}
new_section = layout_manager.manage_image_section(
Expand All @@ -263,7 +295,7 @@ def test_manage_image_section(tmpdir, mocker: pytest_mock.MockerFixture) -> None
)
assert new_section == section

# case section with more image_blocks
# case section with more separeted image blocks
section = {"id": "overview", "blocks": [image_block, no_image_block, image_block]}
new_section = layout_manager.manage_image_section(
str(tmpdir), section, images_stored, resource, oss
Expand Down Expand Up @@ -322,6 +354,15 @@ def test_manage_image_section(tmpdir, mocker: pytest_mock.MockerFixture) -> None
no_image_block,
],
}
# case section with a block with multiple images
section = {"id": "overview", "blocks": [no_image_block, multi_images_block]}
new_section = layout_manager.manage_image_section(
str(tmpdir), section, images_stored, resource, oss
)
assert new_section == {
"id": "overview",
"blocks": [no_image_block, multi_images_block_uploaded],
}


def test_transform_image_blocks(tmpdir, mocker: pytest_mock.MockerFixture) -> None:
Expand Down

0 comments on commit 9fb8b76

Please sign in to comment.