From 0b5c8ac5bbccfe18b733239d11c016722c4809ee Mon Sep 17 00:00:00 2001 From: schroeder5 <s.schroeder@fz-juelich.de> Date: Tue, 11 Feb 2025 08:56:46 +0000 Subject: [PATCH] fixed the patching of a station's annotations --- tests/test_stationmeta.py | 14 +++++++++----- toardb/stationmeta/crud.py | 7 +++++++ 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/tests/test_stationmeta.py b/tests/test_stationmeta.py index beba349..8bdc98a 100644 --- a/tests/test_stationmeta.py +++ b/tests/test_stationmeta.py @@ -933,10 +933,11 @@ class TestApps: def test_patch_stationmeta_roles_and_annotations(self, client, db): -# {"annotations": [{"kind": "User", response = client.patch("/stationmeta/SDZ54421?description=adding annotation text", json={"stationmeta": - {"annotations": [{"kind": 0, + {"roles": [{"role": "PointOfContact", "contact_id": 3, "status": "Active"}, + {"role": "Originator", "contact_id": 1, "status": "Active"}], + "annotations": [{"kind": "User", "text": "some annotation text", "date_added": "2025-02-10 17:00", "approved": True, @@ -953,10 +954,13 @@ class TestApps: response = client.get(f"/stationmeta/id/{response_json['station_id']}") response_json = response.json() assert response_json['annotations'] == [{'id': 1, 'kind': 'user comment', 'text': 'some annotation text', 'date_added': '2025-02-10T17:00:00+00:00', 'approved': True, 'contributor_id': 1}] -# assert response_json['changelog'][1]['old_value'] == ... -# assert response_json['changelog'][1]['new_value'] == ... + assert response_json['changelog'][1]['old_value'] == "{'roles': {{'role': 'ResourceProvider', 'status': 'Active', 'contact_id': 5},}" + assert response_json['changelog'][1]['new_value'] == ( + "{'roles': [{'role': 'PointOfContact', 'contact_id': 3, 'status': 'Active'}, " + "{'role': 'Originator', 'contact_id': 1, 'status': 'Active'}], " + "'annotations': [{'kind': 'User', 'text': 'some annotation text', 'date_added': '2025-02-10 17:00', 'approved': True, 'contributor_id': 1}]}" ) assert response_json['changelog'][1]['author_id'] == 1 - assert response_json['changelog'][1]['type_of_change'] == 'single value correction in metadata' + assert response_json['changelog'][1]['type_of_change'] == 'comprehensive metadata revision' def test_delete_roles_from_stationmeta(self, client, db): diff --git a/toardb/stationmeta/crud.py b/toardb/stationmeta/crud.py index 2c1f869..a8e61f7 100644 --- a/toardb/stationmeta/crud.py +++ b/toardb/stationmeta/crud.py @@ -210,6 +210,11 @@ def get_unique_stationmeta_annotation(db: Session, text: str, contributor_id: in return db_object +# is this internal, or should this also go to public REST api? +def get_stationmeta_annotations(db: Session, station_id: int): + return db.execute(select([stationmeta_core_stationmeta_annotations_table]).where(stationmeta_core_stationmeta_annotations_table.c.station_id == station_id)) + + def get_stationmeta_global(db: Session, station_id: int): db_object = db.query(models.StationmetaGlobal).filter(models.StationmetaGlobal.station_id == station_id) \ .first() @@ -243,6 +248,7 @@ def determine_stationmeta_global(db, tmp_coordinates, country): globalmeta_dict[db_service.variable_name] = value return globalmeta_dict + def create_stationmeta(db: Session, engine: Engine, stationmeta: StationmetaCreate, author_id: int, force: bool): stationmeta_dict = stationmeta.dict() @@ -503,6 +509,7 @@ def patch_stationmeta(db: Session, description: str, number_of_commas = number_of_commas - 1 for a in annotations_data: db_annotation = models.StationmetaAnnotation(**a) + db_annotation.kind = get_value_from_str(toardb.toardb.AK_vocabulary,db_annotation.kind) # check whether annotation is already present in database db_object = get_unique_stationmeta_annotation(db, db_annotation.text, db_annotation.contributor_id) if db_object: -- GitLab