def test_activate_extenstion_notfound(self):
        '''This test case ensures a concrete exception is thrown when we try to activate an inexistent extension.'''

        comp_name = "component-not-found-triplex"
        expected_comp_path = "%s%s" % (instantiator.get_package_abslocation(contrib), comp_name)

        self._mocked_os_path.exists = Mock(return_value=False)

        argv = [SdkCommandActivateExtension.get_name(), "--name", comp_name, "--comp-root", "samples"]

        cmd_activate = SdkCommandActivateExtension(argv, cmd_factory=None)

        with self.assertRaises(FantasticoSdkCommandNotFoundError):
            cmd_activate.exec_command(self._mocked_os)

        self._mocked_os_path.exists.assert_called_once_with(expected_comp_path)
    def test_activate_extension_long_ok(self):
        '''This method ensures activate-extension correctly creates the symlink on filesystem.'''

        comp_name = "dynamic-menu"
        comp_root_folder = "fantastico/samples"
        argv = [SdkCommandActivateExtension.get_name(), "--name", comp_name, "--comp-root", comp_root_folder]

        self._mock_activate_ok_scenario(comp_name, comp_root_folder, argv)
    def _mock_activate_ok_scenario(self, comp_name, comp_root_folder, argv):
        '''This method mocks the success scenario for activate extension.'''

        root_folder = instantiator.get_component_path_data(SettingsFacade().get_config().__class__)[1]
        comp_root = "%s%s/%s" % (root_folder, comp_root_folder, comp_name)
        expected_comp_path = "%s%s" % (instantiator.get_package_abslocation(contrib), comp_name)

        comp_structure = ["__init__.py", "sql", "models", "dynamic_menus.py"]

        linking_trace = {}
        remove_trace = []

        def list_comp(dirname):
            '''This method mocks listdir method from os library.'''

            if dirname == expected_comp_path:
                return comp_structure

        def symlink(src, dest, holder=linking_trace):
            '''This method mocks the symlink method from os library.'''

            holder[src] = dest

        def file_exists(filename):
            if filename == comp_root:
                return False

            return True

        def remove(filename, remove_trace=remove_trace):
            remove_trace.append(filename)

        self._mocked_os.path.exists = file_exists
        self._mocked_os.remove = remove
        self._mocked_os.mkdir = Mock()
        self._mocked_os.listdir = list_comp
        self._mocked_os.symlink = symlink

        cmd_activate = SdkCommandActivateExtension(argv, cmd_factory=None)

        cmd_activate.exec_command(os_lib=self._mocked_os)

        self._assert_ok_scenario_results(comp_structure, expected_comp_path, linking_trace, remove_trace, comp_root)
 def assert_action(help_str):
     self.assertTrue(help_str.startswith("usage: %s" % SdkCommandActivateExtension.get_help()))
     self.assertTrue(help_str.find("-n NAME, --name NAME") > -1)
     self.assertTrue(help_str.find("-p COMP_ROOT, --comp-root COMP_ROOT") > -1)