Esempio n. 1
0
    def test_update_from_json(self):
        # Test
        metadata = RepositoryMetadata()
        metadata.update_from_json(VALID_REPO_METADATA_JSON)

        # Verify
        self.assertEqual(2, len(metadata.modules))
        for m in metadata.modules:
            self.assertTrue(isinstance(m, Module))

        sorted_modules = sorted(metadata.modules, key=lambda x: x.name)

        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(sorted_modules[0].description, None)
        self.assertEqual(sorted_modules[0].project_page, None)

        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'])
        self.assertEqual(sorted_modules[1].description, None)
        self.assertEqual(sorted_modules[1].project_page, None)
Esempio n. 2
0
    def test_update_from_json(self):
        # Test
        metadata = RepositoryMetadata()
        metadata.update_from_json(VALID_REPO_METADATA_JSON)

        # Verify
        self.assertEqual(2, len(metadata.modules))
        for m in metadata.modules:
            self.assertTrue(isinstance(m, Module))

        sorted_modules = sorted(metadata.modules, key=lambda x : x.name)

        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].tags, [])
        self.assertEqual(sorted_modules[0].description, None)
        self.assertEqual(sorted_modules[0].project_page, None)

        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].tags, ['postfix', 'applications'])
        self.assertEqual(sorted_modules[1].description, None)
        self.assertEqual(sorted_modules[1].project_page, None)
Esempio n. 3
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'])
Esempio n. 4
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'])
    def test_update_from_json(self):
        # Test
        metadata = RepositoryMetadata()
        metadata.update_from_json(VALID_REPO_METADATA_JSON)

        # Verify
        self.assertEqual(2, len(metadata.modules))
        for m in metadata.modules:
            self.assertTrue(isinstance(m, Module))

        sorted_modules = sorted(metadata.modules, key=lambda x: x.name)

        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(sorted_modules[0].description, None)
        self.assertEqual(sorted_modules[0].project_page, None)

        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"])
        self.assertEqual(sorted_modules[1].description, None)
        self.assertEqual(sorted_modules[1].project_page, None)
    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"])
Esempio n. 7
0
            end_time = datetime.now()
            duration = end_time - start_time
            self.progress_report.metadata_execution_time = duration.seconds

            self.progress_report.update_progress()

            return None

        finally:
            self.downloader = None

        # Parse the retrieved metadata documents
        try:
            metadata = RepositoryMetadata()
            for doc in metadata_json_docs:
                metadata.update_from_json(doc)
        except Exception, e:
            _logger.exception('Exception parsing metadata for repository <%s>' % self.repo.id)
            self.progress_report.metadata_state = STATE_FAILED
            self.progress_report.metadata_error_message = _('Error parsing repository modules metadata document')
            self.progress_report.metadata_exception = e
            self.progress_report.metadata_traceback = sys.exc_info()[2]

            end_time = datetime.now()
            duration = end_time - start_time
            self.progress_report.metadata_execution_time = duration.seconds

            self.progress_report.update_progress()

            return None
Esempio n. 8
0
            end_time = datetime.now()
            duration = end_time - start_time
            self.progress_report.metadata_execution_time = duration.seconds

            self.progress_report.update_progress()

            return None

        finally:
            self.downloader = None

        # Parse the retrieved metadata documents
        try:
            metadata = RepositoryMetadata()
            for doc in metadata_json_docs:
                metadata.update_from_json(doc)
        except Exception, e:
            _logger.exception(
                'Exception parsing metadata for repository <%s>' %
                self.repo.id)
            self.progress_report.metadata_state = STATE_FAILED
            self.progress_report.metadata_error_message = _(
                'Error parsing repository modules metadata document')
            self.progress_report.metadata_exception = e
            self.progress_report.metadata_traceback = sys.exc_info()[2]

            end_time = datetime.now()
            duration = end_time - start_time
            self.progress_report.metadata_execution_time = duration.seconds

            self.progress_report.update_progress()