diff options
| author | 2014-06-13 21:51:02 -0300 | |
|---|---|---|
| committer | 2014-06-13 21:51:02 -0300 | |
| commit | 58c4878526dec5510f23c812274686787d8724ba (patch) | |
| tree | 5f2374bc17adb10e15f7e5b4576595d9cc2ef17e /tests/test_command_init.py | |
| parent | fa50632a9d87c3989566fed3e49c160a132e0d14 (diff) | |
Imported Upstream version 7.0.1upstream/7.0.1
Diffstat (limited to 'tests/test_command_init.py')
| -rw-r--r-- | tests/test_command_init.py | 57 |
1 files changed, 48 insertions, 9 deletions
diff --git a/tests/test_command_init.py b/tests/test_command_init.py index 4332213..d2171f8 100644 --- a/tests/test_command_init.py +++ b/tests/test_command_init.py @@ -11,13 +11,18 @@ import unittest import mock import nikola +from nikola.plugins.command.init import SAMPLE_CONF +from nikola.plugins.command.init import format_default_translations_config class CommandInitCallTest(unittest.TestCase): def setUp(self): + self.ask_questions = mock.MagicMock() self.copy_sample_site = mock.MagicMock() self.create_configuration = mock.MagicMock() self.create_empty_site = mock.MagicMock() + ask_questions_patch = mock.patch( + 'nikola.plugins.command.init.CommandInit.ask_questions', self.ask_questions) copy_sample_site_patch = mock.patch( 'nikola.plugins.command.init.CommandInit.copy_sample_site', self.copy_sample_site) create_configuration_patch = mock.patch( @@ -25,8 +30,8 @@ class CommandInitCallTest(unittest.TestCase): create_empty_site_patch = mock.patch( 'nikola.plugins.command.init.CommandInit.create_empty_site', self.create_empty_site) - self.patches = [copy_sample_site_patch, create_configuration_patch, - create_empty_site_patch] + self.patches = [ask_questions_patch, copy_sample_site_patch, + create_configuration_patch, create_empty_site_patch] for patch in self.patches: patch.start() @@ -42,16 +47,26 @@ class CommandInitCallTest(unittest.TestCase): del self.create_empty_site def test_init_default(self): - for arguments in (dict(options={'demo': True}, args=['destination']), {}): - self.init_command.execute(**arguments) + self.init_command.execute() - self.assertTrue(self.create_configuration.called) - self.assertTrue(self.copy_sample_site.called) - self.assertFalse(self.create_empty_site.called) + self.assertTrue(self.ask_questions.called) + self.assertTrue(self.create_configuration.called) + self.assertFalse(self.copy_sample_site.called) + self.assertTrue(self.create_empty_site.called) - def test_init_called_without_target(self): - self.init_command.execute() + def test_init_args(self): + arguments = dict(options={'demo': True, 'quiet': True}, args=['destination']) + self.init_command.execute(**arguments) + self.assertFalse(self.ask_questions.called) + self.assertTrue(self.create_configuration.called) + self.assertTrue(self.copy_sample_site.called) + self.assertFalse(self.create_empty_site.called) + + def test_init_called_without_target_quiet(self): + self.init_command.execute(**dict(options={'quiet': True})) + + self.assertFalse(self.ask_questions.called) self.assertFalse(self.create_configuration.called) self.assertFalse(self.copy_sample_site.called) self.assertFalse(self.create_empty_site.called) @@ -59,10 +74,34 @@ class CommandInitCallTest(unittest.TestCase): def test_init_empty_dir(self): self.init_command.execute(args=['destination']) + self.assertTrue(self.ask_questions.called) self.assertTrue(self.create_configuration.called) self.assertFalse(self.copy_sample_site.called) self.assertTrue(self.create_empty_site.called) +class InitHelperTests(unittest.TestCase): + """Test helper functions provided with the init command.""" + + def test_configure_translations_without_additional_languages(self): + """ + Testing the configuration of the translation when no additional language has been found. + """ + translations_cfg = format_default_translations_config(set()) + self.assertEqual(SAMPLE_CONF["TRANSLATIONS"], translations_cfg) + + def test_configure_translations_with_2_additional_languages(self): + """ + Testing the configuration of the translation when no additional language has been found. + """ + translations_cfg = format_default_translations_config( + set(["es", "en"])) + self.assertEqual("""{ + DEFAULT_LANG: "", + "en": "./en", + "es": "./es", +}""", translations_cfg) + + if __name__ == '__main__': unittest.main() |
