Example #1
0
class IntPDTester(unittest.TestCase):

    __pfd__ = {
        'name': 'sonata-project-sample',
        'vendor': 'com.sonata.project',
        'version': '0.0.1',
        'maintainer': 'Name, Company, Contact',
        'description': 'Project description',
        'catalogues': ['personal'],
        'publish_to': ['personal']
    }

    def __init__(self, *args, **kwargs):
        super(IntPDTester, self).__init__(*args, **kwargs)
        ws = Workspace("")
        prj = Project(ws, '/')
        self.pck = Packager(workspace=ws, project=prj, generate_pd=False)

    def test_correct_gds(self):
        """ Test the correct general description section """
        gsd = self.pck.package_gds(IntPDTester.__pfd__)
        self.assertNotEqual(gsd, False)

    def test_incomplete_gds(self):
        """
        Test the returning message when the provided
        project has incomplete information.
        """
        pfd = IntPDTester.__pfd__
        pfd.pop('name')
        gsd = self.pck.package_gds(pfd)
        self.assertEqual(gsd, False)
Example #2
0
 def pack(self, output_path):
     """
     Use son-package to pack the given packet.
     :param output_path: resulting packages are placed in output_path
     :return: package path
     """
     start_time = time.time()
     pkg_destination_path = os.path.join(output_path, self.pkg_name())
     # obtain workspace
     # TODO have workspace dir as command line argument
     workspace = Workspace.__create_from_descriptor__(
         Workspace.DEFAULT_WORKSPACE_DIR)
     if workspace is None:
         LOG.error("Couldn't initialize workspace: %r. Abort." %
                   Workspace.DEFAULT_WORKSPACE_DIR)
         exit(1)
     # obtain project
     project = Project.__create_from_descriptor__(workspace,
                                                  self.pkg_service_path)
     if project is None:
         LOG.error("Packager couldn't load service project: %r. Abort." %
                   self.pkg_service_path)
         exit(1)
     # initialize and run packager
     pck = Packager(workspace, project, dst_path=pkg_destination_path)
     pck.generate_package(os.path.join(output_path, self.pkg_name()))
     self.pkg_package_path = os.path.join(output_path,
                                          self.pkg_name()) + ".son"
     self.pkg_file_size = os.path.getsize(self.pkg_package_path)
     self.pack_time = time.time() - start_time
     return self.pkg_package_path
Example #3
0
 def pack(self, output_path, verbose=False, workspace_dir=Workspace.DEFAULT_WORKSPACE_DIR):
     """
     Creates a *.son file of this service object.
     First writes the normal project structure to disk (to be used with packaging tool)
     """
     start_time = time.time()
     tmp_path = self._write(output_path)
     pkg_path = os.path.join(output_path, self.pkg_name) + ".son"
     LOG.warning(pkg_path)
     self.metadata["package_disk_path"] = pkg_path
     # be sure the target directory exists
     ensure_dir(output_path)
     # obtain workspace
     # TODO have workspace dir as command line argument
     workspace = Workspace.__create_from_descriptor__(workspace_dir)
     if workspace is None:
         LOG.error("Couldn't initialize workspace: %r. Abort." % workspace_dir)
         exit(1)
     # force verbosity of external tools if required
     workspace.log_level = "DEBUG" if verbose else "INFO"
     # obtain project
     project = Project.__create_from_descriptor__(workspace, tmp_path)
     if project is None:
         LOG.error("Packager couldn't load service project: %r. Abort." % tmp_path)
         exit(1)
     # initialize and run packager
     pck = Packager(workspace, project, dst_path=output_path)
     pck.generate_package(self.pkg_name)
     self.metadata["package_disk_size"] = os.path.getsize(pkg_path)
     self.metadata["package_generation_time"] = time.time() - start_time
     LOG.debug("Packed: {} to {}".format(self, pkg_path))
     return pkg_path
