How to use the perceval.archive.ArchiveManager function in perceval

To help you get started, we’ve selected a few perceval examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github chaoss / grimoirelab-perceval / tests / test_backend.py View on Github external
def test_archive_manager_on_init(self, mock_expanduser):
        """Test if the archive manager is set when the class is initialized"""

        mock_expanduser.return_value = self.test_path

        args = ['-u', 'jsmith', '-p', '1234', '-t', 'abcd',
                '--from-date', '2015-01-01', '--tag', 'test',
                '--output', self.fout_path, 'http://example.com/']

        cmd = MockedBackendCommand(*args)

        manager = cmd.archive_manager
        self.assertIsInstance(manager, ArchiveManager)
        self.assertEqual(os.path.exists(manager.dirpath), True)
        self.assertEqual(manager.dirpath, self.test_path)

        # Due to '--no-archive' is given, Archive Manager isn't set
        args = ['-u', 'jsmith', '-p', '1234', '-t', 'abcd',
                '--no-archive', '--from-date', '2015-01-01',
                '--tag', 'test', '--output', self.fout_path,
                'http://example.com/']

        cmd = MockedBackendCommand(*args)
        self.assertEqual(cmd.archive_manager, None)
github chaoss / grimoirelab-perceval / tests / test_archive.py View on Github external
def test_search_archived_after(self):
        """Check if a set of archives created after a given date are searched"""

        archive_mng_path = os.path.join(self.test_path, ARCHIVE_TEST_DIR)
        manager = ArchiveManager(archive_mng_path)

        # First set of archives to create
        metadata = [
            {
                'origin': 'https://example.com',
                'backend_name': 'git',
                'backend_version': '0.8',
                'category': 'commit',
                'backend_params': {},
            },
            {
                'origin': 'https://example.com',
                'backend_name': 'gerrit',
                'backend_version': '0.1',
                'category': 'changes',
                'backend_params': {}
github chaoss / grimoirelab-kingarthur / tests / test_jobs.py View on Github external
job = PercevalJob('1234567890', 8, 'mytask',
                          'git', 'commit',
                          self.conn, 'items')
        args = {
            'uri': 'http://example.com/',
            'gitpath': os.path.join(self.dir, 'data/git_log.txt')
        }
        archive_args = {
            'archive_path': self.tmp_path,
            'fetch_from_archive': False
        }

        job.run(args, archive_args)

        self.assertIsInstance(job.archive_manager, ArchiveManager)
        result = job.result
        self.assertIsInstance(job.result, JobResult)
        self.assertEqual(result.job_id, '1234567890')
        self.assertEqual(result.job_number, 8)
        self.assertEqual(result.task_id, 'mytask')
        self.assertEqual(result.backend, 'git')
        self.assertEqual(result.category, 'commit')
        self.assertEqual(result.summary.last_uuid, '1375b60d3c23ac9b81da92523e4144abc4489d4c')
        self.assertEqual(result.summary.max_updated_on,
                         datetime.datetime(2014, 2, 12, 6, 10, 39, tzinfo=UTC))
        self.assertEqual(result.summary.last_updated_on,
                         datetime.datetime(2012, 8, 14, 17, 30, 13, tzinfo=UTC))
        self.assertEqual(result.summary.fetched, 9)
        self.assertEqual(result.summary.last_offset, None)

        commits = self.conn.lrange('items', 0, -1)
github chaoss / grimoirelab-perceval / tests / test_backend.py View on Github external
def test_archive(self):
        """Test whether a set of items is fetched from the archive"""

        manager = ArchiveManager(self.test_path)

        category = 'mock_item'
        args = {
            'origin': 'http://example.com/',
            'tag': 'test',
            'subtype': 'mocksubtype',
            'from-date': str_to_datetime('2015-01-01')
        }

        # First, fetch the items twice to check if several archive
        # are used
        items = fetch(CommandBackend, args, category, manager=manager)
        items = [item for item in items]
        self.assertEqual(len(items), 5)

        items = fetch(CommandBackend, args, category, manager=manager)
github chaoss / grimoirelab-perceval / tests / test_archive.py View on Github external
def test_remove_archive_not_found(self):
        """Test if an exception is raised when the archive is not found"""

        archive_mng_path = os.path.join(self.test_path, ARCHIVE_TEST_DIR)
        manager = ArchiveManager(archive_mng_path)

        with self.assertRaisesRegex(ArchiveManagerError, 'archive mockarchive does not exist'):
            manager.remove_archive('mockarchive')
github chaoss / grimoirelab-perceval / tests / test_archive.py View on Github external
def test_struct(self):
        """Test whether the structure of an archive manager directory is created"""

        archive_mng_path = os.path.join(self.test_path, ARCHIVE_TEST_DIR)

        # Directory does not exist yet
        self.assertEqual(os.path.isdir(archive_mng_path), False)

        # Object and directory are created
        manager = ArchiveManager(archive_mng_path)
        self.assertEqual(manager.dirpath, archive_mng_path)
        self.assertEqual(os.path.isdir(archive_mng_path), True)

        # A new object using the same directory does not create
        # a new directory
        alt_manager = ArchiveManager(archive_mng_path)
        self.assertEqual(alt_manager.dirpath, archive_mng_path)
        self.assertEqual(os.path.isdir(archive_mng_path), True)
github chaoss / grimoirelab-perceval / tests / test_backend.py View on Github external
def test_archived_after(self):
        """Test if only those items archived after a date are returned"""

        manager = ArchiveManager(self.test_path)

        category = 'mock_item'
        args = {
            'origin': 'http://example.com/',
            'tag': 'test',
            'subtype': 'mocksubtype',
            'from-date': str_to_datetime('2015-01-01')
        }

        items = fetch(CommandBackend, args, category, manager=manager)
        items = [item for item in items]
        self.assertEqual(len(items), 5)

        archived_dt = datetime_utcnow()

        items = fetch(CommandBackend, args, category, manager=manager)
github chaoss / grimoirelab-perceval / tests / test_archive.py View on Github external
def test_search_no_match(self):
        """Check if an empty set of archives is returned when none match the criteria"""

        archive_mng_path = os.path.join(self.test_path, ARCHIVE_TEST_DIR)
        manager = ArchiveManager(archive_mng_path)

        dt = datetime_utcnow()
        metadata = [
            {
                'origin': 'https://example.com',
                'backend_name': 'git',
                'backend_version': '0.8',
                'category': 'commit',
                'backend_params': {},
            },
            {
                'origin': 'https://example.com',
                'backend_name': 'gerrit',
                'backend_version': '0.1',
                'category': 'changes',
                'backend_params': {}
github chaoss / grimoirelab-kingarthur / arthur / jobs.py View on Github external
def initialize_archive_manager(self, archive_path):
        """Initialize the archive manager.

        :param archive_path: path where the archive manager is located
        """
        if archive_path == "":
            raise ValueError("Archive manager path cannot be empty")

        if archive_path:
            self.archive_manager = perceval.archive.ArchiveManager(archive_path)
github chaoss / grimoirelab-perceval / perceval / backend.py View on Github external
def _initialize_archive(self):
        """Initialize archive based on the parsed parameters."""

        if 'archive_path' not in self.parsed_args:
            manager = None
        elif self.parsed_args.no_archive:
            manager = None
        else:
            if not self.parsed_args.archive_path:
                archive_path = os.path.expanduser(ARCHIVES_DEFAULT_PATH)
            else:
                archive_path = self.parsed_args.archive_path

            manager = ArchiveManager(archive_path)

        self.archive_manager = manager