Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jeriox committed Oct 18, 2023
1 parent f6cc3a8 commit 48e00ff
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 42 deletions.
2 changes: 1 addition & 1 deletion myhpi/polls/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from django.shortcuts import redirect
from modelcluster.fields import ParentalKey
from wagtail.admin.edit_handlers import FieldPanel, InlinePanel
from wagtail.core.models import Orderable, Page
from wagtail.models import Orderable, Page
from wagtail.search import index

from myhpi.core.markdown.fields import CustomMarkdownField
Expand Down
41 changes: 0 additions & 41 deletions myhpi/tests/test_markdown_extensions.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
import re
from typing import Collection

import django
from django.test import TestCase
from django.utils.translation import activate
from wagtail.core.models import Page
from wagtail.images.models import Image

from myhpi.core.markdown.extensions import ImagePattern

django.setup()

from myhpi.core.markdown.extensions import (
BreakPreprocessor,
EnterLeavePreprocessor,
HeadingLevelPreprocessor,
InternalLinkPattern,
QuorumPreprocessor,
StartEndPreprocessor,
VotePreprocessor,
Expand Down Expand Up @@ -92,39 +87,3 @@ def test_heading_level_preprocessor(self):
"###### Heading 6",
],
)

def test_internal_link_preprocessor(self):
ilp = InternalLinkPattern(InternalLinkPattern.default_pattern())

from myhpi.tests.core.setup import setup_data

test_data = setup_data()
test_page = test_data["pages"][0]
text = f"[Page title](page:{test_page.id})"
el, _, _ = ilp.handleMatch(re.match(ilp.pattern, text))
self.assertEqual(el.attrib["href"], test_page.localized.get_url())

def test_image_pattern(self):
activate("en")
from django.core.files.uploadedfile import SimpleUploadedFile

ip = ImagePattern(ImagePattern.default_pattern())

image_file = SimpleUploadedFile(
name="test_image.jpg",
content=open("myhpi/tests/files/test_image.jpg", "rb").read(),
content_type="image/jpeg",
)

image = Image.objects.create(
title="Test image",
file=image_file,
)

text = f"![Alt text](image:{image.id})"
invalid_text = "![Alt text](image:1234567890)"
el, _, _ = ip.handleMatch(re.match(ip.pattern, text))
self.assertEqual(el.attrib["src"], image.get_rendition("width-800").url)

el, _, _ = ip.handleMatch(re.match(ip.pattern, invalid_text))
self.assertEqual(el.text, "[missing image]")

0 comments on commit 48e00ff

Please sign in to comment.