Example #4
0
    def test_generate_package(self, m_zipfile, m_join):
        """
        Ensures that a package file is created with correct name and location
        """
        # First, create a workspace to give to Packager
        workspace = Workspace("ws/root", ws_name="ws_test", log_level='debug')

        # Create project
        project = Project(workspace, 'prj/path')

        # Instantiate a Packager instance
        packager = Packager(workspace=workspace,
                            project=project,
                            generate_pd=False,
                            dst_path="dst/path")

        packager._package_descriptor = True

        # Prepare mocks
        context_manager_mock = Mock()
        m_zipfile.ZipFile.return_value = context_manager_mock
        enter_mock = Mock()
        exit_mock = Mock()
        setattr(context_manager_mock, '__enter__', enter_mock)
        setattr(context_manager_mock, '__exit__', exit_mock)

        # execute
        packager.generate_package("package_name")

        # make assertions
        self.assertEqual(m_join.call_args_list[-1],
                         mock.call('dst/path', 'package_name.son'))
Example #5
0
 def pack(self, output_path):
     """
     Use son-package to pack the given packet.
     :param output_path: resulting packages are placed in output_path
     :return: package path
     """
     start_time = time.time()
     pkg_destination_path = os.path.join(output_path, self.pkg_name())
     # obtain workspace
     # TODO have workspace dir as command line argument
     workspace = Workspace.__create_from_descriptor__(Workspace.DEFAULT_WORKSPACE_DIR)
     if workspace is None:
         LOG.error("Couldn't initialize workspace: %r. Abort." % Workspace.DEFAULT_WORKSPACE_DIR)
         exit(1)
     # obtain project
     project = Project.__create_from_descriptor__(workspace, self.pkg_service_path)
     if project is None:
         LOG.error("Packager couldn't load service project: %r. Abort." % self.pkg_service_path)
         exit(1)
     # initialize and run packager
     pck = Packager(workspace, project, dst_path=pkg_destination_path)
     pck.generate_package(os.path.join(output_path, self.pkg_name()))
     self.pkg_package_path = os.path.join(output_path, self.pkg_name()) + ".son"
     self.pkg_file_size = os.path.getsize(self.pkg_package_path)
     self.pack_time = time.time() - start_time
     return self.pkg_package_path
Example #6
0
    def test_package_gds(self):
        """
        Test the validation of the project general description section
        """
        # First, create a workspace to give to Packager
        workspace = Workspace("ws/root", ws_name="ws_test", log_level="debug")

        # Create project
        project = Project(workspace, "prj/path")

        # Instantiate a Packager instance
        packager = Packager(workspace=workspace, project=project, generate_pd=False, dst_path="dst/path")

        packager._package_descriptor = True

        # Create fake project configuration
        prj_config = {
            "catalogues": "[personal]",
            "description": "Project description",
            "vendor": "eu.sonata.project",
            "maintainer": "Name, Company, Contact",
            "publish_to": "[personal]",
            "version": "0.0.1",
        }

        # Remove keys, one by one...
        for key in prj_config:
            value = prj_config.pop(key)
            self.assertFalse(packager.package_gds(prj_config))
            prj_config[key] = value

        # Make prj_config complete...
        prj_config["name"] = "sonata - project - sample"

        self.assertTrue(packager.package_gds(prj_config))
Example #7
0
    def test_generate_package(self, m_zipfile, m_join, m_validator, m_hash):
        """
        Ensures that a package file is created with correct name and location
        """
        # First, create a workspace to give to Packager
        workspace = Workspace("ws/root", ws_name="ws_test", log_level="debug")

        # Create project
        project = Project(workspace, "prj/path")

        # Instantiate a Packager instance
        packager = Packager(workspace=workspace, project=project, generate_pd=False, dst_path="dst/path")

        packager._package_descriptor = True

        # Prepare mocks
        context_manager_mock = Mock()
        m_zipfile.ZipFile.return_value = context_manager_mock
        enter_mock = Mock()
        exit_mock = Mock()
        setattr(context_manager_mock, "__enter__", enter_mock)
        setattr(context_manager_mock, "__exit__", exit_mock)
        m_validator.validate_package.return_value = True
        m_hash.return_value = ""

        # execute
        packager.generate_package("package_name")

        # make assertions
        self.assertEqual(m_join.call_args_list[-1], mock.call("dst/path", "package_name.son"))
