Ejemplo n.º 1
0
    def test_glacier_error_on_upload(self):

        dir1 = self._get_test_subdir('dir1')
        self._remove_db_if_exists(dir1)
        main = Main(glacier=GlacierErrorOnUploadMock)
        main.process_directory(dir1)
        main.close()
        logging.debug("Database at %s: %s", dir1,
            pprint.pformat(self._get_db_copy(dir1)))
        logging.debug("Log: %s", pprint.pformat(main.ctx.log))
Ejemplo n.º 2
0
    def test_glacier_ftp(self):

        def _wait_callback(buf):
            time.sleep(0.1)

        dir1 = self._get_test_subdir('dir1')
        self._remove_db_if_exists(dir1)
        main = Main(glacier=GlacierFtpBased)
        try:
            main.glacier.launch()
            main.glacier.wait_for_ftpserver()
            main.glacier.upload_file_ftp_callback = _wait_callback
            main.process_directory(dir1)
            main.close()
        finally:
            main.glacier.kill_ftp()
Ejemplo n.º 3
0
 def test_01_metadata_crated_when_doesnt_exists(self):
     """Tests that metadata is created when don't exists"""
     dir1 = self._get_test_subdir('dir1')
     # Remove DB if exists (of previous run of the tests)
     self._remove_db_if_exists(dir1)
     # Call process_directory()
     main = Main(glacier=GlacierMock)
     main.process_directory(dir1)
     main.close()
     # Check statistics
     logging.debug("Log: %s", pprint.pformat(main.ctx.log))
     self.assertEqual(main.ctx.included_count, 3)
     self.assertEqual(main.ctx.excluded_count, 0)
     # Check that local metadata was created
     db_filename = os.path.join(dir1, DB_FILENAME)
     database = gdbm.open(db_filename, 'c')
     logging.debug("Database at %s: %s", db_filename, pprint.pformat(database))
     for filename in ('file1.txt', 'file2.txt', 'file3.txt'):
         data = json.loads(database[filename])
         data['archive_id']
         data['stats.st_size']
         data['stats.st_mtime']
Ejemplo n.º 4
0
 def test_02_comparison_works_with_existing_metadata(self):
     """Tests that metadata is compared sucesfully when no change exists in files,
     and no file should be uploaded"""
     dir2 = self._get_test_subdir('dir2')
     # Create local metadata DB
     created_metadata = _generate_local_metadata_db(dir2,
         ('file1.txt', 'file2.txt', 'file3.txt'), overwrite=True)
     # Call process_directory()
     main = Main(glacier=GlacierMock)
     main.process_directory(dir2)
     main.close()
     # Check statistics
     logging.debug("Log: %s", pprint.pformat(main.ctx.log))
     self.assertEqual(main.ctx.included_count, 0)
     self.assertIn(main.ctx.excluded_count, [3, 4])
     # Check that local metadata wasn't changed
     db_filename = os.path.join(dir2, DB_FILENAME)
     database = gdbm.open(db_filename, 'c')
     logging.debug("Database at %s: %s", db_filename, pprint.pformat(database))
     for filename in ('file1.txt', 'file2.txt', 'file3.txt'):
         data = json.loads(database[filename])
         self.assertDictEqual(data,
             created_metadata[filename])
