Beispiel #1
0
    def test_to_json(self):
        # Setup
        metadata = RepositoryMetadata()
        metadata.update_from_json(VALID_REPO_METADATA_JSON)

        # Test
        serialized = metadata.to_json()

        # Verify
        parsed = json.loads(serialized)

        self.assertEqual(2, len(parsed))

        sorted_modules = sorted(parsed, key=lambda x: x["name"])

        self.assertEqual(4, len(sorted_modules[0]))
        self.assertEqual(sorted_modules[0]["name"], "common")
        self.assertEqual(sorted_modules[0]["author"], "lab42")
        self.assertEqual(sorted_modules[0]["version"], "0.0.1")
        self.assertEqual(sorted_modules[0]["tag_list"], [])

        self.assertEqual(4, len(sorted_modules[1]))
        self.assertEqual(sorted_modules[1]["name"], "postfix")
        self.assertEqual(sorted_modules[1]["author"], "lab42")
        self.assertEqual(sorted_modules[1]["version"], "0.0.2")
        self.assertEqual(sorted_modules[1]["tag_list"], ["postfix", "applications"])
Beispiel #2
0
    def test_to_json(self):
        # Setup
        metadata = RepositoryMetadata()
        metadata.update_from_json(VALID_REPO_METADATA_JSON)

        # Test
        serialized = metadata.to_json()

        # Verify
        parsed = json.loads(serialized)

        self.assertEqual(2, len(parsed))

        sorted_modules = sorted(parsed, key=lambda x: x['name'])

        self.assertEqual(4, len(sorted_modules[0]))
        self.assertEqual(sorted_modules[0]['name'], 'common')
        self.assertEqual(sorted_modules[0]['author'], 'lab42')
        self.assertEqual(sorted_modules[0]['version'], '0.0.1')
        self.assertEqual(sorted_modules[0]['tag_list'], [])

        self.assertEqual(4, len(sorted_modules[1]))
        self.assertEqual(sorted_modules[1]['name'], 'postfix')
        self.assertEqual(sorted_modules[1]['author'], 'lab42')
        self.assertEqual(sorted_modules[1]['version'], '0.0.2')
        self.assertEqual(sorted_modules[1]['tag_list'],
                         ['postfix', 'applications'])
Beispiel #3
0
    def _generate_metadata(self, modules):
        """
        Generates the repository metadata document for all modules in the

        :param modules: list of modules in the repository; empty list if there are none
        :type modules: list of pulp_puppet.plugins.db.models.Module
        """
        msg = _('Generating metadata for repository <%(repo_id)s>')
        msg_dict = {'repo_id': self.repo.repo_id}
        _logger.info(msg, msg_dict)

        metadata = RepositoryMetadata()
        metadata.modules = modules

        # Write the JSON representation of the metadata to the repository
        json_metadata = metadata.to_json()
        build_dir = self._build_dir()
        metadata_file = os.path.join(build_dir, constants.REPO_METADATA_FILENAME)

        f = open(metadata_file, 'w')
        f.write(json_metadata)
        f.close()
Beispiel #4
0
    def _generate_metadata(self, modules):
        """
        Generates the repository metadata document for all modules in the

        :param modules: list of modules in the repository; empty list if there are none
        :type modules: list of pulp_puppet.plugins.db.models.Module
        """
        msg = _('Generating metadata for repository <%(repo_id)s>')
        msg_dict = {'repo_id': self.repo.repo_id}
        _logger.info(msg, msg_dict)

        metadata = RepositoryMetadata()
        metadata.modules = modules

        # Write the JSON representation of the metadata to the repository
        json_metadata = metadata.to_json()
        build_dir = self._build_dir()
        metadata_file = os.path.join(build_dir,
                                     constants.REPO_METADATA_FILENAME)

        f = open(metadata_file, 'w')
        f.write(json_metadata)
        f.close()