diff --git a/nomad/processing/data.py b/nomad/processing/data.py index 406f7d8383ced52e85475e7a6931f3f24603b41d..53897cfade8eed11eceb394948f2ae09b30fe5e6 100644 --- a/nomad/processing/data.py +++ b/nomad/processing/data.py @@ -538,6 +538,7 @@ class Upload(Proc): with utils.lnr(logger, '(re-)publish failed'): upload_with_metadata = self.to_upload_with_metadata(self.metadata) + calcs = upload_with_metadata.calcs if config.repository_db.publish_enabled: if config.repository_db.mode == 'coe' and isinstance(self.upload_files, StagingUploadFiles): @@ -555,13 +556,10 @@ class Upload(Proc): coe_upload = coe_repo.Upload.publish(upload_with_metadata) with utils.timer( - logger, 'upload read from repository', step='repo', + logger, 'upload PIDs read from repository', step='repo', upload_size=self.upload_files.size): - calcs = [ - coe_calc.to_calc_with_metadata() - for coe_calc in coe_upload.calcs] - else: - calcs = upload_with_metadata.calcs + for calc, coe_calc in zip(calcs, coe_upload.calcs): + calc.pid = coe_calc.coe_calc_id with utils.timer( logger, 'upload metadata updated', step='metadata', diff --git a/tests/processing/test_data.py b/tests/processing/test_data.py index 5fa79b1b946c7f48ad7f1b67fc550b96da8b3ffa..e56455c6d10848459d2a006b6a8a8d1b80749d3b 100644 --- a/tests/processing/test_data.py +++ b/tests/processing/test_data.py @@ -64,7 +64,7 @@ def run_processing(uploaded: Tuple[str, str], test_user) -> Upload: return upload -def assert_processing(upload: Upload): +def assert_processing(upload: Upload, published: bool = False): assert not upload.tasks_running assert upload.current_task == 'cleanup' assert upload.upload_id is not None @@ -72,25 +72,33 @@ def assert_processing(upload: Upload): assert upload.tasks_status == SUCCESS upload_files = UploadFiles.get(upload.upload_id, is_authorized=lambda: True) - assert isinstance(upload_files, StagingUploadFiles) + if published: + assert isinstance(upload_files, PublicUploadFiles) + else: + assert isinstance(upload_files, StagingUploadFiles) for calc in Calc.objects(upload_id=upload.upload_id): assert calc.parser is not None assert calc.mainfile is not None assert calc.tasks_status == SUCCESS + assert calc.metadata['published'] == published with upload_files.archive_file(calc.calc_id) as archive_json: archive = json.load(archive_json) assert 'section_run' in archive assert 'section_entry_info' in archive - with upload_files.archive_log_file(calc.calc_id) as f: + with upload_files.archive_log_file(calc.calc_id, 'rt') as f: assert 'a test' in f.read() assert len(calc.errors) == 0 with upload_files.raw_file(calc.mainfile) as f: f.read() + for path in calc.metadata['files']: + with upload_files.raw_file(path) as f: + f.read() + assert upload.get_calc(calc.calc_id).metadata is not None @@ -125,6 +133,8 @@ def test_publish(non_empty_processed: Upload, no_warn, example_user_metadata, wi if with_publish_to_coe_repo and config.repository_db.mode == 'coe': assert(os.path.exists(os.path.join(config.fs.coe_extracted, upload.upload_id))) + assert_processing(Upload.get(upload.upload_id, include_published=True), published=True) + def test_republish(non_empty_processed: Upload, no_warn, example_user_metadata, monkeypatch, with_publish_to_coe_repo): processed = non_empty_processed diff --git a/tests/test_coe_repo.py b/tests/test_coe_repo.py index b1a5d8c4d2e7073316949080b627c3514bce8cbc..1b8d2c3bffa8052df6ebbb2ecf2e6c94431dfe3c 100644 --- a/tests/test_coe_repo.py +++ b/tests/test_coe_repo.py @@ -82,6 +82,9 @@ def assert_coe_calc(coe_calc: Calc, calc: datamodel.DFTCalcWithMetadata, has_han assert len(coe_calc.files) == len(calc.files) assert coe_calc.formula == calc.formula + # calc files + assert len(coe_calc.files) == len(calc.files) + # user meta data assert coe_calc.comment == calc.comment assert len(coe_calc.references) == len(calc.references)