def test_write_and_set_mod_time(self): """ Check that the file gets written and that its mod time gets set. """ with TempDir() as temp_dir: file_path = os.path.join(temp_dir, "test.txt") download_dest = DownloadDestLocalFile(file_path) with download_dest.make_file_context("file_id", "file_name", 100, "content_type", "sha1", {}, 1500222333000) as f: f.write(b'hello world\n') with open(file_path, 'rb') as f: self.assertEqual(b'hello world\n', f.read()) self.assertEqual(1500222333, os.path.getmtime(file_path))
def test_write_and_set_mod_time_and_progress(self): """ Check that the file gets written and that its mod time gets set. """ with TempDir() as temp_dir: file_path = os.path.join(temp_dir, "test.txt") download_local_file = DownloadDestLocalFile(file_path) progress_listener = ProgressListenerForTest() download_dest = DownloadDestProgressWrapper( download_local_file, progress_listener) with download_dest.make_file_context("file_id", "file_name", 100, "content_type", "sha1", {}, 1500222333000) as f: f.write(b'hello world\n') with open(file_path, 'rb') as f: self.assertEqual(b'hello world\n', f.read()) self.assertEqual(1500222333, os.path.getmtime(file_path)) self.assertEqual( [ 'set_total_bytes(100)', 'bytes_completed(12)', 'close()', ], progress_listener.get_calls(), )
def _fetch_remote_db(self, db_path): db_bucket_path = os.path.join(self.path, ".b2mirror.db") self.log.info("Fetching tracking db from bucket ({}) to {}".format( db_bucket_path, db_path)) try: self.bucket.download_file_by_name(db_bucket_path, DownloadDestLocalFile(db_path)) except b2exception.UnknownError as e: if '404 not_found' in e.message: return False else: raise return True
def _make_dest(self, temp_dir): file_path = os.path.join(temp_dir, "test.txt") return DownloadDestLocalFile(file_path), file_path