Create wrapper for config extension
This commit is contained in:
parent
58e825c43b
commit
f38e7a53df
3 changed files with 12 additions and 6 deletions
|
@ -26,6 +26,12 @@ class BaseTestCase(unittest.TestCase):
|
||||||
except OSError:
|
except OSError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def extend_config(self, *args):
|
||||||
|
base_config = self.BASE_VALID_CONFIG.copy()
|
||||||
|
for arg in args:
|
||||||
|
base_config = dict(base_config, **arg)
|
||||||
|
return base_config
|
||||||
|
|
||||||
def delete_templates(self):
|
def delete_templates(self):
|
||||||
for template in [
|
for template in [
|
||||||
'header.html',
|
'header.html',
|
||||||
|
|
|
@ -30,7 +30,7 @@ class ContextTestCase(BaseTestCase):
|
||||||
self.assertIn(key, context)
|
self.assertIn(key, context)
|
||||||
|
|
||||||
def test_context_contains_context(self):
|
def test_context_contains_context(self):
|
||||||
config = dict(self.BASE_VALID_CONFIG, **{
|
config = self.extend_config({
|
||||||
'context': {
|
'context': {
|
||||||
'1': '2'
|
'1': '2'
|
||||||
}
|
}
|
||||||
|
@ -49,7 +49,7 @@ class ContextTestCase(BaseTestCase):
|
||||||
self.assertEqual(context['output_dir'], os.path.abspath(self.BASE_VALID_CONFIG['output_dir']))
|
self.assertEqual(context['output_dir'], os.path.abspath(self.BASE_VALID_CONFIG['output_dir']))
|
||||||
|
|
||||||
def test_word_count(self):
|
def test_word_count(self):
|
||||||
config = dict(self.BASE_VALID_CONFIG, **{
|
config = self.extend_config({
|
||||||
'show_word_count': True
|
'show_word_count': True
|
||||||
})
|
})
|
||||||
context = get_context(config, 'testy test test')
|
context = get_context(config, 'testy test test')
|
||||||
|
@ -61,14 +61,14 @@ class ContextTestCase(BaseTestCase):
|
||||||
datetime.now().time(),
|
datetime.now().time(),
|
||||||
datetime.now()
|
datetime.now()
|
||||||
]:
|
]:
|
||||||
config = dict(self.BASE_VALID_CONFIG, **{
|
config = self.extend_config({
|
||||||
'submission_date': value
|
'submission_date': value
|
||||||
})
|
})
|
||||||
context = get_context(config, 'test')
|
context = get_context(config, 'test')
|
||||||
self.assertEqual(context['submission_date'], value.strftime(consts.DATE_FORMAT))
|
self.assertEqual(context['submission_date'], value.strftime(consts.DATE_FORMAT))
|
||||||
|
|
||||||
def test_date_format(self):
|
def test_date_format(self):
|
||||||
config = dict(self.BASE_VALID_CONFIG, **{
|
config = self.extend_config({
|
||||||
'submission_date': '2017-01-01'
|
'submission_date': '2017-01-01'
|
||||||
})
|
})
|
||||||
context = get_context(config, 'test')
|
context = get_context(config, 'test')
|
||||||
|
|
|
@ -44,14 +44,14 @@ class AddBodyClassTestCase(BaseTestCase):
|
||||||
class RenderTemplateTestCase(BaseTestCase):
|
class RenderTemplateTestCase(BaseTestCase):
|
||||||
def test_renders_template(self):
|
def test_renders_template(self):
|
||||||
html = 'test {{ test }}'
|
html = 'test {{ test }}'
|
||||||
output = content.render_template(html, dict(self.BASE_VALID_CONFIG, **{
|
output = content.render_template(html, self.extend_config({
|
||||||
'test': 'content'
|
'test': 'content'
|
||||||
}))
|
}))
|
||||||
self.assertEqual(output, 'test content')
|
self.assertEqual(output, 'test content')
|
||||||
|
|
||||||
def test_changes_nothing(self):
|
def test_changes_nothing(self):
|
||||||
html = 'test test'
|
html = 'test test'
|
||||||
output = content.render_template(html, dict(self.BASE_VALID_CONFIG, **{
|
output = content.render_template(html, self.extend_config({
|
||||||
'test': 'content'
|
'test': 'content'
|
||||||
}))
|
}))
|
||||||
self.assertEqual(output, html)
|
self.assertEqual(output, html)
|
||||||
|
|
Reference in a new issue