github.com/blystad/deis@v0.11.0/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          self.assertContains(
    28              response, '<form method="post" action="/accounts/logout/">')
    29  
    30      def test_dashboard(self):
    31          response = self.client.get('/')
    32          self.assertContains(response, '<title>Deis | Dashboard</title>', html=True)
    33          self.assertContains(
    34              response,
    35              r'You have <a href="/clusters/">one cluster</a> and <a href="/apps/">one app</a>.')
    36  
    37      def test_clusters(self):
    38          response = self.client.get('/clusters/')
    39          self.assertContains(response, '<title>Deis | Clusters</title>', html=True)
    40          self.assertContains(response, '<h1>One Cluster</h1>')
    41          self.assertContains(response, '<h3>autotest-1</h3>')
    42          self.assertContains(response, '<dt>Owned by</dt>')
    43          self.assertContains(response, '<dd>autotest-1</dd>')
    44  
    45      def test_apps(self):
    46          response = self.client.get('/apps/')
    47          self.assertContains(response, '<title>Deis | Apps</title>', html=True)
    48          self.assertContains(response, '<h1>One App</h1>')
    49          self.assertContains(response, '<h3>autotest-1-app</h3>')
    50  
    51      def test_support(self):
    52          response = self.client.get('/support/')
    53          self.assertContains(response, '<title>Deis | Support</title>', html=True)
    54          self.assertContains(response, '<div class="forkImage">')
    55          self.assertContains(response, '<h2>IRC</h2>')
    56          self.assertContains(response, '<h2>GitHub</h2>')
    57  
    58  
    59  class GravatarTagsTest(TestCase):
    60  
    61      def _render_template(self, t, ctx=None):
    62          """Test that the tag renders a gravatar URL."""
    63          tmpl = Template(t)
    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, '')