def test_success_export_then_import_different_users(self, mock_config_file): inv_manager = InventoryManager(mock_config_file[0]) lb = inv_manager.create_labbook('unittester', 'unittester', 'unittest-zip') with tempfile.TemporaryDirectory() as tempd: path = ZipExporter.export_labbook(lb.root_dir, tempd) newlb = ZipExporter.import_labbook(path, "unittester2", "unittester2", mock_config_file[0]) assert not os.path.exists(path) assert 'unittester2' == InventoryManager(mock_config_file[0]).query_owner(newlb) assert newlb.is_repo_clean # Now try with same user as exporter path2 = ZipExporter.export_labbook(lb.root_dir, tempd) shutil.rmtree(lb.root_dir) lb2 = ZipExporter.import_labbook(path2, "unittester", "unittester", mock_config_file[0]) assert 'unittester' == InventoryManager(mock_config_file[0]).query_owner(lb2) assert lb2.is_repo_clean
def export_labbook_as_zip(labbook_path: str, lb_export_directory: str) -> str: """Return path to archive file of exported labbook. """ p = os.getpid() logger = LMLogger.get_logger() logger.info(f"(Job {p}) Starting export_labbook_as_zip({labbook_path})") try: lb = InventoryManager().load_labbook_from_directory(labbook_path) with lb.lock(): path = ZipExporter.export_labbook(lb.root_dir, lb_export_directory) return path except Exception as e: logger.exception(f"(Job {p}) Error on export_labbook_as_zip: {e}") raise
def test_fail_export_not_a_labbook(self): # Pass in a valid directory, but one that is not an LB with pytest.raises(ZipWorkflowException): ZipExporter.export_labbook('/var', '.')
def test_fail_export_garbled_export(self): # Test giving a path that doesn't exist with pytest.raises(ZipWorkflowException): ZipExporter.export_labbook('/not/a/real/path', '.')