def test_activate_ok(self):
        '''This test case ensures an extension is activated correctly.'''

        extensions_folder = "tmp_modules"
        root_folder = instantiator.get_component_path_data(SettingsFacade().get_config().__class__)[1]

        extensions_path = "%s%s" % (root_folder, extensions_folder)

        if os.path.exists(extensions_path):
            shutil.rmtree(extensions_path)

        os.mkdir(extensions_path)

        argv = ["fantastico", "activate-extension", "--name", "dynamic_menu", "--comp-root", "tmp_modules"]

        main(argv)

        comp_path = "%s/dynamic_menu" % (extensions_path)

        self.assertTrue(os.path.exists(comp_path))
        self.assertTrue(os.path.exists("%s/tests" % comp_path))
        self.assertTrue(os.path.exists("%s/sql" % comp_path))
        self.assertTrue(os.path.exists("%s/menu_controller.py" % comp_path))
        self.assertTrue(os.path.exists("%s/menu_exceptions.py" % comp_path))
        self.assertTrue(os.path.exists("%s/__init__.py" % comp_path))
        self.assertFalse(os.path.exists("%s/models" % comp_path))
    def exec(self, os_lib=os):
        '''This method is executed to activate the given extension name.'''

        comp_name = self._arguments.name
        contrib_path = instantiator.get_package_abslocation(contrib)
        comp_path = "%s%s" % (contrib_path, comp_name)

        if not os_lib.path.exists(comp_path):
            raise FantasticoSdkCommandNotFoundError(
                "Extension %s does not exist." % comp_name)

        file_matcher = lambda abspath, filename: True
        root_folder = instantiator.get_component_path_data(
            SettingsFacade().get_config().__class__)[1]
        comp_root_folder = "%s%s/%s" % (root_folder, self._arguments.comp_root,
                                        comp_name)

        if not os_lib.path.exists(comp_root_folder):
            os_lib.mkdir(comp_root_folder)

        instantiator.scan_folder_by_criteria(
                            comp_path, file_matcher,
                            action=lambda abspath, filename: \
                                self._link_files(abspath, filename, contrib_path, root_folder, os_lib),
                            os_lib=os_lib)
    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 exec(self, os_lib=os):
        """This method is executed to activate the given extension name."""

        comp_name = self._arguments.name
        contrib_path = instantiator.get_package_abslocation(contrib)
        comp_path = "%s%s" % (contrib_path, comp_name)

        if not os_lib.path.exists(comp_path):
            raise FantasticoSdkCommandNotFoundError("Extension %s does not exist." % comp_name)

        file_matcher = lambda abspath, filename: True
        root_folder = instantiator.get_component_path_data(SettingsFacade().get_config().__class__)[1]
        comp_root_folder = "%s%s/%s" % (root_folder, self._arguments.comp_root, comp_name)

        if not os_lib.path.exists(comp_root_folder):
            os_lib.mkdir(comp_root_folder)

        instantiator.scan_folder_by_criteria(
            comp_path,
            file_matcher,
            action=lambda abspath, filename: self._link_files(abspath, filename, contrib_path, root_folder, os_lib),
            os_lib=os_lib,
        )
Beispiel #5
0
    def _get_class_root_folder(self):
        '''This methods determines the root folder under which the test is executed.'''

        return instantiator.get_component_path_data(self.__class__)[1]
Beispiel #6
0
    def _get_root_folder(self):
        '''This method determines the root folder under which core is executed.'''

        return instantiator.get_component_path_data(BasicSettings)[1]
Beispiel #7
0
    def get_root_folder(self):
        '''Method used to return the root folder of the current fantastico project (detected starting from settings)
        profile used.'''

        return instantiator.get_component_path_data(self.get_config().__class__)[1]
Beispiel #8
0
    def get_root_folder(self):
        '''Method used to return the root folder of the current fantastico project (detected starting from settings)
        profile used.'''

        return instantiator.get_component_path_data(
            self.get_config().__class__)[1]
    def get_component_folder(self):
        '''This method is used to retrieve the component folder name under which this controller is defined.'''

        root_folder = self._settings_facade.get_root_folder()

        return instantiator.get_component_path_data(self.__class__, root_folder)[0]
Beispiel #10
0
    def _get_class_root_folder(self):
        '''This methods determines the root folder under which the test is executed.'''

        return instantiator.get_component_path_data(self.__class__)[1]
Beispiel #11
0
    def _get_root_folder(self):
        '''This method determines the root folder under which core is executed.'''

        return instantiator.get_component_path_data(BasicSettings)[1]