Skip to content
This repository has been archived by the owner on Nov 30, 2021. It is now read-only.

Commit

Permalink
Merge pull request #426 from opdemand/more-tests
Browse files Browse the repository at this point in the history
Added some tests pointed out by coverage.py.
  • Loading branch information
Gabriel Monroy committed Dec 27, 2013
2 parents 0b803fa + 24f4d0f commit b575574
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 1 deletion.
23 changes: 23 additions & 0 deletions api/tests/test_formation.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,29 @@ def test_formation(self):
response = self.client.delete(url)
self.assertEqual(response.status_code, 204)

def test_formation_delete(self):
"""
Test that deleting a formation also deletes its apps.
"""
url = '/api/formations'
body = {'id': 'auto_test-1', 'domain': 'localhost.localdomain'}
response = self.client.post(url, json.dumps(body), content_type='application/json')
self.assertEqual(response.status_code, 201)
formation_id = response.data['id'] # noqa
url = '/api/apps'
body = {'formation': 'auto_test-1'}
response = self.client.post(url, json.dumps(body), content_type='application/json')
self.assertEqual(response.status_code, 201)
response = self.client.get('/api/apps')
self.assertEqual(response.status_code, 200)
self.assertEqual(len(response.data['results']), 1)
url = '/api/formations/{formation_id}'.format(**locals())
response = self.client.delete(url)
self.assertEqual(response.status_code, 204)
response = self.client.get('/api/apps')
self.assertEqual(response.status_code, 200)
self.assertEqual(len(response.data['results']), 0)

def test_formation_cm(self):
"""
Test that configuration management is updated on formation changes
Expand Down
16 changes: 16 additions & 0 deletions api/tests/test_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,22 @@ def test_node_create(self):
self.assertEqual(response.status_code, 200)
self.assertEqual(response.data['count'], 0)

def test_node_create_errors(self):
url = '/api/formations'
body = {'id': 'autotest'}
response = self.client.post(url, json.dumps(body), content_type='application/json')
self.assertEqual(response.status_code, 201)
formation_id = response.data['id']
url = '/api/formations/{formation_id}/layers'.format(**locals())
body = {'id': 'runtime', 'flavor': 'autotest', 'runtime': True}
response = self.client.post(url, json.dumps(body), content_type='application/json')
self.assertEqual(response.status_code, 201)
# create a node for an existing instance
url = '/api/formations/{formation_id}/nodes'.format(**locals())
body = {'fqdn': 'error', 'layer': 'runtime'}
response = self.client.post(url, json.dumps(body), content_type='application/json')
self.assertEqual(response.status_code, 401)

def test_node_str(self):
"""Test the text representation of a node."""
url = '/api/formations'
Expand Down
3 changes: 2 additions & 1 deletion cm/mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ def bootstrap_node(node):
:param node: a dict containing the node's fully-qualified domain name and SSH info
"""
pass
if 'error' in node.get('fqdn'):
raise RuntimeError('Node Bootstrap Error:\nmock testing')


def converge_node(node):
Expand Down
38 changes: 38 additions & 0 deletions web/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

from __future__ import unicode_literals

from django.template import Context
from django.template import Template
from django.template import TemplateSyntaxError
from django.test import TestCase


Expand Down Expand Up @@ -51,3 +54,38 @@ def test_support(self):
self.assertContains(response, '<div class="forkImage">')
self.assertContains(response, '<h2>IRC</h2>')
self.assertContains(response, '<h2>GitHub</h2>')


class GravatarTagsTest(TestCase):

def _render_template(self, str, ctx=None):
"""Test that the tag renders a gravatar URL."""
tmpl = Template(str)
return tmpl.render(Context(ctx)).strip()

def test_render(self):
tmpl = """\
{% load gravatar_tags %}
{% gravatar_url email %}
"""
rendered = self._render_template(tmpl, {'email': 'github@deis.io'})
self.assertEquals(
rendered,
r'//www.gravatar.com/avatar/058ff74579b6a8fa1e10ab98c990e945?s=24&d=mm')

def test_render_syntax_error(self):
"""Test that the tag requires one argument."""
tmpl = """
{% load gravatar_tags %}
{% gravatar_url %}
"""
self.assertRaises(TemplateSyntaxError, self._render_template, tmpl)

def test_render_context_error(self):
"""Test that an empty email returns an empty string."""
tmpl = """
{% load gravatar_tags %}
{% gravatar_url email %}
"""
rendered = self._render_template(tmpl, {})
self.assertEquals(rendered, '')

0 comments on commit b575574

Please sign in to comment.