def _generate_metadata(self, modules): """ Generates the repository metadata document for all modules in the :type modules: list of pulp.plugins.model.AssociatedUnit """ _logger.info('Generating metadata for repository <%s>' % self.repo.id) # Convert the Pulp data types into the local model metadata = RepositoryMetadata() for m in modules: combined = copy.copy(m.unit_key) combined.update(m.metadata) module = Module.from_dict(combined) metadata.modules.append(module) # 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()
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'])
def _generate_metadata(self, modules): """ Generates the repository metadata document for all modules in the :type modules: list of pulp.plugins.model.AssociatedUnit """ _logger.info('Generating metadata for repository <%s>' % self.repo.id) # Convert the Pulp data types into the local model metadata = RepositoryMetadata() for m in modules: combined = copy.copy(m.unit_key) combined.update(m.metadata) module = Module.from_dict(combined) metadata.modules.append(module) # 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()
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'])
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"])