github.com/mgood/deis@v1.0.2-0.20141120022609-9a185b756e7d/controller/web/tests.py (about) 1 """ 2 Unit tests for the Deis web app. 3 4 Run the tests with "./manage.py test web" 5 """ 6 7 from __future__ import unicode_literals 8 9 from django.template import Context 10 from django.template import Template 11 from django.template import TemplateSyntaxError 12 from django.test import TestCase 13 14 15 class WebViewsTest(TestCase): 16 17 fixtures = ['test_web.json'] 18 19 def setUp(self): 20 self.client.login(username='autotest-1', password='password') 21 22 def test_account(self): 23 response = self.client.get('/account/') 24 self.assertContains(response, '<title>Deis | Account</title>', html=True) 25 self.assertContains(response, 'autotest-1') 26 self.assertContains(response, '<img src="//www.gravatar.com/avatar') 27 28 def test_dashboard(self): 29 response = self.client.get('/') 30 self.assertContains(response, '<title>Deis | Dashboard</title>', html=True) 31 32 def test_apps(self): 33 response = self.client.get('/apps/') 34 self.assertContains(response, '<title>Deis | Apps</title>', html=True) 35 self.assertContains(response, '<h1>One App</h1>') 36 self.assertContains(response, '<h3>autotest-1-app</h3>') 37 38 def test_support(self): 39 response = self.client.get('/support/') 40 self.assertContains(response, '<title>Deis | Support</title>', html=True) 41 self.assertContains(response, '<div class="forkImage">') 42 self.assertContains(response, '<h2>IRC</h2>') 43 self.assertContains(response, '<h2>GitHub</h2>') 44 45 46 class GravatarTagsTest(TestCase): 47 48 def _render_template(self, t, ctx=None): 49 """Test that the tag renders a gravatar URL.""" 50 tmpl = Template(t) 51 return tmpl.render(Context(ctx)).strip() 52 53 def test_render(self): 54 tmpl = """\ 55 {% load gravatar_tags %} 56 {% gravatar_url email %} 57 """ 58 rendered = self._render_template(tmpl, {'email': 'github@deis.io'}) 59 self.assertEquals( 60 rendered, 61 r'//www.gravatar.com/avatar/058ff74579b6a8fa1e10ab98c990e945?s=24&d=mm') 62 63 def test_render_syntax_error(self): 64 """Test that the tag requires one argument.""" 65 tmpl = """ 66 {% load gravatar_tags %} 67 {% gravatar_url %} 68 """ 69 self.assertRaises(TemplateSyntaxError, self._render_template, tmpl) 70 71 def test_render_context_error(self): 72 """Test that an empty email returns an empty string.""" 73 tmpl = """ 74 {% load gravatar_tags %} 75 {% gravatar_url email %} 76 """ 77 rendered = self._render_template(tmpl, {}) 78 self.assertEquals(rendered, '')