|
2 | 2 | # |
3 | 3 | # Copyright (C) 2021 CERN. |
4 | 4 | # Copyright (C) 2021 Northwestern University. |
| 5 | +# Copyright (C) 2022 TU Wien. |
5 | 6 | # |
6 | 7 | # Invenio-Requests is free software; you can redistribute it and/or |
7 | 8 | # modify it under the terms of the MIT License; see LICENSE file for more |
@@ -215,3 +216,67 @@ def test_empty_comment( |
215 | 216 | ) |
216 | 217 | assert 400 == response.status_code |
217 | 218 | assert expected_json == response.json |
| 219 | + |
| 220 | + |
| 221 | +# |
| 222 | +# Read-only mode |
| 223 | +# |
| 224 | + |
| 225 | + |
| 226 | +def test_comment_request_ro( |
| 227 | + rw_app, client_logged_as, headers, events_resource_data, example_request |
| 228 | +): |
| 229 | + rw_app.config["RECORDS_PERMISSIONS_READ_ONLY"] = True |
| 230 | + request_id = example_request.id |
| 231 | + client = client_logged_as("admin@example.org") |
| 232 | + |
| 233 | + # Commenting on a request in read-only mode should fail |
| 234 | + response = client.post( |
| 235 | + f"/requests/{request_id}/comments", headers=headers, json=events_resource_data |
| 236 | + ) |
| 237 | + assert response.status_code == 403 |
| 238 | + |
| 239 | + |
| 240 | +def test_update_comment_request_ro( |
| 241 | + rw_app, client_logged_as, headers, events_resource_data, example_request |
| 242 | +): |
| 243 | + request_id = example_request.id |
| 244 | + client = client_logged_as("admin@example.org") |
| 245 | + |
| 246 | + response = client.post( |
| 247 | + f"/requests/{request_id}/comments", headers=headers, json=events_resource_data |
| 248 | + ) |
| 249 | + comment_id = response.json["id"] |
| 250 | + assert response.status_code == 201 |
| 251 | + |
| 252 | + # Updating the comment in read-only mode should fail |
| 253 | + rw_app.config["RECORDS_PERMISSIONS_READ_ONLY"] = True |
| 254 | + data = copy.deepcopy(events_resource_data) |
| 255 | + data["payload"]["content"] = "I've revised my comment." |
| 256 | + response = client.put( |
| 257 | + f"/requests/{request_id}/comments/{comment_id}", |
| 258 | + headers=headers, |
| 259 | + json=data, |
| 260 | + ) |
| 261 | + assert response.status_code == 403 |
| 262 | + |
| 263 | + |
| 264 | +def test_delete_comment_request_ro( |
| 265 | + rw_app, client_logged_as, headers, events_resource_data, example_request |
| 266 | +): |
| 267 | + request_id = example_request.id |
| 268 | + client = client_logged_as("admin@example.org") |
| 269 | + |
| 270 | + response = client.post( |
| 271 | + f"/requests/{request_id}/comments", headers=headers, json=events_resource_data |
| 272 | + ) |
| 273 | + comment_id = response.json["id"] |
| 274 | + assert response.status_code == 201 |
| 275 | + |
| 276 | + # Updating the comment in read-only mode should fail |
| 277 | + rw_app.config["RECORDS_PERMISSIONS_READ_ONLY"] = True |
| 278 | + response = client.delete( |
| 279 | + f"/requests/{request_id}/comments/{comment_id}", |
| 280 | + headers=headers, |
| 281 | + ) |
| 282 | + assert response.status_code == 403 |
0 commit comments