diff --git a/tests/test_stationmeta.py b/tests/test_stationmeta.py index beba3499fc09fc8023317c03a12721d8c0f9bdd4..8bdc98ae9b94aad2e5f8ecca0f12038ab6a1f67a 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 2c1f8694c2e9578e428a73cac1e466051da97a20..a8e61f71b2ab5721da8e7b6397e4508611f2bcb1 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: