forked from plone/bobtemplates.plone
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.py
209 lines (192 loc) · 9.71 KB
/
tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
# -*- coding: utf-8 -*-
import unittest
import os
import tempfile
import shutil
from bobtemplates import hooks
from mrbob.bobexceptions import ValidationError
from scripttest import TestFileEnvironment
class BaseTemplateTest(unittest.TestCase):
def setUp(self):
self.tempdir = tempfile.mkdtemp()
self.addCleanup(shutil.rmtree, self.tempdir)
# docs http://pythonpaste.org/scripttest/
self.env = TestFileEnvironment(
os.path.join(self.tempdir, 'test-output'),
ignore_hidden=False,
)
def create_template(self):
"""Run mr.bob to create your template."""
options = {
'dir': os.path.join(os.path.dirname(__file__)),
'template': self.template,
'project': self.project,
'answers_file': self.answers_file,
}
return self.env.run(
'%(dir)s/bin/mrbob -O %(project)s --config '
'%(dir)s/%(answers_file)s %(dir)s/bobtemplates/%(template)s'
% options)
class PloneTemplateTest(BaseTemplateTest):
"""Tests for the `roo_addon` template."""
template = ''
project = ''
answers_file = ''
def test_roo_addon_template(self):
"""Test the `roo_addon` template.
Generate a project from a template, test which files were created
and run all tests in the generated package.
"""
self.template = 'roo_addon'
self.project = 'collective.foo'
self.answers_file = 'nosetests_answers.ini'
self.maxDiff = None
result = self.create_template()
self.assertItemsEqual(
result.files_created.keys(),
[
self.project,
self.project + '/.gitignore',
self.project + '/.travis.yml',
self.project + '/CHANGES.rst',
self.project + '/CONTRIBUTORS.rst',
self.project + '/MANIFEST.in',
self.project + '/README.rst',
self.project + '/bootstrap-buildout.py',
self.project + '/buildout.cfg',
self.project + '/docs',
self.project + '/docs/LICENSE.GPL',
self.project + '/docs/LICENSE.rst',
self.project + '/docs/index.rst',
self.project + '/setup.py',
self.project + '/src',
self.project + '/src/collective',
self.project + '/src/collective/__init__.py',
self.project + '/src/collective/foo',
self.project + '/src/collective/foo/__init__.py',
self.project + '/src/collective/foo/browser',
self.project + '/src/collective/foo/browser/__init__.py',
self.project + '/src/collective/foo/browser/configure.zcml',
self.project + '/src/collective/foo/browser/overrides',
self.project + '/src/collective/foo/browser/overrides/.gitkeep', # noqa
self.project + '/src/collective/foo/browser/static',
self.project + '/src/collective/foo/browser/static/.gitkeep',
self.project + '/src/collective/foo/configure.zcml',
self.project + '/src/collective/foo/interfaces.py',
self.project + '/src/collective/foo/locales',
self.project + '/src/collective/foo/locales/collective.foo.pot', # noqa
self.project + '/src/collective/foo/locales/update.sh',
self.project + '/src/collective/foo/profiles',
self.project + '/src/collective/foo/profiles/default',
self.project + '/src/collective/foo/profiles/default/browserlayer.xml', # noqa
self.project + '/src/collective/foo/profiles/default/metadata.xml', # noqa
self.project + '/src/collective/foo/profiles/uninstall',
self.project + '/src/collective/foo/profiles/uninstall/browserlayer.xml', # noqa
self.project + '/src/collective/foo/setuphandlers.py',
self.project + '/src/collective/foo/testing.py',
self.project + '/src/collective/foo/tests',
self.project + '/src/collective/foo/tests/__init__.py',
self.project + '/src/collective/foo/tests/robot',
self.project + '/src/collective/foo/tests/robot/test_example.robot', # noqa
self.project + '/src/collective/foo/tests/test_robot.py',
self.project + '/src/collective/foo/tests/test_setup.py',
self.project + '/travis.cfg',
self.project + '/.coveragerc',
self.project + '/.editorconfig',
self.project + '/.gitattributes',
self.project + '/setup.cfg',
]
)
def test_roo_addon_nested_template(self):
"""Test the `roo_addon_nested` template.
Generate a project from a template, test which files were created
and run all tests in the generated package.
"""
self.template = 'roo_addon'
self.project = 'collective.foo.bar'
self.answers_file = 'nosetests_answers_nested.ini'
self.maxDiff = None
result = self.create_template()
self.assertItemsEqual(
result.files_created.keys(),
[
self.project,
self.project + '/.gitignore',
self.project + '/.travis.yml',
self.project + '/CHANGES.rst',
self.project + '/CONTRIBUTORS.rst',
self.project + '/MANIFEST.in',
self.project + '/README.rst',
self.project + '/bootstrap-buildout.py',
self.project + '/buildout.cfg',
self.project + '/docs',
self.project + '/docs/LICENSE.GPL',
self.project + '/docs/LICENSE.rst',
self.project + '/docs/index.rst',
self.project + '/setup.py',
self.project + '/src',
self.project + '/src/collective',
self.project + '/src/collective/__init__.py',
self.project + '/src/collective/foo',
self.project + '/src/collective/foo/__init__.py',
self.project + '/src/collective/foo/bar',
self.project + '/src/collective/foo/bar/__init__.py',
self.project + '/src/collective/foo/bar/browser',
self.project + '/src/collective/foo/bar/browser/__init__.py',
self.project + '/src/collective/foo/bar/browser/configure.zcml', # noqa
self.project + '/src/collective/foo/bar/browser/overrides', # noqa
self.project + '/src/collective/foo/bar/browser/overrides/.gitkeep', # noqa
self.project + '/src/collective/foo/bar/browser/static',
self.project + '/src/collective/foo/bar/browser/static/.gitkeep', # noqa
self.project + '/src/collective/foo/bar/configure.zcml',
self.project + '/src/collective/foo/bar/interfaces.py',
self.project + '/src/collective/foo/bar/locales',
self.project + '/src/collective/foo/bar/locales/collective.foo.bar.pot', # noqa
self.project + '/src/collective/foo/bar/locales/update.sh',
self.project + '/src/collective/foo/bar/profiles',
self.project + '/src/collective/foo/bar/profiles/default',
self.project + '/src/collective/foo/bar/profiles/default/browserlayer.xml', # noqa
self.project + '/src/collective/foo/bar/profiles/default/metadata.xml', # noqa
self.project + '/src/collective/foo/bar/profiles/uninstall',
self.project + '/src/collective/foo/bar/profiles/uninstall/browserlayer.xml', # noqa
self.project + '/src/collective/foo/bar/setuphandlers.py',
self.project + '/src/collective/foo/bar/testing.py',
self.project + '/src/collective/foo/bar/tests',
self.project + '/src/collective/foo/bar/tests/__init__.py',
self.project + '/src/collective/foo/bar/tests/robot',
self.project + '/src/collective/foo/bar/tests/robot/test_example.robot', # noqa
self.project + '/src/collective/foo/bar/tests/test_robot.py',
self.project + '/src/collective/foo/bar/tests/test_setup.py',
self.project + '/travis.cfg',
self.project + '/.coveragerc',
self.project + '/.editorconfig',
self.project + '/.gitattributes',
self.project + '/setup.cfg',
]
)
class HooksTest(unittest.TestCase):
def test_to_boolean(self):
# Initial simple test to show coverage in hooks.py.
self.assertEqual(hooks.to_boolean(None, None, 'y'), True)
def test_post_dexterity_type_name(self):
"""Test validation of entered dexterity type names
"""
def hookit(value):
return hooks.post_dexterity_type_name(None, None, value)
with self.assertRaises(ValidationError):
hookit('import')
with self.assertRaises(ValidationError):
hookit(u'süpertype')
with self.assertRaises(ValidationError):
hookit(u'Staff Member')
with self.assertRaises(ValidationError):
hookit(u'2ndComing')
with self.assertRaises(ValidationError):
hookit(u'Second Coming')
with self.assertRaises(ValidationError):
hookit(u'Staff Member')
with self.assertRaises(ValidationError):
hookit(u'*sterisk')
self.assertEqual(hookit(u'Supertype'), u'Supertype')
self.assertEqual(hookit(u'second_coming'), u'second_coming')
self.assertEqual(hookit(u'the_2nd_coming'), u'the_2nd_coming')