class TestCreate(BaseTestCase):
    def setUp(self):
        self.plugins_name = "fuel_plugin"
        self.plugin_path = "/tmp/{0}".format(self.plugins_name)
        self.template_dir = "/temp_dir"
        self.creator = CreatePlugin(self.plugin_path)
        self.creator.template_dir = self.template_dir

    @mock.patch("fuel_plugin_builder.actions.create.utils.exists", return_value=False)
    def test_check(self, exists_mock):
        self.creator.check()
        exists_mock.assert_called_once_with(self.plugin_path)

    @mock.patch("fuel_plugin_builder.actions.create.utils.exists", return_value=True)
    def test_check_when_plugin_exists_with_same_name(self, exists_mock):
        self.assertRaisesRegexp(
            errors.PluginDirectoryExistsError,
            "Plugins directory {0} already exists, " "choose another name".format(self.plugin_path),
            self.creator.check,
        )
        exists_mock.assert_called_once_with(self.plugin_path)

    @mock.patch("fuel_plugin_builder.actions.create.utils.exists", return_value=False)
    def test_check_with_invalid_name(self, exists_mock):
        self.creator.plugin_name = "Test_plugin"
        self.assertRaisesRegexp(
            errors.ValidationError, messages.PLUGIN_WRONG_NAME_EXCEPTION_MESSAGE, self.creator.check
        )
        exists_mock.assert_called_once_with(self.plugin_path)

    @mock.patch.object(CreatePlugin, "check")
    @mock.patch("fuel_plugin_builder.actions.create.utils")
    def test_run(self, utils_mock, _):
        self.creator.run()
        utils_mock.render_files_in_dir(self.template_dir, self.creator.render_ctx)
class TestCreate(BaseTestCase):

    def setUp(self):
        self.plugins_name = 'fuel_plugin'
        self.plugin_path = '/tmp/{0}'.format(self.plugins_name)
        self.template_dir = '/temp_dir'
        self.creator = CreatePlugin(self.plugin_path)
        self.creator.template_dir = self.template_dir

    @mock.patch('fuel_plugin_builder.actions.create.utils.exists',
                return_value=False)
    def test_check(self, exists_mock):
        self.creator.check()
        exists_mock.assert_called_once_with(self.plugin_path)

    @mock.patch('fuel_plugin_builder.actions.create.utils.exists',
                return_value=True)
    def test_check_raises_errors(self, exists_mock):
        self.assertRaisesRegexp(
            errors.PluginDirectoryExistsError,
            'Plugins directory {0} already exists, '
            'choose another name'.format(self.plugin_path),
            self.creator.check)
        exists_mock.assert_called_once_with(self.plugin_path)

    @mock.patch.object(CreatePlugin, 'check')
    @mock.patch('fuel_plugin_builder.actions.create.utils')
    def test_run(self, utils_mock, _):
        self.creator.run()
        utils_mock.render_files_in_dir(
            self.template_dir,
            self.creator.render_ctx)
class TestCreate(BaseTestCase):

    def setUp(self):
        self.plugins_name = 'fuel_plugin'
        self.plugin_path = '/tmp/{0}'.format(self.plugins_name)
        self.template_dir = '/temp_dir'
        self.creator = CreatePlugin(self.plugin_path)
        self.creator.template_dir = self.template_dir

    @mock.patch('fuel_plugin_builder.actions.create.utils.exists',
                return_value=False)
    def test_check(self, exists_mock):
        self.creator.check()
        exists_mock.assert_called_once_with(self.plugin_path)

    @mock.patch('fuel_plugin_builder.actions.create.utils.exists',
                return_value=True)
    def test_check_when_plugin_exists_with_same_name(self, exists_mock):
        self.assertRaisesRegexp(
            errors.PluginDirectoryExistsError,
            'Plugins directory {0} already exists, '
            'choose another name'.format(self.plugin_path),
            self.creator.check)
        exists_mock.assert_called_once_with(self.plugin_path)

    @mock.patch('fuel_plugin_builder.actions.create.utils.exists',
                return_value=False)
    def test_check_with_invalid_name(self, exists_mock):
        self.creator.plugin_name = 'Test_plugin'
        self.assertRaisesRegexp(
            errors.ValidationError,
            messages.PLUGIN_WRONG_NAME_EXCEPTION_MESSAGE,
            self.creator.check)
        exists_mock.assert_called_once_with(self.plugin_path)

    @mock.patch.object(CreatePlugin, 'check')
    @mock.patch('fuel_plugin_builder.actions.create.utils')
    def test_run(self, utils_mock, _):
        self.creator.run()
        utils_mock.render_files_in_dir(
            self.template_dir,
            self.creator.render_ctx)