diff --git a/tests/fixtures/timeseries/timeseries_roles.json b/tests/fixtures/timeseries/timeseries_roles.json index 3d7dc6a964c216c371d2fbf02806184ba25de700..dbf7fae69e68d058db7febc817663d7bf936f185 100644 --- a/tests/fixtures/timeseries/timeseries_roles.json +++ b/tests/fixtures/timeseries/timeseries_roles.json @@ -10,5 +10,11 @@ "role": 5, "status": 0, "contact_id": 4 + }, + { + "id": 3, + "role": 1, + "status": 0, + "contact_id": 3 } ] diff --git a/tests/fixtures/timeseries/timeseries_timeseries_roles.json b/tests/fixtures/timeseries/timeseries_timeseries_roles.json index c9b3fbc9c8c845e1bcbdfcc6362f14404441afdc..562603fe5fb62c67bb83b5eb893678a7c93b430c 100644 --- a/tests/fixtures/timeseries/timeseries_timeseries_roles.json +++ b/tests/fixtures/timeseries/timeseries_timeseries_roles.json @@ -4,6 +4,11 @@ "timeseries_id": 1, "role_id": 2 }, + { + "_comment": "Every time series needs at least one role (time series without roles are not allowed!)", + "timeseries_id": 1, + "role_id": 3 + }, { "_comment": "Every time series needs at least one role (time series without roles are not allowed!)", "timeseries_id": 2, diff --git a/tests/test_data.py b/tests/test_data.py index da4e3acfd73820e8920291e25cb9457bd934f0e9..5dac34c8b27bcfc4f68775df837fbbbf2e7a7662 100644 --- a/tests/test_data.py +++ b/tests/test_data.py @@ -218,8 +218,12 @@ class TestApps: 'roles': [{'id': 2, 'role': 'resource provider', 'status': 'active', 'contact': {'id': 4, 'organisation': {'id': 1, 'name': 'UBA', 'longname': 'Umweltbundesamt', 'kind': 'government', 'city': 'Dessau-Roßlau', 'postcode': '06844', 'street_address': 'Wörlitzer Platz 1', - 'country': 'Germany', 'homepage': 'https://www.umweltbundesamt.de', 'contact_url': 'mailto:immission@uba.de'}}}], - 'citation': 'Umweltbundesamt: time series of toluene at Shangdianzi, accessed from the TOAR database on 2023-07-28 12:00:00'}, + 'country': 'Germany', 'homepage': 'https://www.umweltbundesamt.de', 'contact_url': 'mailto:immission@uba.de'}}}, + {'id': 3, 'role': 'principal investigator', 'status': 'active', + 'contact': {'id': 3, 'person': {'email': 's.schroeder@fz-juelich.de','id': 3, 'isprivate': False, + 'name': 'Sabine Schröder', 'orcid': '0000-0002-0309-8010', 'phone': '+49-2461-61-6397'}}} + ], + 'citation': 'Sabine Schröder: time series of toluene at Shangdianzi, accessed from the TOAR database on 2023-07-28 12:00:00'}, 'data': [{'datetime': '2012-12-16T21:00:00+00:00', 'value': 21.581, 'flags': 'OK validated verified', 'version': '1.0', 'timeseries_id': 1}, {'datetime': '2012-12-16T22:00:00+00:00', 'value': 13.734, 'flags': 'OK validated verified', 'version': '1.0', 'timeseries_id': 1}, {'datetime': '2012-12-16T23:00:00+00:00', 'value': 13.734, 'flags': 'OK validated verified', 'version': '1.0', 'timeseries_id': 1}, @@ -315,8 +319,18 @@ class TestApps: 'street_address': 'Wörlitzer Platz 1', 'country': 'Germany', 'homepage': 'https://www.umweltbundesamt.de', - 'contact_url': 'mailto:immission@uba.de'}}}], - 'citation': 'Umweltbundesamt: time series of toluene at ' + 'contact_url': 'mailto:immission@uba.de'}}}, + {'id': 3, + 'role': 'principal investigator', + 'status': 'active', + 'contact': {'id': 3, + 'person': {'email': 's.schroeder@fz-juelich.de', + 'id': 3, + 'isprivate': False, + 'name': 'Sabine Schröder', + 'orcid': '0000-0002-0309-8010', + 'phone': '+49-2461-61-6397'}}}], + 'citation': 'Sabine Schröder: time series of toluene at ' 'Shangdianzi, accessed from the TOAR database on ' '2023-07-28 12:00:00', 'license': 'This data is published under a Creative Commons ' @@ -399,8 +413,17 @@ class TestApps: 'street_address': 'Wörlitzer Platz 1', 'country': 'Germany', 'homepage': 'https://www.umweltbundesamt.de', - 'contact_url': 'mailto:immission@uba.de'}}}], - 'citation': 'Umweltbundesamt: time series of toluene at ' + 'contact_url': 'mailto:immission@uba.de'}}}, + {'id': 3, + 'role': 'principal investigator', + 'status': 'active', + 'contact': {'id': 3, 'person': {'email': 's.schroeder@fz-juelich.de', + 'id': 3, + 'isprivate': False, + 'name': 'Sabine Schröder', + 'orcid': '0000-0002-0309-8010', + 'phone': '+49-2461-61-6397'}}}], + 'citation': 'Sabine Schröder: time series of toluene at ' 'Shangdianzi, accessed from the TOAR database on ' '2023-07-28 12:00:00', 'license': 'This data is published under a Creative Commons ' @@ -505,11 +528,28 @@ class TestApps: '# "contact_url": "mailto:immission@uba.de"\n', '# }\n', '# }\n', + '# },\n', + '# {\n', + '# "id": 3,\n', + '# "role": "principal investigator",\n', + '# "status": "active",\n', + '# "contact": {\n', + '# "id": 3,\n', + '# "person": {\n', + '# "id": 3,\n', + '# "name": "Sabine Schröder",\n', + '# "email": "s.schroeder@fz-juelich.de",\n', + '# "phone": "+49-2461-61-6397",\n', + '# "orcid": "0000-0002-0309-8010",\n', + '# "isprivate": false\n', + '# },\n', + '# "organisation": null\n', + '# }\n', '# }\n', '# ],\n', '# "annotations": null,\n', '# "changelog": null,\n', - '# "citation": "Umweltbundesamt: time series of toluene at Shangdianzi, accessed from the TOAR database on 2023-07-28 12:00:00",\n', + '# "citation": "Sabine Schröder: time series of toluene at Shangdianzi, accessed from the TOAR database on 2023-07-28 12:00:00",\n', '# "attribution": null,\n', '# "license": "This data is published under a Creative Commons Attribution 4.0 International (CC BY 4.0). https://creativecommons.org/licenses/by/4.0/"\n', '#}\n', @@ -638,8 +678,11 @@ class TestApps: 'roles': [{'id': 2, 'role': 'resource provider', 'status': 'active', 'contact': {'id': 4, 'organisation': {'id': 1, 'name': 'UBA', 'longname': 'Umweltbundesamt', 'kind': 'government', 'city': 'Dessau-Roßlau', 'postcode': '06844', 'street_address': 'Wörlitzer Platz 1', - 'country': 'Germany', 'homepage': 'https://www.umweltbundesamt.de', 'contact_url': 'mailto:immission@uba.de'}}}], - 'citation': 'Umweltbundesamt: time series of toluene at Shangdianzi, accessed from the TOAR database on 2023-07-28 12:00:00'}, + 'country': 'Germany', 'homepage': 'https://www.umweltbundesamt.de', 'contact_url': 'mailto:immission@uba.de'}}}, + {'id': 3, 'role': 'principal investigator', 'status': 'active', + 'contact': {'id': 3, 'person': {'email': 's.schroeder@fz-juelich.de','id': 3, 'isprivate': False, + 'name': 'Sabine Schröder', 'orcid': '0000-0002-0309-8010', 'phone': '+49-2461-61-6397'}}}], + 'citation': 'Sabine Schröder: time series of toluene at Shangdianzi, accessed from the TOAR database on 2023-07-28 12:00:00'}, 'data': [{'datetime': '2012-12-16T21:00:00+00:00', 'value': 21.581, 'flags': 'OK validated verified', 'timeseries_id': 1, 'version': '1.0'}, {'datetime': '2012-12-16T22:00:00+00:00', 'value': 13.734, 'flags': 'OK validated verified', 'timeseries_id': 1, 'version': '1.0'}, {'datetime': '2012-12-16T23:00:00+00:00', 'value': 13.734, 'flags': 'OK validated verified', 'timeseries_id': 1, 'version': '1.0'}, @@ -1050,6 +1093,17 @@ class TestApps: 'contact_url': 'mailto:immission@uba.de', } } + }, + {'id': 3, 'role': 'principal investigator', 'status': 'active', + 'contact': {'id': 3, + 'person': {'email': 's.schroeder@fz-juelich.de', + 'id': 3, + 'isprivate': False, + 'name': 'Sabine Schröder', + 'orcid': '0000-0002-0309-8010', + 'phone': '+49-2461-61-6397' + } + } }], 'changelog': [{'datetime': '', 'description': 'Sabine Schröder (s.schroeder@fz-juelich.de): test patch bulk data', @@ -1062,7 +1116,7 @@ class TestApps: 'period_end': '2012-12-17T04:00:00+00:00', 'version': '000002.000000.00000000000000' }], - 'citation': 'Umweltbundesamt: time series of toluene at Shangdianzi, accessed from the TOAR database', + 'citation': 'Sabine Schröder: time series of toluene at Shangdianzi, accessed from the TOAR database', 'license': 'This data is published under a Creative Commons Attribution 4.0 International (CC BY 4.0). https://creativecommons.org/licenses/by/4.0/', 'doi': ''}, 'data': [{'datetime': '2012-12-16T21:00:00+00:00', 'value': 21.581, 'flags': 'OK validated verified', 'timeseries_id': 1, 'version': '1.0'}, diff --git a/tests/test_search.py b/tests/test_search.py index 17b76a7e8a4f08f28de465de539c504d0d6b9ac4..34061821483cdea4dffaeddc96222c719e5ee02d 100644 --- a/tests/test_search.py +++ b/tests/test_search.py @@ -262,7 +262,17 @@ class TestApps: 'street_address': 'Wörlitzer Platz 1', 'country': 'Germany', 'homepage': 'https://www.umweltbundesamt.de', - 'contact_url': 'mailto:immission@uba.de'}}}]}, + 'contact_url': 'mailto:immission@uba.de'}}}, + {'id': 3, + 'role': 'principal investigator', + 'status': 'active', + 'contact': {'id': 3, + 'person': {'email': 's.schroeder@fz-juelich.de', + 'id': 3, + 'isprivate': False, + 'name': 'Sabine Schröder', + 'orcid': '0000-0002-0309-8010', + 'phone': '+49-2461-61-6397'}}}]}, {'id': 2, 'label': 'CMA', 'order': 1, @@ -679,7 +689,12 @@ class TestApps: response = client.get("/search/?fields=id,role,order,additional_metadata") expected_status_code = 200 assert response.status_code == expected_status_code - expected_resp = [{'id': 1, + expected_resp = [{'additional_metadata': {'original_units': 'ppb'}, + 'id': 1, + 'order': 1, + 'roles': {'contact_id': 3, 'role': 'principal investigator', 'status': 'active'} + }, + {'id': 1, 'order': 1, 'additional_metadata': {"original_units": "ppb"}, 'roles': {'role': 'resource provider', 'status': 'active', 'contact_id': 4} @@ -1093,7 +1108,21 @@ class TestApps: 'street_address': 'Wörlitzer Platz 1', 'country': 'Germany', 'homepage': 'https://www.umweltbundesamt.de', - 'contact_url': 'mailto:immission@uba.de'}}}]}] + 'contact_url': 'mailto:immission@uba.de'}}}, + {'id': 3, + 'role': 'principal investigator', + 'status': 'active', + 'contact': {'id': 3, + 'person': {'email': 's.schroeder@fz-juelich.de', + 'id': 3, + 'isprivate': False, + 'name': 'Sabine Schröder', + 'orcid': '0000-0002-0309-8010', + 'phone': '+49-2461-61-6397' + } + } + }] + }] assert response.json() == expected_response @@ -1189,5 +1218,19 @@ class TestApps: 'street_address': 'Wörlitzer Platz 1', 'country': 'Germany', 'homepage': 'https://www.umweltbundesamt.de', - 'contact_url': 'mailto:immission@uba.de'}}}]}] + 'contact_url': 'mailto:immission@uba.de'}}}, + {'id': 3, + 'role': 'principal investigator', + 'status': 'active', + 'contact': {'id': 3, + 'person': {'email': 's.schroeder@fz-juelich.de', + 'id': 3, + 'isprivate': False, + 'name': 'Sabine Schröder', + 'orcid': '0000-0002-0309-8010', + 'phone': '+49-2461-61-6397' + } + } + }] + }] assert response.json() == expected_response diff --git a/tests/test_stationmeta.py b/tests/test_stationmeta.py index c8d86144d3900bc3b85dffa51af934b4f5d37db4..aa5ca570a40661f995b543a8b2966aa8851864f5 100644 --- a/tests/test_stationmeta.py +++ b/tests/test_stationmeta.py @@ -1025,3 +1025,15 @@ class TestApps: expected_resp = {'detail': 'Station for deleting field not found.'} assert response.json() == expected_resp + + def test_test(self, client, db): + response = client.patch("/stationmeta/SDY54421?description=changing global metadata", + json={"stationmeta": + {"globalmeta": { "toar2_category": "Rural"}} + }, + headers={"email": "s.schroeder@fz-juelich.de"} + ) + expected_status_code = 404 + assert response.status_code == expected_status_code + expected_resp = {'detail': 'Station for patching not found.'} + assert response.json() == expected_resp diff --git a/tests/test_timeseries.py b/tests/test_timeseries.py index 76c78871d95903a5be36a938990dab38f6a3efcf..5cb98235bda5e6f647830cf68aee266515fe51a2 100644 --- a/tests/test_timeseries.py +++ b/tests/test_timeseries.py @@ -69,7 +69,7 @@ class TestApps: fake_conn.commit() fake_cur.execute("ALTER SEQUENCE timeseries_annotations_id_seq RESTART WITH 1") fake_conn.commit() - fake_cur.execute("ALTER SEQUENCE timeseries_roles_id_seq RESTART WITH 3") + fake_cur.execute("ALTER SEQUENCE timeseries_roles_id_seq RESTART WITH 4") fake_conn.commit() fake_cur.execute("ALTER SEQUENCE timeseries_programmes_id_seq RESTART WITH 1") fake_conn.commit() @@ -262,7 +262,17 @@ class TestApps: 'street_address': 'Wörlitzer Platz 1', 'country': 'Germany', 'homepage': 'https://www.umweltbundesamt.de', - 'contact_url': 'mailto:immission@uba.de'}}}]}, + 'contact_url': 'mailto:immission@uba.de'}}}, + {'id': 3, + 'role': 'principal investigator', + 'status': 'active', + 'contact': {'id': 3, + 'person': {'email': 's.schroeder@fz-juelich.de', + 'id': 3, + 'isprivate': False, + 'name': 'Sabine Schröder', + 'orcid': '0000-0002-0309-8010', + 'phone': '+49-2461-61-6397'}}}]}, {'id': 2, 'label': 'CMA', 'order': 1, @@ -386,7 +396,10 @@ class TestApps: 'roles': [{'id': 2, 'role': 'resource provider', 'status': 'active', 'contact': {'id': 4, 'organisation': {'id': 1, 'name': 'UBA', 'longname': 'Umweltbundesamt', 'kind': 'government', 'city': 'Dessau-Roßlau', 'postcode': '06844', 'street_address': 'Wörlitzer Platz 1', - 'country': 'Germany', 'homepage': 'https://www.umweltbundesamt.de', 'contact_url': 'mailto:immission@uba.de'}}}], + 'country': 'Germany', 'homepage': 'https://www.umweltbundesamt.de', 'contact_url': 'mailto:immission@uba.de'}}}, + {'id': 3, 'role': 'principal investigator', 'status': 'active', + 'contact': {'id': 3, 'person': {'email': 's.schroeder@fz-juelich.de', 'id': 3, 'isprivate': False, + 'name': 'Sabine Schröder', 'orcid': '0000-0002-0309-8010', 'phone': '+49-2461-61-6397'}}}], 'variable': {'name': 'toluene', 'longname': 'toluene', 'displayname': 'Toluene', 'cf_standardname': 'mole_fraction_of_toluene_in_air', 'units': 'nmol mol-1', 'chemical_formula': 'C7H8', 'id': 7}, @@ -610,7 +623,11 @@ class TestApps: 'roles': [{'id': 2, 'role': 'resource provider', 'status': 'active', 'contact': {'id': 4, 'organisation': {'id': 1, 'name': 'UBA', 'longname': 'Umweltbundesamt', 'kind': 'government', 'city': 'Dessau-Roßlau', 'postcode': '06844', 'street_address': 'Wörlitzer Platz 1', - 'country': 'Germany', 'homepage': 'https://www.umweltbundesamt.de', 'contact_url': 'mailto:immission@uba.de'}}}], + 'country': 'Germany', 'homepage': 'https://www.umweltbundesamt.de', 'contact_url': 'mailto:immission@uba.de'}}}, + {'id': 3, 'role': 'principal investigator', 'status': 'active', + 'contact': {'id': 3, 'person': {'email': 's.schroeder@fz-juelich.de','id': 3, 'isprivate': False, + 'name': 'Sabine Schröder', 'orcid': '0000-0002-0309-8010', 'phone': '+49-2461-61-6397'}}} + ], 'station': {'id': 2, 'codes': ['SDZ54421'], 'name': 'Shangdianzi', 'coordinates': {'lat': 40.65, 'lng': 117.106, 'alt': 293.9}, 'coordinate_validation_status': 'not checked', 'country': 'China', @@ -776,7 +793,17 @@ class TestApps: 'contact_url': 'mailto:immission@uba.de' } } - } + }, + {'id': 3, + 'role': 'principal investigator', + 'status': 'active', + 'contact': {'id': 3, + 'person': {'email': 's.schroeder@fz-juelich.de', + 'id': 3, + 'isprivate': False, + 'name': 'Sabine Schröder', + 'orcid': '0000-0002-0309-8010', + 'phone': '+49-2461-61-6397'}}} ] }] assert response.json() == expected_response @@ -986,7 +1013,18 @@ class TestApps: 'id': 2, 'role': 'resource provider', 'status': 'active' - } + }, + {'id': 3, + 'role': 'principal investigator', + 'status': 'active', + 'contact': {'id': 3, + 'organisation': None, + 'person': {'email': 's.schroeder@fz-juelich.de', + 'id': 3, + 'isprivate': False, + 'name': 'Sabine Schröder', + 'orcid': '0000-0002-0309-8010', + 'phone': '+49-2461-61-6397'}}} ] assert response.json() == expected_response @@ -995,7 +1033,7 @@ class TestApps: response = client.post("/timeseries/request_contributors?format=text", files={"file": open("tests/fixtures/timeseries/timeseries_id.txt", "rb")}) expected_status_code = 200 assert response.status_code == expected_status_code - expected_response = 'organisations: Forschungszentrum Jülich;Umweltbundesamt' + expected_response = 'organisations: Forschungszentrum Jülich;Umweltbundesamt; persons:Sabine Schröder' assert response.json() == expected_response @@ -1003,7 +1041,7 @@ class TestApps: response = client.post("/timeseries/request_contributors", files={"file": open("tests/fixtures/timeseries/timeseries_id.txt", "rb")}) expected_status_code = 200 assert response.status_code == expected_status_code - expected_response = 'organisations: Forschungszentrum Jülich;Umweltbundesamt' + expected_response = 'organisations: Forschungszentrum Jülich;Umweltbundesamt; persons:Sabine Schröder' assert response.json() == expected_response @@ -1075,7 +1113,18 @@ class TestApps: 'id': 2, 'role': 'resource provider', 'status': 'active' - } + }, + {'id': 3, + 'role': 'principal investigator', + 'status': 'active', + 'contact': {'id': 3, + 'organisation': None, + 'person': {'email': 's.schroeder@fz-juelich.de', + 'id': 3, + 'isprivate': False, + 'name': 'Sabine Schröder', + 'orcid': '0000-0002-0309-8010', + 'phone': '+49-2461-61-6397'}}} ] assert response.json() == expected_response @@ -1084,7 +1133,7 @@ class TestApps: response = client.get("/timeseries/request_timeseries_list_of_contributors/7f0df73a-bd0f-48b9-bb17-d5cd36f89598?format=text") expected_status_code = 200 assert response.status_code == expected_status_code - expected_response = 'organisations: Forschungszentrum Jülich;Umweltbundesamt' + expected_response = 'organisations: Forschungszentrum Jülich;Umweltbundesamt; persons:Sabine Schröder' assert response.json() == expected_response @@ -1223,12 +1272,22 @@ class TestApps: 'contact_url': 'mailto:immission@uba.de'}}, 'id': 2, 'role': 'resource provider', - 'status': 'active'}] + 'status': 'active'}, + {'id': 3, + 'role': 'principal investigator', + 'status': 'active', + 'contact': {'id': 3, + 'person': {'email': 's.schroeder@fz-juelich.de', + 'id': 3, + 'isprivate': False, + 'name': 'Sabine Schröder', + 'orcid': '0000-0002-0309-8010', + 'phone': '+49-2461-61-6397'}}}] set_expected_response_roles = {json.dumps(item, sort_keys=True) for item in response_roles} set_response_roles = {json.dumps(item, sort_keys=True) for item in response_json['roles']} assert set_response_roles == set_expected_response_roles - assert response_json['changelog'][0]['old_value'] == "{'roles': [{'role': 'ResourceProvider', 'status': 'Active', 'contact_id': 4}]}" - assert response_json['changelog'][0]['new_value'] == "{'roles': [{'role': 'ResourceProvider', 'status': 'Active', 'contact_id': 4}, {'role': 'ResourceProvider', 'contact_id': 5, 'status': 'Active'}]}" + assert response_json['changelog'][0]['old_value'] == "{'roles': [{'role': 'ResourceProvider', 'status': 'Active', 'contact_id': 4}, {'role': 'PrincipalInvestigator', 'status': 'Active', 'contact_id': 3}]}" + assert response_json['changelog'][0]['new_value'] == "{'roles': [{'role': 'ResourceProvider', 'status': 'Active', 'contact_id': 4}, {'role': 'PrincipalInvestigator', 'status': 'Active', 'contact_id': 3}, {'role': 'ResourceProvider', 'contact_id': 5, 'status': 'Active'}]}" assert response_json['changelog'][0]['author_id'] == 1 assert response_json['changelog'][0]['type_of_change'] == 'single value correction in metadata'