Add ReplyBuilder tests
The ReplyBuilder does stuff like parsing >quotes, >>replies, and [spoiler]spoiler tags[/spoiler] We mostly want to track consistent behavior with this Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
105
tests/test_replybuilder.py
Normal file
105
tests/test_replybuilder.py
Normal file
@@ -0,0 +1,105 @@
|
|||||||
|
from datetime import timedelta
|
||||||
|
from django.test import TestCase
|
||||||
|
from board.models import Board, Post
|
||||||
|
from board.templatetags.post_body import ReplyBuilder
|
||||||
|
|
||||||
|
|
||||||
|
class ReplyBuilderTestCase(TestCase):
|
||||||
|
def setUp(self):
|
||||||
|
Board.objects.create(
|
||||||
|
url="test", name="test", post_cooldown=timedelta(seconds=0)
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_quote(self):
|
||||||
|
expected = [
|
||||||
|
(
|
||||||
|
"this is some text that shouldn't be quoted.",
|
||||||
|
"this is some text that shouldn't be quoted.",
|
||||||
|
),
|
||||||
|
(
|
||||||
|
">implying this quotes text correctly",
|
||||||
|
'<span class="quote">>implying this quotes text correctly</span>',
|
||||||
|
),
|
||||||
|
(
|
||||||
|
">implying this >quotes >text correctly",
|
||||||
|
'<span class="quote">>implying this >quotes >text correctly</span>',
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"""
|
||||||
|
>implying this quotes text correctly
|
||||||
|
nothing ever changes
|
||||||
|
""",
|
||||||
|
'<span class="quote">>implying this quotes text correctly</span><br/>nothing ever changes',
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"""
|
||||||
|
what happened to the 1 2 3 4 5 6 7 8 9
|
||||||
|
>implying this quotes text correctly
|
||||||
|
nothing ever changes
|
||||||
|
""",
|
||||||
|
'what happened to the 1 2 3 4 5 6 7 8 9<br/><span class="quote">>implying this quotes text correctly</span><br/>nothing ever changes',
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"""
|
||||||
|
nothing ever changes
|
||||||
|
>implying this quotes text correctly
|
||||||
|
what happened to the 1 2 3 4 5 6 7 8 9
|
||||||
|
""",
|
||||||
|
'nothing ever changes<br/><span class="quote">>implying this quotes text correctly</span><br/>what happened to the 1 2 3 4 5 6 7 8 9',
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
||||||
|
for input, output in expected:
|
||||||
|
rb = ReplyBuilder(input.strip())
|
||||||
|
self.assertEquals(rb.build(), output)
|
||||||
|
|
||||||
|
def test_reply(self):
|
||||||
|
board = Board.objects.get(url="test")
|
||||||
|
post1 = Post.objects.create(board=board, text="test 1", ip="127.0.0.1")
|
||||||
|
post2 = Post.objects.create(board=board, text="test 1", ip="127.0.0.1")
|
||||||
|
post3 = Post.objects.create(board=board, text="test 1", ip="127.0.0.1")
|
||||||
|
|
||||||
|
expected = [
|
||||||
|
(
|
||||||
|
f">>{post1.id}",
|
||||||
|
f'<a class="post_link" href="{post1.get_absolute_url()}">>>{post1.id}</a>',
|
||||||
|
),
|
||||||
|
(
|
||||||
|
f">>{post2.id}",
|
||||||
|
f'<a class="post_link" href="{post2.get_absolute_url()}">>>{post2.id}</a>',
|
||||||
|
),
|
||||||
|
(
|
||||||
|
f">>{post1.id} >>{post2.id} >>{post3.id}",
|
||||||
|
f'<a class="post_link" href="{post1.get_absolute_url()}">>>{post1.id}</a> '
|
||||||
|
f'<a class="post_link" href="{post2.get_absolute_url()}">>>{post2.id}</a> '
|
||||||
|
f'<a class="post_link" href="{post3.get_absolute_url()}">>>{post3.id}</a>',
|
||||||
|
),
|
||||||
|
(
|
||||||
|
f">>999999",
|
||||||
|
f'<span class="post_link_broken">>>999999</span>',
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
||||||
|
for input, output in expected:
|
||||||
|
rb = ReplyBuilder(input.strip())
|
||||||
|
self.assertEquals(rb.build(), output)
|
||||||
|
|
||||||
|
def test_spoiler(self):
|
||||||
|
expected = [
|
||||||
|
(
|
||||||
|
"[spoiler]This is a spoiler[/spoiler]",
|
||||||
|
'<span class="spoiler">This is a spoiler</span>',
|
||||||
|
),
|
||||||
|
(
|
||||||
|
r"\[spoiler]This is an escaped spoiler[/spoiler]",
|
||||||
|
"[spoiler]This is an escaped spoiler[/spoiler]",
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"[spoiler]This is an unfinished spoiler",
|
||||||
|
'<span class="spoiler">This is an unfinished spoiler</span>',
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
||||||
|
for input, output in expected:
|
||||||
|
rb = ReplyBuilder(input.strip(), parse_spoilers=True)
|
||||||
|
self.assertEquals(rb.build(), output)
|
||||||
Reference in New Issue
Block a user