|
6 | 6 |
|
7 | 7 | from __future__ import unicode_literals |
8 | 8 |
|
| 9 | +from django.template import Context |
| 10 | +from django.template import Template |
| 11 | +from django.template import TemplateSyntaxError |
9 | 12 | from django.test import TestCase |
10 | 13 |
|
11 | 14 |
|
@@ -51,3 +54,38 @@ def test_support(self): |
51 | 54 | self.assertContains(response, '<div class="forkImage">') |
52 | 55 | self.assertContains(response, '<h2>IRC</h2>') |
53 | 56 | self.assertContains(response, '<h2>GitHub</h2>') |
| 57 | + |
| 58 | + |
| 59 | +class GravatarTagsTest(TestCase): |
| 60 | + |
| 61 | + def _render_template(self, str, ctx=None): |
| 62 | + """Test that the tag renders a gravatar URL.""" |
| 63 | + tmpl = Template(str) |
| 64 | + return tmpl.render(Context(ctx)).strip() |
| 65 | + |
| 66 | + def test_render(self): |
| 67 | + tmpl = """\ |
| 68 | +{% load gravatar_tags %} |
| 69 | +{% gravatar_url email %} |
| 70 | +""" |
| 71 | + rendered = self._render_template(tmpl, {'email': 'github@deis.io'}) |
| 72 | + self.assertEquals( |
| 73 | + rendered, |
| 74 | + r'//www.gravatar.com/avatar/058ff74579b6a8fa1e10ab98c990e945?s=24&d=mm') |
| 75 | + |
| 76 | + def test_render_syntax_error(self): |
| 77 | + """Test that the tag requires one argument.""" |
| 78 | + tmpl = """ |
| 79 | +{% load gravatar_tags %} |
| 80 | +{% gravatar_url %} |
| 81 | +""" |
| 82 | + self.assertRaises(TemplateSyntaxError, self._render_template, tmpl) |
| 83 | + |
| 84 | + def test_render_context_error(self): |
| 85 | + """Test that an empty email returns an empty string.""" |
| 86 | + tmpl = """ |
| 87 | +{% load gravatar_tags %} |
| 88 | +{% gravatar_url email %} |
| 89 | +""" |
| 90 | + rendered = self._render_template(tmpl, {}) |
| 91 | + self.assertEquals(rendered, '') |
0 commit comments