~gnuoy/charms/trusty/swift-proxy/stable-charmhelper-sync

« back to all changes in this revision

Viewing changes to unit_tests/test_templates.py

  • Committer: James Page
  • Date: 2013-11-18 11:16:28 UTC
  • mfrom: (46.1.5 fix-templates)
  • Revision ID: james.page@canonical.com-20131118111628-lu2qje5j5y3w2v1l
[Michael Nelson] Fixup templates for essex release, add template unit tests for changes
[James Page] Add standard unit test fixtures for openstack charms

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import mock
 
2
import unittest
 
3
 
 
4
from jinja2 import Environment
 
5
 
 
6
from charmhelpers.contrib.openstack.templating import get_loader
 
7
 
 
8
 
 
9
class ProxyServerTemplateTestCase(unittest.TestCase):
 
10
 
 
11
    @mock.patch('charmhelpers.contrib.openstack.templating.log')
 
12
    def get_template_for_release(self, os_release, mock_log):
 
13
        loader = get_loader('./templates', os_release)
 
14
        env = Environment(loader=loader)
 
15
 
 
16
        return env.get_template('proxy-server.conf')
 
17
 
 
18
    def test_essex_keystone_includes_correct_egg(self):
 
19
        """Regression test for bug 1251551."""
 
20
        template = self.get_template_for_release('essex')
 
21
 
 
22
        result = template.render(auth_type='keystone')
 
23
 
 
24
        self.assertIn("use = egg:swift#swift3", result)
 
25
 
 
26
    def test_essex_keystone_includes_correct_delay_auth_true(self):
 
27
        """Regression test for bug 1251551."""
 
28
        template = self.get_template_for_release('essex')
 
29
 
 
30
        result = template.render(auth_type='keystone',
 
31
                                 delay_auth_decision='true')
 
32
 
 
33
        self.assertIn("delay_auth_decision = 1", result)
 
34
 
 
35
    def test_essex_keystone_includes_correct_delay_auth_false(self):
 
36
        """Regression test for bug 1251551."""
 
37
        template = self.get_template_for_release('essex')
 
38
 
 
39
        result = template.render(auth_type='keystone',
 
40
                                 delay_auth_decision='anything')
 
41
 
 
42
        self.assertIn("delay_auth_decision = 0", result)
 
43
 
 
44
    def test_os_release_not_in_templates(self):
 
45
        """Regression test for bug 1251551.
 
46
 
 
47
        The os_release is no longer provided as context to the templates.
 
48
        """
 
49
        for release in ('essex', 'grizzly', 'havana'):
 
50
            template = self.get_template_for_release(release)
 
51
            with open(template.filename, 'r') as template_orig:
 
52
                self.assertNotIn(
 
53
                    'os_release', template_orig.read(),
 
54
                    "The template '{}' contains os_release which is "
 
55
                    "no longer provided in the context.".format(
 
56
                        template.filename))
 
57
 
 
58
    def test_config_renders_for_all_releases(self):
 
59
        """The configs render without syntax error."""
 
60
        for release in ('essex', 'grizzly', 'havana'):
 
61
            template = self.get_template_for_release(release)
 
62
 
 
63
            result = template.render()
 
64
 
 
65
            self.assertTrue(result.startswith("[DEFAULT]"))