Ejemplo n.º 5
0
    def test_03_metadata_is_updated_and_files_changes_are_detected(self):
        """Tests metadata updates"""
        dir3 = self._get_test_subdir('dir3')
        # Remove files
        self._remove_db_if_exists(dir3)
        for filename in ('file2.txt', 'file3.txt'):
            try:
                os.unlink(os.path.join(dir3, filename))
            except OSError:
                pass

        # --- Call process_directory() ---
        main = Main(glacier=GlacierMock)
        main.process_directory(dir3)
        main.close()
        # Check statistics
        logging.debug("Log: %s", pprint.pformat(main.ctx.log))
        self.assertEqual(main.ctx.included_count, 1)  # file1.txt
        self.assertEqual(main.ctx.excluded_count, 0)

        # --- Call process_directory() ---
        for _ in range(0, 2):
            main = Main(glacier=GlacierMock)
            main.process_directory(dir3)
            main.close()
            # Check statistics
            logging.debug("Log: %s", pprint.pformat(main.ctx.log))
            self.assertEqual(main.ctx.included_count, 0)
            self.assertEqual(main.ctx.excluded_count, 2)  # .frockup.gdbm + file1.txt

        # --- Add `file2.txt`
        file2_path = os.path.join(dir3, 'file2.txt')
        shutil.copy2(os.path.join(dir3, '../dir2/file2.txt'), file2_path)

        # --- Call process_directory() ---
        main = Main(glacier=GlacierMock)
        main.process_directory(dir3)
        main.close()
        # Check statistics
        logging.debug("Log: %s", pprint.pformat(main.ctx.log))
        self.assertEqual(main.ctx.included_count, 1)  # file2.txt
        self.assertEqual(main.ctx.excluded_count, 2)  # .frockup.gdbm + file1.txt

        # --- Call process_directory() ---
        main = Main(glacier=GlacierMock)
        main.process_directory(dir3)
        main.close()
        # Check statistics
        logging.debug("Log: %s", pprint.pformat(main.ctx.log))
        self.assertEqual(main.ctx.included_count, 0)
        self.assertEqual(main.ctx.excluded_count, 3)  # .frockup.gdbm + file1.txt + file2.txt

        # --- Touch `file2.txt`
        os.utime(file2_path, (1, 1))

        # --- Call process_directory() ---
        main = Main(glacier=GlacierMock)
        main.process_directory(dir3)
        main.close()
        # Check statistics
        logging.debug("Log: %s", pprint.pformat(main.ctx.log))
        self.assertEqual(main.ctx.included_count, 1)  # file2.txt
        self.assertEqual(main.ctx.excluded_count, 2)  # .frockup.gdbm + file1.txt

        # Check `old_archive_ids`
        db = self._get_db_copy(dir3)
        self.assertTrue('old_archive_ids' in db['file2.txt'])
        self.assertEqual(len(db['file2.txt']['old_archive_ids']), 1)

        # --- Call process_directory() ---
        main = Main(glacier=GlacierMock)
        main.process_directory(dir3)
        main.close()
        # Check statistics
        logging.debug("Log: %s", pprint.pformat(main.ctx.log))
        self.assertEqual(main.ctx.included_count, 0)
        self.assertEqual(main.ctx.excluded_count, 3)  # .frockup.gdbm + file1.txt + file2.txt

        # Check `old_archive_ids`
        db = self._get_db_copy(dir3)
        self.assertTrue('old_archive_ids' in db['file2.txt'])
        self.assertEqual(len(db['file2.txt']['old_archive_ids']), 1)

        # --- Add data to `file2.txt`
        with open(file2_path, 'a') as f2_file_object:
            f2_file_object.write('\nA new Line\n')

        # --- Call process_directory() ---
        main = Main(glacier=GlacierMock)
        main.process_directory(dir3)
        main.close()
        # Check statistics
        logging.debug("Log: %s", pprint.pformat(main.ctx.log))
        self.assertEqual(main.ctx.included_count, 1)  # file2.txt
        self.assertEqual(main.ctx.excluded_count, 2)  # .frockup.gdbm + file1.txt

        # Check `old_archive_ids`
        db = self._get_db_copy(dir3)
        self.assertTrue('old_archive_ids' in db['file2.txt'])
        self.assertEqual(len(db['file2.txt']['old_archive_ids']), 2)

        # --- Call process_directory() ---
        main = Main(glacier=GlacierMock)
        main.process_directory(dir3)
        main.close()
        # Check statistics
        logging.debug("Log: %s", pprint.pformat(main.ctx.log))
        self.assertEqual(main.ctx.included_count, 0)
        self.assertEqual(main.ctx.excluded_count, 3)  # .frockup.gdbm + file1.txt + file2.txt

        # Check `old_archive_ids`
        db = self._get_db_copy(dir3)
        self.assertTrue('old_archive_ids' in db['file2.txt'])
        self.assertEqual(len(db['file2.txt']['old_archive_ids']), 2)

        logging.debug("Database at %s: %s", dir3,
            pprint.pformat(self._get_db_copy(dir3)))