diff --git a/setup.py b/setup.py index 147515f..6a30923 100644 --- a/setup.py +++ b/setup.py @@ -43,7 +43,7 @@ def read(fname): ] dev_requires = test_requires + [ - 'ipdb==0.7', + 'pdbpp==0.7', 'ipython==0.13.2', 'Sphinx==1.1.3', 'flake8==2.0', diff --git a/src/facio/pipeline/__init__.py b/src/facio/hooks/__init__.py similarity index 74% rename from src/facio/pipeline/__init__.py rename to src/facio/hooks/__init__.py index 6e9080b..ffafb79 100644 --- a/src/facio/pipeline/__init__.py +++ b/src/facio/hooks/__init__.py @@ -1,8 +1,8 @@ # -*- coding: utf-8 -*- """ -.. module:: facio.pipeline - :synopsis: Pipeline detection and execution. +.. module:: facio.hooks + :synopsis: Hook detection and execution. """ import sys @@ -14,36 +14,36 @@ from yaml.scanner import ScannerError -class Pipeline(BaseFacio): +class Hook(BaseFacio): def __init__(self): - """ Pipeline class instanctiation. """ + """ Hook class instanctiation. """ self.calls = [] def load(self, path): - """ Parse the pipeline file. + """ Parse the hooks file. - :param path: Path to pipeline file, locally + :param path: Path to hooks file, locally :type path: str """ try: with open(path) as f: try: - self.pipeline = yaml.load(f.read()) + self.hooks = yaml.load(f.read()) except ScannerError: - self.warning('Error loading {0} pipeline - Is it ' + self.warning('Error loading {0} hooks - Is it ' 'correctly formatted?'.format(path)) else: - self.out('Loading Pipeline') + self.out('Loading hooks') except IOError: self.warning('{0} not found'.format(path)) def _validate_before(self): try: - if 'before' in self.pipeline: - if not type(self.pipeline.get('before')) == list: + if 'before' in self.hooks: + if not type(self.hooks.get('before')) == list: self.warning('Ignoring before: should be a list') return False else: @@ -54,8 +54,8 @@ def _validate_before(self): def _validate_after(self): try: - if 'after' in self.pipeline: - if not type(self.pipeline.get('after')) == list: + if 'after' in self.hooks: + if not type(self.hooks.get('after')) == list: self.warning('Ignoring after: should be a list') return False else: @@ -65,7 +65,7 @@ def _validate_after(self): return False def has_before(self): - """ Does the pipeline contain a before module list. + """ Does the hooks file contain a before list. :returns: Bool """ @@ -76,7 +76,7 @@ def has_before(self): return False def has_after(self): - """ Does the pipeline contain a after module list. + """ Does the hooks file contain a after list. :returns: Bool """ @@ -87,7 +87,7 @@ def has_after(self): return False def import_module(self, path): - """ Import module to run in before or post pipeline. + """ Import module to run in before or post hooks. :param path: The python path to the module :type path: str @@ -124,13 +124,13 @@ def run_module(self, path): e, traceback.tb_lineno)) self.calls.append({path: result}) - state.pipeline_save_call(path, result) + state.save_hook_call(path, result) return result def has_run(self, path): - """ Has a pipeline module run. + """ Has a hooks module run. - :param path: The pipeline python module path + :param path: The hooks python module path :type path: str :returns: False if not run else the modules returned data @@ -146,11 +146,11 @@ def has_run(self, path): def run_before(self): """ Run the before modules. """ - for path in self.pipeline.get('before', []): + for path in self.hooks.get('before', []): self.run_module(path) def run_after(self): """ Run the after modules. """ - for path in self.pipeline.get('after', []): + for path in self.hooks.get('after', []): self.run_module(path) diff --git a/src/facio/hooks/django/__init__.py b/src/facio/hooks/django/__init__.py new file mode 100644 index 0000000..abed441 --- /dev/null +++ b/src/facio/hooks/django/__init__.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- + +""" +.. module:: facio.hooks.django + :synopsis: hookss for Django related templates. +""" diff --git a/src/facio/pipeline/django/secret_key.py b/src/facio/hooks/django/secret.py similarity index 78% rename from src/facio/pipeline/django/secret_key.py rename to src/facio/hooks/django/secret.py index f126a27..e5b1af3 100644 --- a/src/facio/pipeline/django/secret_key.py +++ b/src/facio/hooks/django/secret.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- """ -.. module:: facio.pipeline.django.secret_key +.. module:: facio.hooks.django.secret_key :synopsis: Generates a Django Secret key and updates context_variables with a DJANGO_SECRET_KEY value. """ @@ -16,13 +16,18 @@ class GenerateDjangoSecretKey(BaseFacio): characters = 'abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)' def generate(self): + """ Generate Django secret key + + :returns: str -- The generated key + """ + self.out('Generating Django Secret Key') key = ''.join([choice(self.characters) for i in range(50)]) return key def run(): - """ Called by the ``facio.pipeline`` runner. """ + """ Called by the ``facio.hooks`` runner. """ generator = GenerateDjangoSecretKey() key = generator.generate() diff --git a/src/facio/hooks/python/__init__.py b/src/facio/hooks/python/__init__.py new file mode 100644 index 0000000..5c2c496 --- /dev/null +++ b/src/facio/hooks/python/__init__.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- + +""" +.. module:: facio.hooks.python + :synopsis: Bundled python hookss. +""" diff --git a/src/facio/pipeline/python/setup.py b/src/facio/hooks/python/setup.py similarity index 88% rename from src/facio/pipeline/python/setup.py rename to src/facio/hooks/python/setup.py index 62e54b3..ffb24b2 100644 --- a/src/facio/pipeline/python/setup.py +++ b/src/facio/hooks/python/setup.py @@ -1,8 +1,8 @@ # -*- coding: utf-8 -*- """ -.. module:: facio.pipeline.python.setup - :synopsis: Bundled pipeline for running python setup.py +.. module:: facio.hooks.python.setup + :synopsis: Bundled hooks for running python setup.py """ import os @@ -54,7 +54,7 @@ def get_install_arg(self): return arg def get_default_path_to_python(self): - """ Returns the default path to python, if virtualenv pipeline + """ Returns the default path to python, if virtualenv hooks has been called use that path, else use the current executing python, this should be the systems python in most cases. @@ -62,8 +62,8 @@ def get_default_path_to_python(self): """ # Returns path to virtualenv - call = state.pipeline_get_call_result( - 'facio.pipeline.python.virtualenv') + call = state.get_hook_call( + 'facio.hooks.python.virtualenv') if call: return os.path.join(call, 'bin', 'python') @@ -72,7 +72,7 @@ def get_default_path_to_python(self): def get_path_to_python(self): """ Gets the path to python to run setup.py against. - Detect if the virtualenv pipeline has run, if so the default + Detect if the virtualenv hooks has run, if so the default path to python should come from the path to this virtual environment, else it should be the system default python path. @@ -120,7 +120,7 @@ def run(self): def run(): - """ Called by pipeline runner, runs the setup class and returns Bool on + """ Called by hooks runner, runs the setup class and returns Bool on status of the run command. :returns: bool -- The state of running setup.py diff --git a/src/facio/pipeline/python/virtualenv.py b/src/facio/hooks/python/virtualenv.py similarity index 91% rename from src/facio/pipeline/python/virtualenv.py rename to src/facio/hooks/python/virtualenv.py index abcb824..c71d03d 100644 --- a/src/facio/pipeline/python/virtualenv.py +++ b/src/facio/hooks/python/virtualenv.py @@ -1,8 +1,8 @@ # -*- coding: utf-8 -*- """ -.. module:: facio.pipeline.python.virtualenv - :synopsis: Bundled pipeline for creating python virtual environments. +.. module:: facio.hooks.python.virtualenv + :synopsis: Bundled hooks for creating python virtual environments. """ import os @@ -52,7 +52,7 @@ def create(self): from sh import virtualenv as venv except ImportError: self.warning("Please install virtualenv to use the python " - "virtualenv pipeline") + "virtualenv hooks") return None else: path = self.get_path() @@ -71,7 +71,7 @@ def create(self): def run(): - """ Called from ``facio.pipeline`` runner. + """ Called from ``facio.hooks`` runner. :returns: str -- Path to the created virtual environment """ diff --git a/src/facio/pipeline/django/__init__.py b/src/facio/pipeline/django/__init__.py deleted file mode 100644 index d6c924c..0000000 --- a/src/facio/pipeline/django/__init__.py +++ /dev/null @@ -1,6 +0,0 @@ -# -*- coding: utf-8 -*- - -""" -.. module:: facio.pipeline.django - :synopsis: Pipelines for Django related templates. -""" diff --git a/src/facio/pipeline/python/__init__.py b/src/facio/pipeline/python/__init__.py deleted file mode 100644 index 86c0e17..0000000 --- a/src/facio/pipeline/python/__init__.py +++ /dev/null @@ -1,6 +0,0 @@ -# -*- coding: utf-8 -*- - -""" -.. module:: facio.pipeline.python - :synopsis: Bundled python pipelines. -""" diff --git a/src/facio/run.py b/src/facio/run.py index 505af34..8ca831a 100644 --- a/src/facio/run.py +++ b/src/facio/run.py @@ -37,7 +37,7 @@ def run(self): pipeline = Pipeline() pipeline.load(os.path.join( - state.get_project_root(), '.facio.pipeline.yml' + state.get_project_root(), '.facio.hooks.yml' )) if pipeline.has_before(): diff --git a/src/facio/state.py b/src/facio/state.py index c99b8bf..8d4b78c 100644 --- a/src/facio/state.py +++ b/src/facio/state.py @@ -121,9 +121,9 @@ def get_context_variable(self, name): variables = self.get_context_variables() return variables.get(name, None) - def pipeline_get_call_result(self, module_path): - """ Returns a pipeline call result, else returns false if the module - path is not in the pipeline call list. + def get_hook_call(self, module_path): + """ Returns a hook call result, else returns false if the module + path is not in the hook call list. :param module_path: The python dotted path to the module :type module_path: str @@ -132,7 +132,7 @@ def pipeline_get_call_result(self, module_path): """ try: - calls = self.state.pipeline_calls + calls = self.state.hook_calls except AttributeError: calls = [] @@ -143,8 +143,8 @@ def pipeline_get_call_result(self, module_path): return result - def pipeline_save_call(self, module_path, result): - """ Saves a pipeline call to state + def save_hook_call(self, module_path, result): + """ Saves a hook call to state :param module_path: The python dotted path to the module :type module_path: str @@ -156,13 +156,13 @@ def pipeline_save_call(self, module_path, result): """ try: - calls = self.state.pipeline_calls + calls = self.state.hook_calls except AttributeError: calls = [] - if not self.pipeline_get_call_result(module_path): + if not self.get_hook_call(module_path): calls.append((module_path, result)) - self.state.pipeline_calls = calls + self.state.hook_calls = calls return calls diff --git a/tests/test_pipeline.py b/tests/test_hooks/__init__.py similarity index 56% rename from tests/test_pipeline.py rename to tests/test_hooks/__init__.py index af2cd08..8fc63db 100644 --- a/tests/test_pipeline.py +++ b/tests/test_hooks/__init__.py @@ -1,38 +1,36 @@ # -*- coding: utf-8 -*- """ -.. module:: tests.test_pipeline - :synopsis: Tests for the facio pipeline module. +.. module:: tests.test_hooks + :synopsis: Tests for the facio hooks module. """ -import six - -from facio.pipeline import Pipeline +from facio.hooks import Hook from mock import MagicMock, mock_open, patch from random import choice -from . import BaseTestCase +from .. import BaseTestCase -class PipelineTest(BaseTestCase): - """ Pipeline Tests """ +class HookTest(BaseTestCase): + """ hooks Tests """ def setUp(self): self._patch_clint([ 'facio.base.puts', - 'facio.pipeline.Pipeline.out', - 'facio.pipeline.Pipeline.warning', - 'facio.pipeline.Pipeline.error', + 'facio.hooks.Hook.out', + 'facio.hooks.Hook.warning', + 'facio.hooks.Hook.error', ]) def _mock_open(self, data): - patcher = patch('facio.pipeline.open', + patcher = patch('facio.hooks.open', mock_open(read_data=data), create=True) return patcher def _module_factory(self, n): - """ Generate n number of mocked pipeline modules. + """ Generate n number of mocked hooks modules. :param n: Number of modules to generate :type n: int @@ -59,10 +57,10 @@ def test_can_load_yaml(self): open_mock = self._mock_open(data) open_mock.start() - p = Pipeline() - p.load('/foo/bar.yml') - self.mocked_facio_pipeline_Pipeline_out.assert_called_with( - 'Loading Pipeline') + i = Hook() + i.load('/foo/bar.yml') + self.mocked_facio_hooks_Hook_out.assert_called_with( + 'Loading hooks') open_mock.stop() @@ -78,10 +76,10 @@ def test_yaml_load_error_output(self): open_mock = self._mock_open(data) open_mock.start() - p = Pipeline() - p.load('/foo/bar.yml') - self.mocked_facio_pipeline_Pipeline_warning.assert_called_with( - "Error loading /foo/bar.yml pipeline - Is it correctly formatted?") + i = Hook() + i.load('/foo/bar.yml') + self.mocked_facio_hooks_Hook_warning.assert_called_with( + "Error loading /foo/bar.yml hooks - Is it correctly formatted?") open_mock.stop() def test_load_ioerror(self): @@ -89,13 +87,13 @@ def test_load_ioerror(self): m = open_mock.start() m.side_effect = IOError - p = Pipeline() - p.load('/foo/bar.yml') + i = Hook() + i.load('/foo/bar.yml') - self.mocked_facio_pipeline_Pipeline_warning.assert_called_with( + self.mocked_facio_hooks_Hook_warning.assert_called_with( "/foo/bar.yml not found") - self.assertFalse(p._validate_before()) - self.assertFalse(p._validate_after()) + self.assertFalse(i._validate_before()) + self.assertFalse(i._validate_after()) open_mock.stop() @@ -108,10 +106,10 @@ def test_yaml_formatted_correctly_before(self): open_mock = self._mock_open(data) open_mock.start() - p = Pipeline() - p.load('/foo/bar.yml') - self.assertFalse(p.has_before()) - self.mocked_facio_pipeline_Pipeline_warning.assert_called_with( + i = Hook() + i.load('/foo/bar.yml') + self.assertFalse(i.has_before()) + self.mocked_facio_hooks_Hook_warning.assert_called_with( 'Ignoring before: should be a list') open_mock.stop() @@ -125,24 +123,24 @@ def test_yaml_formatted_correctly_after(self): open_mock = self._mock_open(data) open_mock.start() - p = Pipeline() - p.load('/foo/bar.yml') - self.assertFalse(p.has_after()) - self.mocked_facio_pipeline_Pipeline_warning.assert_called_with( + i = Hook() + i.load('/foo/bar.yml') + self.assertFalse(i.has_after()) + self.mocked_facio_hooks_Hook_warning.assert_called_with( 'Ignoring after: should be a list') open_mock.stop() - def test_empty_pipeline_always_retuns_false(self): + def test_empty_hooks_always_retuns_false(self): data = """ """ open_mock = self._mock_open(data) open_mock.start() - p = Pipeline() - p.load('/foo/bar.yml') + i = Hook() + i.load('/foo/bar.yml') - self.assertFalse(p.has_before()) - self.assertFalse(p.has_after()) + self.assertFalse(i.has_before()) + self.assertFalse(i.has_after()) open_mock.stop() def test_has_before_true(self): @@ -153,9 +151,9 @@ def test_has_before_true(self): open_mock = self._mock_open(data) open_mock.start() - p = Pipeline() - p.load('/foo/bar.yml') - self.assertTrue(p.has_before()) + i = Hook() + i.load('/foo/bar.yml') + self.assertTrue(i.has_before()) open_mock.stop() @@ -167,9 +165,9 @@ def test_has_before_false(self): open_mock = self._mock_open(data) open_mock.start() - p = Pipeline() - p.load('/foo/bar.yml') - self.assertFalse(p.has_before()) + i = Hook() + i.load('/foo/bar.yml') + self.assertFalse(i.has_before()) open_mock.stop() @@ -181,9 +179,9 @@ def test_has_after_true(self): open_mock = self._mock_open(data) open_mock.start() - p = Pipeline() - p.load('/foo/bar.yml') - self.assertTrue(p.has_after()) + i = Hook() + i.load('/foo/bar.yml') + self.assertTrue(i.has_after()) open_mock.stop() @@ -195,60 +193,61 @@ def test_has_after_false(self): open_mock = self._mock_open(data) open_mock.start() - p = Pipeline() - p.load('/foo/bar.yml') - self.assertFalse(p.has_after()) + i = Hook() + i.load('/foo/bar.yml') + self.assertFalse(i.has_after()) open_mock.stop() - @patch('facio.pipeline.Pipeline.load', return_value=True) - @patch('facio.pipeline.import_module', return_value=True) + @patch('facio.hooks.Hook.load', return_value=True) + @patch('facio.hooks.import_module', return_value=True) def test_import_success(self, mock_importlib, mockload): - p = Pipeline() - p.load('/foo/bar.yml') - p.import_module('path.to.module') - self.mocked_facio_pipeline_Pipeline_out.assert_called_with( + i = Hook() + i.load('/foo/bar.yml') + i.import_module('path.to.module') + self.mocked_facio_hooks_Hook_out.assert_called_with( 'Loaded module: path.to.module') - @patch('facio.pipeline.Pipeline.load', return_value=True) + @patch('facio.hooks.Hook.load', return_value=True) def test_import_module_failure(self, mockload): - p = Pipeline() - p.load('/foo/bar.yml') - p.import_module('pipeline_test_module') - self.mocked_facio_pipeline_Pipeline_error.assert_called_with( - 'Failed to Load module: pipeline_test_module') + i = Hook() + i.load('/foo/bar.yml') + i.import_module('hooks_test_module') + + self.mocked_facio_hooks_Hook_error.assert_called_with( + 'Failed to Load module: hooks_test_module') - @patch('facio.pipeline.Pipeline.load', return_value=True) + @patch('facio.hooks.Hook.load', return_value=True) def test_run_module_success(self, mockload): - p = Pipeline() - p.load('/foo/bar.yml') - import_module_mock = patch('facio.pipeline.import_module') + i = Hook() + i.load('/foo/bar.yml') + import_module_mock = patch('facio.hooks.Hook.import_module') mock = import_module_mock.start() module = MagicMock() module.run.return_value = True mock.return_value = module - rtn = p.run_module('foo.bar.baz') + rtn = i.run_module('foo.bar.baz') + mock = import_module_mock.stop() self.assertTrue(module.run.called) self.assertTrue(rtn) - mock = import_module_mock.stop() - @patch('facio.pipeline.Pipeline.load', return_value=True) + @patch('facio.hooks.Hook.load', return_value=True) def test_run_module_failure(self, mockload): - p = Pipeline() - p.load('/foo/bar.yml') - import_module_mock = patch('facio.pipeline.import_module') + i = Hook() + i.load('/foo/bar.yml') + import_module_mock = patch('facio.hooks.Hook.import_module') mock = import_module_mock.start() module = MagicMock() module.run.side_effect = AttributeError mock.return_value = module - rtn = p.run_module('foo.bar.baz') + rtn = i.run_module('foo.bar.baz') + mock = import_module_mock.stop() self.assertTrue(module.run.called) self.assertFalse(rtn) - mock = import_module_mock.stop() - @patch('facio.pipeline.Pipeline.load', return_value=True) + @patch('facio.hooks.Hook.load', return_value=True) def test_module_exception_caught(self, mockload): - import_module_mock = patch('facio.pipeline.import_module') + import_module_mock = patch('facio.hooks.Hook.import_module') mock = import_module_mock.start() module = MagicMock() module.foo.side_effect = KeyError('Failed lookup') @@ -258,54 +257,55 @@ def fake_run(): module.foo() module.run = fake_run - p = Pipeline() - p.load('/foo/bar.yml') - p.run_module('foo.bar.baz') + i = Hook() + i.load('/foo/bar.yml') + i.run_module('foo.bar.baz') + mock = import_module_mock.stop() self.assertTrue(module.foo.called) - self.mocked_facio_pipeline_Pipeline_warning.assert_called_with( + self.mocked_facio_hooks_Hook_warning.assert_called_with( 'Exeption caught in module: \'Failed lookup\' line: 117') - mock = import_module_mock.stop() - @patch('facio.pipeline.Pipeline.load', return_value=True) - def test_store_pipeline_states(self, return_value=True): - p = Pipeline() - p.load('/foo/bar.yml') - import_module_mock = patch('facio.pipeline.import_module') + @patch('facio.hooks.Hook.load', return_value=True) + def test_store_hooks_states(self, return_value=True): + i = Hook() + i.load('/foo/bar.yml') + import_module_mock = patch('facio.hooks.Hook.import_module') mock_import = import_module_mock.start() mocked_modules = self._module_factory(3) for path, module in mocked_modules: mock_import.return_value = module - p.run_module(path) + i.run_module(path) self.assertTrue(module.run.called) - self.assertEqual(p.calls[-1:][0].get(path), + self.assertEqual(i.calls[-1:][0].get(path), module.run.return_value) - self.assertEquals(len(p.calls), 3) - mock_import = import_module_mock.stop() - @patch('facio.pipeline.Pipeline.load', return_value=True) - def test_pipeline_call_history_retrival(self, return_value=True): - p = Pipeline() - p.load('/foo/bar.yml') - import_module_mock = patch('facio.pipeline.import_module') + self.assertEquals(len(i.calls), 3) + + @patch('facio.hooks.Hook.load', return_value=True) + def test_hooks_call_history_retrival(self, return_value=True): + i = Hook() + i.load('/foo/bar.yml') + import_module_mock = patch('facio.hooks.Hook.import_module') mock_import = import_module_mock.start() mocked_modules = self._module_factory(10) for path, module in mocked_modules: mock_import.return_value = module - p.run_module(path) + i.run_module(path) + import_module_mock.stop() - self.assertFalse(p.has_run('not.in.facked.modules')) - self.assertEqual(p.has_run('foo.bar.baz2'), mocked_modules[1][1].run()) + self.assertFalse(i.has_run('not.in.facked.modules')) + self.assertEqual(i.has_run('foo.bar.baz2'), mocked_modules[1][1].run()) def test_run_before(self): data = """ before: - thing.foo.bar """ - import_module_mock = patch('facio.pipeline.import_module') + import_module_mock = patch('facio.hooks.Hook.import_module') mock_import = import_module_mock.start() mock_module = MagicMock() mock_module.run.return_value = True @@ -313,21 +313,21 @@ def test_run_before(self): open_mock = self._mock_open(data) open_mock.start() - p = Pipeline() - p.load('/foo/bar.yml') - p.run_before() - - self.assertTrue(mock_module.run.called) - self.assertTrue(p.has_run('thing.foo.bar')) + i = Hook() + i.load('/foo/bar.yml') + i.run_before() open_mock.stop() + self.assertTrue(mock_module.run.called) + self.assertTrue(i.has_run('thing.foo.bar')) + def test_run_after(self): data = """ after: - thing.foo.bar """ - import_module_mock = patch('facio.pipeline.import_module') + import_module_mock = patch('facio.hooks.import_module') mock_import = import_module_mock.start() mock_module = MagicMock() mock_module.run.return_value = True @@ -335,11 +335,11 @@ def test_run_after(self): open_mock = self._mock_open(data) open_mock.start() - p = Pipeline() - p.load('/foo/bar.yml') - p.run_after() + i = Hook() + i.load('/foo/bar.yml') + i.run_after() self.assertTrue(mock_module.run.called) - self.assertTrue(p.has_run('thing.foo.bar')) + self.assertTrue(i.has_run('thing.foo.bar')) open_mock.stop() diff --git a/tests/test_pipelines/test_django.py b/tests/test_hooks/test_django.py similarity index 60% rename from tests/test_pipelines/test_django.py rename to tests/test_hooks/test_django.py index e9dfa61..388924d 100644 --- a/tests/test_pipelines/test_django.py +++ b/tests/test_hooks/test_django.py @@ -1,12 +1,12 @@ # -*- coding: utf-8 -*- """ -.. module:: tests.test_pipeline.test_django - :synopsis: Tests for bundled django pipelines +.. module:: tests.test_hooks.test_django + :synopsis: Tests for bundled django hooks """ -from facio.pipeline.django.secret_key import GenerateDjangoSecretKey, run +from facio.hooks.django.secret import GenerateDjangoSecretKey, run from facio.state import state from mock import patch from six.moves import builtins @@ -19,7 +19,7 @@ class TestDjangoSecretKey(BaseTestCase): def setUp(self): self._patch_clint([ 'facio.base.puts', - 'facio.pipeline.django.secret_key.GenerateDjangoSecretKey.out', + 'facio.hooks.django.secret.GenerateDjangoSecretKey.out', ]) def tearDown(self): @@ -28,19 +28,20 @@ def tearDown(self): except AttributeError: pass - @patch('facio.pipeline.django.secret_key.choice', create=True) - @patch('facio.pipeline.django.secret_key.range', create=True) + @patch('facio.hooks.django.secret.choice', create=True) + @patch('facio.hooks.django.secret.range', create=True) def test_generate_key(self, mock_range, mock_choice): mock_range.return_value = [0, ] mock_choice.return_value = 'a' i = GenerateDjangoSecretKey() key = i.generate() + out = self.mocked_facio_hooks_django_secret_GenerateDjangoSecretKey_out self.assertEqual(key, 'a') - self.mocked_facio_pipeline_django_secret_key_GenerateDjangoSecretKey_out.assert_called_with('Generating Django Secret Key') # NOQA + out.assert_called_with('Generating Django Secret Key') - @patch('facio.pipeline.django.secret_key.GenerateDjangoSecretKey.generate') + @patch('facio.hooks.django.secret.GenerateDjangoSecretKey.generate') def test_run(self, mock_generate): mock_generate.return_value = 'foobarbaz' diff --git a/tests/test_pipelines/test_python.py b/tests/test_hooks/test_python.py similarity index 79% rename from tests/test_pipelines/test_python.py rename to tests/test_hooks/test_python.py index 88ec57f..13bce49 100644 --- a/tests/test_pipelines/test_python.py +++ b/tests/test_hooks/test_python.py @@ -1,15 +1,15 @@ # -*- coding: utf-8 -*- """ -.. module:: tests.test_pipeline.test_python - :synopsis: Tests for bundled python pipelines +.. module:: tests.test_hooks.test_python + :synopsis: Tests for bundled python hooks """ import os import sys -from facio.pipeline.python.setup import Setup, run as setup_run -from facio.pipeline.python.virtualenv import Virtualenv, run as venv_run +from facio.hooks.python.setup import Setup, run as setup_run +from facio.hooks.python.virtualenv import Virtualenv, run as venv_run from mock import MagicMock, mock_open, patch, PropertyMock from .. import BaseTestCase @@ -20,8 +20,8 @@ class TestPythonVirtualenv(BaseTestCase): def setUp(self): self._patch_clint([ 'facio.base.puts', - 'facio.pipeline.python.virtualenv.Virtualenv.warning', - 'facio.pipeline.python.virtualenv.Virtualenv.error', + 'facio.hooks.python.virtualenv.Virtualenv.warning', + 'facio.hooks.python.virtualenv.Virtualenv.error', ]) # Mocking State @@ -53,7 +53,7 @@ def test_get_name_default(self, mock_input): self.assertEqual(name, 'foo') @patch('facio.base.input') - @patch('facio.pipeline.python.virtualenv.Virtualenv.get_name', create=True) + @patch('facio.hooks.python.virtualenv.Virtualenv.get_name', create=True) def test_get_path(self, mock_get_name, mock_input): mock_get_name.return_value = 'baz' mock_input.return_value = '/foo/bar' @@ -64,7 +64,7 @@ def test_get_path(self, mock_get_name, mock_input): self.assertEqual(path, '/foo/bar/baz') @patch('facio.base.input') - @patch('facio.pipeline.python.virtualenv.Virtualenv.get_name', create=True) + @patch('facio.hooks.python.virtualenv.Virtualenv.get_name', create=True) def test_get_path_default(self, mock_get_name, mock_input): mock_get_name.return_value = 'baz' mock_input.return_value = '' @@ -77,7 +77,7 @@ def test_get_path_default(self, mock_get_name, mock_input): @patch('sh.virtualenv') @patch('facio.base.input') - @patch('facio.pipeline.python.virtualenv.Virtualenv.get_path', create=True) + @patch('facio.hooks.python.virtualenv.Virtualenv.get_path', create=True) def test_create(self, mock_get_path, mock_input, mock_virtualenv): mock_get_path.return_value = '/foo/bar/baz' mock_input.return_value = '' @@ -95,15 +95,15 @@ def test_create_import_error(self, mock_sh_import): i = Virtualenv() path = i.create() - warn = self.mocked_facio_pipeline_python_virtualenv_Virtualenv_warning + warn = self.mocked_facio_hooks_python_virtualenv_Virtualenv_warning self.assertEqual(path, None) warn.assert_called_with("Please install virtualenv to use the " - "python virtualenv pipeline") + "python virtualenv hooks") @patch('sh.virtualenv') @patch('facio.base.input') - @patch('facio.pipeline.python.virtualenv.Virtualenv.get_path', create=True) + @patch('facio.hooks.python.virtualenv.Virtualenv.get_path', create=True) def test_create_venv_exception(self, mock_get_path, mock_input, mock_virtualenv): mock_get_path.return_value = '/foo/bar/baz' @@ -111,7 +111,7 @@ def test_create_venv_exception(self, mock_get_path, mock_input, i = Virtualenv() path = i.create() - err = self.mocked_facio_pipeline_python_virtualenv_Virtualenv_error + err = self.mocked_facio_hooks_python_virtualenv_Virtualenv_error self.assertEqual(path, None) err.assert_called_with("Failed to create virtual " @@ -119,7 +119,7 @@ def test_create_venv_exception(self, mock_get_path, mock_input, @patch('sh.virtualenv') @patch('facio.base.input') - @patch('facio.pipeline.python.virtualenv.Virtualenv.get_path', create=True) + @patch('facio.hooks.python.virtualenv.Virtualenv.get_path', create=True) def test_run(self, mock_get_path, mock_input, mock_virtualenv): mock_get_path.return_value = '/foo/bar/baz' mock_input.return_value = 'n' @@ -134,8 +134,8 @@ class TestSetup(BaseTestCase): def setUp(self): self._patch_clint([ 'facio.base.puts', - 'facio.pipeline.python.setup.Setup.warning', - 'facio.pipeline.python.setup.Setup.error', + 'facio.hooks.python.setup.Setup.warning', + 'facio.hooks.python.setup.Setup.error', ]) # Mocking State @@ -163,7 +163,7 @@ def test_get_install_arg_input_error(self, mock_input): i = Setup() arg = i.get_install_arg() - e = self.mocked_facio_pipeline_python_setup_Setup_error + e = self.mocked_facio_hooks_python_setup_Setup_error self.assertEqual(arg, None) e.assert_called_with("You did not enter a valid setup.py arg") @@ -175,8 +175,8 @@ def test_get_default_python_path_current(self): self.assertEqual(sys.executable, path) def test_get_default_path_virtualenv(self): - self.mock_state.pipeline_calls = [( - 'facio.pipeline.python.virtualenv', '/foo/bar' + self.mock_state.hook_calls = [( + 'facio.hooks.python.virtualenv', '/foo/bar' )] i = Setup() @@ -184,7 +184,7 @@ def test_get_default_path_virtualenv(self): self.assertEqual('/foo/bar/bin/python', path) - @patch('facio.pipeline.python.setup.Setup.get_default_path_to_python') + @patch('facio.hooks.python.setup.Setup.get_default_path_to_python') @patch('facio.base.input') def test_get_python_path_default(self, mock_input, mock_default): mock_input.return_value = '' @@ -205,7 +205,7 @@ def test_get_python_path_input(self, mock_input): self.assertEqual(path, '/foo/bar/python') def test_log_errors(self): - patcher = patch('facio.pipeline.python.setup.open', + patcher = patch('facio.hooks.python.setup.open', mock_open(), create=True) m = patcher.start() @@ -218,10 +218,10 @@ def test_log_errors(self): patcher.stop() - @patch('facio.pipeline.python.setup.os.chdir') + @patch('facio.hooks.python.setup.os.chdir') @patch('facio.base.input') - @patch('facio.pipeline.python.setup.Setup.get_path_to_python') - @patch('facio.pipeline.python.setup.subprocess.Popen') + @patch('facio.hooks.python.setup.Setup.get_path_to_python') + @patch('facio.hooks.python.setup.subprocess.Popen') @patch('facio.state.pwd') def test_run_zero_exit_code( self, @@ -250,11 +250,11 @@ def test_run_zero_exit_code( stderr=-1, stdout=-1) - @patch('facio.pipeline.python.setup.Setup.log_errors') - @patch('facio.pipeline.python.setup.os.chdir') + @patch('facio.hooks.python.setup.Setup.log_errors') + @patch('facio.hooks.python.setup.os.chdir') @patch('facio.base.input') - @patch('facio.pipeline.python.setup.Setup.get_path_to_python') - @patch('facio.pipeline.python.setup.subprocess.Popen') + @patch('facio.hooks.python.setup.Setup.get_path_to_python') + @patch('facio.hooks.python.setup.subprocess.Popen') @patch('facio.state.pwd') def test_run_non_zero_exit_code( self, @@ -284,10 +284,10 @@ def test_run_non_zero_exit_code( stderr=-1, stdout=-1) - @patch('facio.pipeline.python.setup.os.chdir') + @patch('facio.hooks.python.setup.os.chdir') @patch('facio.base.input') - @patch('facio.pipeline.python.setup.Setup.get_path_to_python') - @patch('facio.pipeline.python.setup.subprocess.Popen') + @patch('facio.hooks.python.setup.Setup.get_path_to_python') + @patch('facio.hooks.python.setup.subprocess.Popen') @patch('facio.state.pwd') def test_run( self, diff --git a/tests/test_pipelines/__init__.py b/tests/test_pipelines/__init__.py deleted file mode 100644 index 3739bf5..0000000 --- a/tests/test_pipelines/__init__.py +++ /dev/null @@ -1,6 +0,0 @@ -# -*- coding: utf-8 -*- - -""" -.. module:: tests.test_pipeline - :synopsis: Tests for bundled pipelines -""" diff --git a/tests/test_state.py b/tests/test_state.py index 0cebf1d..823bad6 100644 --- a/tests/test_state.py +++ b/tests/test_state.py @@ -79,20 +79,20 @@ def test_get_context_variable(self): self.assertEqual(state.get_context_variable('PROJECT_NAME'), 'foo') self.assertNotEqual(state.get_context_variable('not_created'), 'foo') - def test_pipeline_call_save(self): + def test_save_hook_call(self): state = State() - state.pipeline_save_call('foo.bar', 'baz') - state.pipeline_save_call('baz.foo', 'bar') - calls = state.pipeline_save_call('foo.bar', 'baz') + state.save_hook_call('foo.bar', 'baz') + state.save_hook_call('baz.foo', 'bar') + calls = state.save_hook_call('foo.bar', 'baz') self.assertEqual(calls, [('foo.bar', 'baz'), ('baz.foo', 'bar')]) - def test_pipeline_get_call(self): + def test_get_hook_call(self): state = State() - state.pipeline_save_call('foo.bar', 'baz') - state.pipeline_save_call('baz.foo', 'bar') + state.save_hook_call('foo.bar', 'baz') + state.save_hook_call('baz.foo', 'bar') - self.assertEqual(state.pipeline_get_call_result('foo.bar'), 'baz') - self.assertEqual(state.pipeline_get_call_result('baz.foo'), 'bar') + self.assertEqual(state.get_hook_call('foo.bar'), 'baz') + self.assertEqual(state.get_hook_call('baz.foo'), 'bar')