Skip to content

Commit

Permalink
Convert the testsuite to pytest
Browse files Browse the repository at this point in the history
matthiask committed Jan 31, 2025
1 parent 2072f6c commit d20d3a9
Showing 12 changed files with 2,088 additions and 2,078 deletions.
8 changes: 8 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -47,6 +47,9 @@ optional-dependencies.all = [
optional-dependencies.tests = [
"coverage",
"django-ckeditor",
"pytest",
"pytest-cov",
"pytest-django",
"requests-mock",
]
urls.Homepage = "https://github.com/matthiask/feincms3/"
@@ -122,3 +125,8 @@ lint.per-file-ignores."*/migrat*/*" = [
lint.isort.combine-as-imports = true
lint.isort.lines-after-imports = 2
lint.mccabe.max-complexity = 15

[tool.pytest.ini_options]
DJANGO_SETTINGS_MODULE = "testapp.settings"
python_files = [ "tests.py", "test_*.py" ]
addopts = "--reuse-db"
1 change: 1 addition & 0 deletions tests/testapp/settings.py
Original file line number Diff line number Diff line change
@@ -31,6 +31,7 @@

ROOT_URLCONF = "testapp.urls"
LANGUAGES = [("en", "English"), ("de", "German"), ("fr", "French")]
LANGUAGE_CODE = "en"

TEMPLATES = [
{
16 changes: 7 additions & 9 deletions tests/testapp/test_cleanse.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
from django.db import models
from django.test import TestCase
from django.test.utils import isolate_apps

from feincms3.cleanse import CleansedRichTextField


class Test(TestCase):
@isolate_apps("testapp")
def test_mixin(self):
class Thing(models.Model): # noqa: DJ008
text = CleansedRichTextField()
@isolate_apps("testapp")
def test_mixin():
class Thing(models.Model): # noqa: DJ008
text = CleansedRichTextField()

thing = Thing(text="<script>Hello</script>World")
thing.full_clean()
self.assertEqual(thing.text, "World")
thing = Thing(text="<script>Hello</script>World")
thing.full_clean()
assert thing.text == "World"
93 changes: 44 additions & 49 deletions tests/testapp/test_embedding.py
Original file line number Diff line number Diff line change
@@ -1,64 +1,59 @@
from django.test import TestCase

from feincms3.embedding import embed


class EmbeddingTest(TestCase):
def test_no_handlers(self):
"""Embed video without handlers"""
self.assertEqual(embed("stuff"), None)
def test_no_handlers():
"""Embed video without handlers"""
assert embed("stuff") is None


def test_youtube(self):
"""YouTube video embedding works"""
self.assertEqual(
embed("https://www.youtube.com/watch?v=dQw4w9WgXcQ"),
"""\
def test_youtube():
"""YouTube video embedding works"""
assert (
embed("https://www.youtube.com/watch?v=dQw4w9WgXcQ")
== """\
<div class="responsive-embed widescreen youtube"><iframe \
src="https://www.youtube.com/embed/dQw4w9WgXcQ?rel=0" frameborder="0" \
allow="autoplay; fullscreen" allowfullscreen=""></iframe></div>""",
)
allow="autoplay; fullscreen" allowfullscreen=""></iframe></div>"""
)

self.assertEqual(
embed("https://youtu.be/y7-s5ZvC_2A"),
"""\
assert (
embed("https://youtu.be/y7-s5ZvC_2A")
== """\
<div class="responsive-embed widescreen youtube"><iframe \
src="https://www.youtube.com/embed/y7-s5ZvC_2A?rel=0" frameborder="0" \
allow="autoplay; fullscreen" allowfullscreen=""></iframe></div>""",
)

self.assertTrue(
embed("https://www.youtube.com/watch?v=4zGnNmncJWg&feature=emb_title")
)
self.assertTrue(
embed(
"https://www.youtube.com/watch?v=DYu_bGbZiiQ&list=RDJMOOG7rWTPg&index=7"
)
)
self.assertTrue(embed("https://www.youtube.com/watch/ZumRshfKdtM"))
self.assertTrue(embed("https://www.youtube.com/shorts/ZumRshfKdtM"))

self.assertEqual(
embed("https://www.youtube.com/live/ljSZ0xrJjCs"),
"""\
<div class="responsive-embed widescreen youtube"><iframe src="https://www.youtube.com/embed/ljSZ0xrJjCs?rel=0" frameborder="0" allow="autoplay; fullscreen" allowfullscreen=""></iframe></div>""",
)

def test_vimeo(self):
"""Vimeo video embedding works"""
self.assertEqual(
embed("https://vimeo.com/455728498"),
"""\
allow="autoplay; fullscreen" allowfullscreen=""></iframe></div>"""
)

assert embed("https://www.youtube.com/watch?v=4zGnNmncJWg&feature=emb_title")
assert embed(
"https://www.youtube.com/watch?v=DYu_bGbZiiQ&list=RDJMOOG7rWTPg&index=7"
)
assert embed("https://www.youtube.com/watch/ZumRshfKdtM")
assert embed("https://www.youtube.com/shorts/ZumRshfKdtM")

assert (
embed("https://www.youtube.com/live/ljSZ0xrJjCs")
== """\
<div class="responsive-embed widescreen youtube"><iframe src="https://www.youtube.com/embed/ljSZ0xrJjCs?rel=0" frameborder="0" allow="autoplay; fullscreen" allowfullscreen=""></iframe></div>"""
)


def test_vimeo():
"""Vimeo video embedding works"""
assert (
embed("https://vimeo.com/455728498")
== """\
<div class="responsive-embed widescreen vimeo"><iframe \
src="https://player.vimeo.com/video/455728498" frameborder="0" \
allow="autoplay; fullscreen" allowfullscreen=""></iframe></div>""",
)
allow="autoplay; fullscreen" allowfullscreen=""></iframe></div>"""
)

self.assertTrue(embed("https://player.vimeo.com/video/417955670"))
assert embed("https://player.vimeo.com/video/417955670")

self.assertEqual(
embed("https://vimeo.com/12345678/3213124324"),
"""\
assert (
embed("https://vimeo.com/12345678/3213124324")
== """\
<div class="responsive-embed widescreen vimeo"><iframe \
src="https://player.vimeo.com/video/12345678" frameborder="0" \
allow="autoplay; fullscreen" allowfullscreen=""></iframe></div>""",
)
allow="autoplay; fullscreen" allowfullscreen=""></iframe></div>"""
)
Loading

0 comments on commit d20d3a9

Please sign in to comment.