Skip to content

Commit

Permalink
Merge pull request #126 from ecmwf-projects/1930-better-tests
Browse files Browse the repository at this point in the history
improving tests
  • Loading branch information
alex75 authored Aug 12, 2024
2 parents daa6c5a + 296b8e8 commit 791fbd3
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 36 deletions.
2 changes: 2 additions & 0 deletions cads_catalogue/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,8 @@ def update_catalogue_resources(
involved_resource_uids.append(resource_uid)
try:
with session.begin_nested():
# NOTE: here the change of dataset's override is not considered because
# any change of override file however imposes force mode
to_update, sources_hash = is_resource_to_update(
session, folders_to_consider_for_hash
)
Expand Down
8 changes: 4 additions & 4 deletions tests/data/layout2.json
Original file line number Diff line number Diff line change
Expand Up @@ -136,15 +136,15 @@
"id": "licence-to-use-copernicus-products",
"revision": 12,
"label": "Licence to use Copernicus Products",
"contents_url": "TESTDATAPAH/cads-licences/licence-to-use-copernicus-productsv12.md",
"attachment_url": "TESTDATAPAH/cads-licences/licence-to-use-copernicus-products.pdf"
"contents_url": "https://document/storage/url/mycatalogue_bucket/licences/licence-to-use-copernicus-products/test_storage_path.md",
"attachment_url": "https://document/storage/url/mycatalogue_bucket/licences/licence-to-use-copernicus-products/test_storage_path.pdf"
},
{
"id": "eumetsat-cm-saf",
"revision": 1,
"label": "EUMETSAT CM SAF products licence",
"contents_url": "TESTDATAPAH/cads-licences/eumetsat-cm-safv1.md",
"attachment_url": "TESTDATAPAH/cads-licences/eumetsat-cm-saf.pdf"
"contents_url": "https://document/storage/url/mycatalogue_bucket/licences/eumetsat-cm-saf/test_storage_path.md",
"attachment_url": "https://document/storage/url/mycatalogue_bucket/licences/eumetsat-cm-saf/test_storage_path.pdf"
}
]
}
Expand Down
76 changes: 44 additions & 32 deletions tests/test_30_layout_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -872,35 +872,47 @@ def test_has_section_id(tmpdir):
assert layout_manager.has_section_id(layout_data, "overview4") is False


# def test_transform_licences_blocks2(session_obj: sa.orm.sessionmaker):
# my_settings_dict = {
# "object_storage_url": "object/storage/url",
# "storage_admin": "admin1",
# "storage_password": "secret1",
# "catalogue_bucket": "mycatalogue_bucket",
# "document_storage_url": "my/url",
# }
# storage_settings = config.ObjectStorageSettings(**my_settings_dict)
# # add some licences to work on
# licences_folder_path = os.path.join(TESTDATA_PATH, "cads-licences")
# licences = licence_manager.load_licences_from_folder(licences_folder_path)
# with session_obj() as session:
# for licence in licences:
# session.add(database.Licence(**licence))
# session.commit()
# # all_licences = session.scalars(sa.select(database.Licence)).all()
#
# input_layout_path = os.path.join(TESTDATA_PATH, "layout1.json")
# with open(input_layout_path) as fp:
# input_layout_data = json.load(fp)
# out_layout_data = layout_manager.transform_licences_blocks2(
# session, input_layout_data, storage_settings
# )
# expected_layout_path = os.path.join(TESTDATA_PATH, "layout2.json")
# # with open(expected_layout_path, "w") as fp:
# # json.dump(out_layout_data, fp, indent=2)
# # TODO: test with effective document_storage_url
# # with open(expected_layout_path) as fp:
# # expected_layout_data = json.load(fp)
# # assert out_layout_data == expected_layout_data
# session.close()
def test_transform_licences_blocks2(session_obj: sa.orm.sessionmaker):
my_settings_dict = {
"object_storage_url": "https://object/storage/url/",
"storage_admin": "admin1",
"storage_password": "secret1",
"catalogue_bucket": "mycatalogue_bucket",
"document_storage_url": "https://document/storage/url/",
}
storage_settings = config.ObjectStorageSettings(**my_settings_dict)
# add some licences to work on
licences_folder_path = os.path.join(TESTDATA_PATH, "cads-licences")
licences = licence_manager.load_licences_from_folder(licences_folder_path)
with session_obj() as session:
for licence in licences:
# simulate upload to storage
licence["download_filename"] = os.path.join(
storage_settings.catalogue_bucket,
"licences",
licence["licence_uid"],
"test_storage_path.pdf",
)
licence["md_filename"] = os.path.join(
storage_settings.catalogue_bucket,
"licences",
licence["licence_uid"],
"test_storage_path.md",
)
session.add(database.Licence(**licence))
session.commit()
# all_licences = session.scalars(sa.select(database.Licence)).all()

input_layout_path = os.path.join(TESTDATA_PATH, "layout1.json")
with open(input_layout_path) as fp:
input_layout_data = json.load(fp)
out_layout_data = layout_manager.transform_licences_blocks2(
session, input_layout_data, storage_settings
)
expected_layout_path = os.path.join(TESTDATA_PATH, "layout2.json")
# with open(expected_layout_path, "w") as fp:
# json.dump(out_layout_data, fp, indent=2)
with open(expected_layout_path) as fp:
expected_layout_data = json.load(fp)
assert out_layout_data == expected_layout_data
session.close()

0 comments on commit 791fbd3

Please sign in to comment.