Skip to content

Commit 24f4d0f

Browse files
committed
Added tests pointed out by coverage.py.
1 parent 0b803fa commit 24f4d0f

4 files changed

Lines changed: 79 additions & 1 deletion

File tree

api/tests/test_formation.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,29 @@ def test_formation(self):
6060
response = self.client.delete(url)
6161
self.assertEqual(response.status_code, 204)
6262

63+
def test_formation_delete(self):
64+
"""
65+
Test that deleting a formation also deletes its apps.
66+
"""
67+
url = '/api/formations'
68+
body = {'id': 'auto_test-1', 'domain': 'localhost.localdomain'}
69+
response = self.client.post(url, json.dumps(body), content_type='application/json')
70+
self.assertEqual(response.status_code, 201)
71+
formation_id = response.data['id'] # noqa
72+
url = '/api/apps'
73+
body = {'formation': 'auto_test-1'}
74+
response = self.client.post(url, json.dumps(body), content_type='application/json')
75+
self.assertEqual(response.status_code, 201)
76+
response = self.client.get('/api/apps')
77+
self.assertEqual(response.status_code, 200)
78+
self.assertEqual(len(response.data['results']), 1)
79+
url = '/api/formations/{formation_id}'.format(**locals())
80+
response = self.client.delete(url)
81+
self.assertEqual(response.status_code, 204)
82+
response = self.client.get('/api/apps')
83+
self.assertEqual(response.status_code, 200)
84+
self.assertEqual(len(response.data['results']), 0)
85+
6386
def test_formation_cm(self):
6487
"""
6588
Test that configuration management is updated on formation changes

api/tests/test_node.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,22 @@ def test_node_create(self):
239239
self.assertEqual(response.status_code, 200)
240240
self.assertEqual(response.data['count'], 0)
241241

242+
def test_node_create_errors(self):
243+
url = '/api/formations'
244+
body = {'id': 'autotest'}
245+
response = self.client.post(url, json.dumps(body), content_type='application/json')
246+
self.assertEqual(response.status_code, 201)
247+
formation_id = response.data['id']
248+
url = '/api/formations/{formation_id}/layers'.format(**locals())
249+
body = {'id': 'runtime', 'flavor': 'autotest', 'runtime': True}
250+
response = self.client.post(url, json.dumps(body), content_type='application/json')
251+
self.assertEqual(response.status_code, 201)
252+
# create a node for an existing instance
253+
url = '/api/formations/{formation_id}/nodes'.format(**locals())
254+
body = {'fqdn': 'error', 'layer': 'runtime'}
255+
response = self.client.post(url, json.dumps(body), content_type='application/json')
256+
self.assertEqual(response.status_code, 401)
257+
242258
def test_node_str(self):
243259
"""Test the text representation of a node."""
244260
url = '/api/formations'

cm/mock.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ def bootstrap_node(node):
1818
1919
:param node: a dict containing the node's fully-qualified domain name and SSH info
2020
"""
21-
pass
21+
if 'error' in node.get('fqdn'):
22+
raise RuntimeError('Node Bootstrap Error:\nmock testing')
2223

2324

2425
def converge_node(node):

web/tests.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66

77
from __future__ import unicode_literals
88

9+
from django.template import Context
10+
from django.template import Template
11+
from django.template import TemplateSyntaxError
912
from django.test import TestCase
1013

1114

@@ -51,3 +54,38 @@ def test_support(self):
5154
self.assertContains(response, '<div class="forkImage">')
5255
self.assertContains(response, '<h2>IRC</h2>')
5356
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

Comments
 (0)