Skip to content

Commit

Permalink
Split up msgs app tests into separate files
Browse files Browse the repository at this point in the history
  • Loading branch information
rowanseymour committed Dec 19, 2024
1 parent c1f05a9 commit 7e25ee8
Show file tree
Hide file tree
Showing 14 changed files with 3,200 additions and 3,157 deletions.
29 changes: 21 additions & 8 deletions temba/msgs/templatetags/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

from temba.tests import TembaTest

from .sms import attachment_button
from . import sms as tags


class TestSMSTagLibrary(TembaTest):
class TestTemplateTags(TembaTest):
def test_attachment_button(self):
# complete attachment with subtype and extension
self.assertEqual(
Expand All @@ -17,7 +17,7 @@ def test_attachment_button(self):
"is_playable": False,
"thumb": None,
},
attachment_button("image/jpeg:https://example.com/test.jpg"),
tags.attachment_button("image/jpeg:https://example.com/test.jpg"),
)

# now with thumbnail
Expand All @@ -30,7 +30,7 @@ def test_attachment_button(self):
"is_playable": False,
"thumb": "https://example.com/test.jpg",
},
attachment_button("image/jpeg:https://example.com/test.jpg", True),
tags.attachment_button("image/jpeg:https://example.com/test.jpg", True),
)

# missing extension and thus no subtype
Expand All @@ -43,7 +43,7 @@ def test_attachment_button(self):
"is_playable": False,
"thumb": None,
},
attachment_button("image:https://example.com/test.aspx"),
tags.attachment_button("image:https://example.com/test.aspx"),
)

# ogg file with wrong content type
Expand All @@ -56,7 +56,7 @@ def test_attachment_button(self):
"is_playable": True,
"thumb": None,
},
attachment_button("application/octet-stream:https://example.com/test.ogg"),
tags.attachment_button("application/octet-stream:https://example.com/test.ogg"),
)

# geo coordinates
Expand All @@ -69,12 +69,25 @@ def test_attachment_button(self):
"is_playable": False,
"thumb": None,
},
attachment_button("geo:-35.998287,26.478109"),
tags.attachment_button("geo:-35.998287,26.478109"),
)

context = Context(attachment_button("image/jpeg:https://example.com/test.jpg"))
context = Context(tags.attachment_button("image/jpeg:https://example.com/test.jpg"))
template = Template("""{% load sms %}{% attachment_button "image/jpeg:https://example.com/test.jpg" %}""")

rendered = template.render(context)
self.assertIn("attachment", rendered)
self.assertIn("src='https://example.com/test.jpg'", rendered)

def test_render(self):
def render_template(src, context=None):
context = context or {}
context = Context(context)
return Template(src).render(context)

template_src = "{% load sms %}{% render as foo %}123<a>{{ bar }}{% endrender %}-{{ foo }}-"
self.assertEqual(render_template(template_src, {"bar": "abc"}), "-123<a>abc-")

# exception if tag not used correctly
self.assertRaises(ValueError, render_template, "{% load sms %}{% render with bob %}{% endrender %}")
self.assertRaises(ValueError, render_template, "{% load sms %}{% render as %}{% endrender %}")
Loading

0 comments on commit 7e25ee8

Please sign in to comment.