Merge ~pjdc/ubuntu-mirror-charm/+git/ubuntu-mirror-charm:refactor-testcases into ubuntu-mirror-charm:master

Proposed by Paul Collins
Status: Merged
Approved by: Paul Collins
Approved revision: 40a9f41cf03327072ac3be9ceebc711e8c9c9562
Merged at revision: fe82f87fb7f206b81634f27750f59850e608372e
Proposed branch: ~pjdc/ubuntu-mirror-charm/+git/ubuntu-mirror-charm:refactor-testcases
Merge into: ubuntu-mirror-charm:master
Diff against target: 96 lines (+36/-22)
1 file modified
tests/unit/test_templates.py (+36/-22)
Reviewer Review Type Date Requested Status
Colin Misare Approve
Canonical IS Reviewers Pending
Review via email: mp+411382@code.launchpad.net

Commit message

factor out generic TemplateTestCase

To post a comment you must log in.
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

This merge proposal is being monitored by mergebot. Change the status to Approved to merge.

Revision history for this message
Colin Misare (cmisare) wrote :

LGTM

review: Approve
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

Merge proposal is approved, but source revision has changed, setting status to needs review.

Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

Change successfully merged at revision fe82f87fb7f206b81634f27750f59850e608372e

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/tests/unit/test_linuxcontainers.py b/tests/unit/test_templates.py
2similarity index 70%
3rename from tests/unit/test_linuxcontainers.py
4rename to tests/unit/test_templates.py
5index 7e82350..a9cf4e6 100644
6--- a/tests/unit/test_linuxcontainers.py
7+++ b/tests/unit/test_templates.py
8@@ -4,28 +4,18 @@ import unittest
9
10 from Cheetah.Template import Template
11
12-TEMPLATE = 'apache-linuxcontainers.tmpl'
13
14-THIRDPARTY_SEARCH_LIST = {
15- 'addresses': ['*'],
16- 'name': 'lxd.example.net',
17- 'aliases': ['uk.lxd.example.net', 'us.lxd.example.net'],
18- 'ports': [80, 443],
19-}
20-
21-LINUXCONTAINERS_SEARCH_LIST = {
22- 'addresses': ['91.189.88.247', '[2001:67c:1360:8001::33]'],
23- 'name': 'lxd.images.canonical.com',
24- 'aliases': ['uk.lxd.images.canonical.com', 'us.lxd.images.canonical.com'],
25- 'ports': [80, 443, 8443],
26-}
27+class TemplateTestCase(object):
28+ """Base class for template test cases.
29
30+ IMPORTANT: Must be before `unittest.TestCase` in the class list,
31+ otherwise setUp and tearDown will be not called, because TestCase
32+ doesn't use super() as it (possibly) should."""
33
34-class TestLinuxcontainers(unittest.TestCase):
35 def setUp(self):
36 self.addTypeEqualityFunc(str, self.assertMultiLineEqual)
37 self.maxDiff = None
38- self.testdata_dir = os.path.join(os.path.dirname(__file__), 'testdata', 'linuxcontainers')
39+ self.testdata_dir = os.path.join(os.path.dirname(__file__), 'testdata', self._role)
40
41 def _template_compare(self, template, search_list, wanted_file):
42 template_file = os.path.join(os.getcwd(), template)
43@@ -33,16 +23,19 @@ class TestLinuxcontainers(unittest.TestCase):
44 wanted = open(wanted_file).read()
45 self.assertEqual(str(template), wanted)
46
47+ def _template_path(self, role):
48+ return os.path.join(os.getcwd(), 'templates', 'apache-{}.tmpl'.format(role))
49+
50 # Cheetah warns about using the Python version of NameMapper, so
51 # we ignore it here. Matching more closely by the message doesn't
52 # seem to work, probably because it begins with a newline and
53 # Python's warnings matching code anchors the message regexp.
54 @pytest.mark.filterwarnings("ignore::UserWarning:Cheetah")
55- def test_template_linuxcontainers(self):
56+ def test_template(self):
57 self._template_compare(
58- os.path.join(os.getcwd(), 'templates', TEMPLATE),
59- LINUXCONTAINERS_SEARCH_LIST,
60- os.path.join(self.testdata_dir, 'linuxcontainers.txt'))
61+ self._template_path(self._role),
62+ self._search_list,
63+ os.path.join(self.testdata_dir, self._role + '.txt'))
64
65 # Cheetah warns about using the Python version of NameMapper, so
66 # we ignore it here. Matching more closely by the message doesn't
67@@ -51,6 +44,27 @@ class TestLinuxcontainers(unittest.TestCase):
68 @pytest.mark.filterwarnings("ignore::UserWarning:Cheetah")
69 def test_template_thirdparty(self):
70 self._template_compare(
71- os.path.join(os.getcwd(), 'templates', TEMPLATE),
72- THIRDPARTY_SEARCH_LIST,
73+ self._template_path(self._role),
74+ self._thirdparty_search_list,
75 os.path.join(self.testdata_dir, 'thirdparty.txt'))
76+
77+
78+LINUXCONTAINERS_THIRDPARTY_SEARCH_LIST = {
79+ 'addresses': ['*'],
80+ 'name': 'lxd.example.net',
81+ 'aliases': ['uk.lxd.example.net', 'us.lxd.example.net'],
82+ 'ports': [80, 443],
83+}
84+
85+LINUXCONTAINERS_SEARCH_LIST = {
86+ 'addresses': ['91.189.88.247', '[2001:67c:1360:8001::33]'],
87+ 'name': 'lxd.images.canonical.com',
88+ 'aliases': ['uk.lxd.images.canonical.com', 'us.lxd.images.canonical.com'],
89+ 'ports': [80, 443, 8443],
90+}
91+
92+
93+class TestLinuxcontainers(TemplateTestCase, unittest.TestCase):
94+ _role = 'linuxcontainers'
95+ _search_list = LINUXCONTAINERS_SEARCH_LIST
96+ _thirdparty_search_list = LINUXCONTAINERS_THIRDPARTY_SEARCH_LIST

Subscribers

People subscribed via source and target branches