Example #8
0
    def test_package_gds(self):
        """
        Test the validation of the project general description section
        """
        # First, create a workspace to give to Packager
        workspace = Workspace("ws/root", ws_name="ws_test", log_level='debug')

        # Create project
        project = Project(workspace, 'prj/path')

        # Instantiate a Packager instance
        packager = Packager(workspace=workspace,
                            project=project,
                            generate_pd=False,
                            dst_path="dst/path")

        packager._package_descriptor = True

        # Create fake project configuration
        prj_config = {
            'version': '0.5',
            'package': {
                'version': '0.1',
                'name': 'sonata-project-sample',
                'vendor': 'com.sonata.project',
                'maintainer': 'Name, Company, Contact',
                'description': 'Project description',
            },
            'descriptor_extension': 'yml'
        }

        # Remove package keys, one by one...
        for key in prj_config['package']:
            value = prj_config['package'].pop(key)
            self.assertIsNone(packager.package_gds(prj_config))
            prj_config['package'][key] = value

        # Make prj_config complete...
        prj_config['name'] = 'sonata - project - sample'

        self.assertTrue(packager.package_gds(prj_config))
    def test_package_gds(self):
        """
        Test the validation of the project general description section
        """
        # First, create a workspace to give to Packager
        workspace = Workspace("ws/root", ws_name="ws_test", log_level='debug')

        # Create project
        project = Project(workspace, 'prj/path')

        # Instantiate a Packager instance
        packager = Packager(workspace=workspace,
                            project=project,
                            generate_pd=False,
                            dst_path="dst/path")

        packager._package_descriptor = True

        # Create fake project configuration
        prj_config = {
            'catalogues': '[personal]',
            'description': 'Project description',
            'vendor': 'eu.sonata.project',
            'maintainer': 'Name, Company, Contact',
            'publish_to': '[personal]',
            'version': '0.0.1'
            }

        # Remove keys, one by one...
        for key in prj_config:
            value = prj_config.pop(key)
            self.assertFalse(packager.package_gds(prj_config))
            prj_config[key] = value

        # Make prj_config complete...
        prj_config['name'] = 'sonata - project - sample'

        self.assertTrue(packager.package_gds(prj_config))
Example #10
0
 def pack(self,
          output_path,
          verbose=False,
          workspace_dir=Workspace.DEFAULT_WORKSPACE_DIR):
     """
     Creates a *.son file of this service object.
     First writes the normal project structure to disk (to be used with packaging tool)
     """
     start_time = time.time()
     tmp_path = self._write(output_path)
     pkg_path = os.path.join(output_path, self.pkg_name) + ".son"
     LOG.warning(pkg_path)
     self.metadata["package_disk_path"] = pkg_path
     # be sure the target directory exists
     ensure_dir(output_path)
     # obtain workspace
     # TODO have workspace dir as command line argument
     workspace = Workspace.__create_from_descriptor__(workspace_dir)
     if workspace is None:
         LOG.error("Couldn't initialize workspace: %r. Abort." %
                   workspace_dir)
         exit(1)
     # force verbosity of external tools if required
     workspace.log_level = "DEBUG" if verbose else "INFO"
     # obtain project
     project = Project.__create_from_descriptor__(workspace, tmp_path)
     if project is None:
         LOG.error("Packager couldn't load service project: %r. Abort." %
                   tmp_path)
         exit(1)
     # initialize and run packager
     pck = Packager(workspace, project, dst_path=output_path)
     pck.generate_package(self.pkg_name)
     self.metadata["package_disk_size"] = os.path.getsize(pkg_path)
     self.metadata["package_generation_time"] = time.time() - start_time
     LOG.debug("Packed: {} to {}".format(self, pkg_path))
     return pkg_path
Example #11
0
 def __init__(self, *args, **kwargs):
     super(IntPDTester, self).__init__(*args, **kwargs)
     ws = Workspace("")
     prj = Project(ws, '/')
     self.pck = Packager(workspace=ws, project=prj, generate_pd=False)