Ejemplo n.º 1
0
    def test_backup_and_recover_cache(self):
        """Test if it does a backup of the cache and recovers its data"""

        # Create a new job with and empty cache
        job = PercevalJob('arthur-job-1234567890', 'mytask', 'git',
                          self.conn, 'items')
        job.initialize_cache(self.tmp_path)

        contents = [item for item in job.cache.retrieve()]
        self.assertEqual(len(contents), 0)

        items = [1, 2, 3, 4, 5]
        job.cache.store(*items)

        # Initialize a new job and make a backup of the data
        job = PercevalJob('arthur-job-1234567890-bis', 'mytask', 'git',
                          self.conn, 'items')
        job.initialize_cache(self.tmp_path, backup=True)

        contents = [item for item in job.cache.retrieve()]
        self.assertListEqual(contents, items)

        # Hard cleaning of the cache data
        job.cache.clean()
        contents = [item for item in job.cache.retrieve()]
        self.assertListEqual(contents, [])

        # Recover the data
        job.recover_cache()
        contents = [item for item in job.cache.retrieve()]
        self.assertListEqual(contents, items)
Ejemplo n.º 2
0
    def test_recover_unitialized_cache(self):
        """Test if not fails recovering from a cache not initialized"""

        job = PercevalJob('arthur-job-1234567890', 'mytask', 'git',
                          self.conn, 'items')
        self.assertEqual(job.cache, None)

        job.recover_cache()
        self.assertEqual(job.cache, None)