forked from inveniosoftware/invenio-records-rest
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_views_item_delete.py
More file actions
67 lines (49 loc) · 2.25 KB
/
Copy pathtest_views_item_delete.py
File metadata and controls
67 lines (49 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# SPDX-FileCopyrightText: 2015-2018 CERN.
# SPDX-License-Identifier: MIT
"""Delete record tests."""
from flask import url_for
from helpers import get_json, record_url
from invenio_pidstore.models import PersistentIdentifier
from mock import patch
from sqlalchemy.exc import SQLAlchemyError
from invenio_records_rest.errors import PIDResolveRESTError
def test_valid_delete(app, indexed_records):
"""Test VALID record delete request (DELETE .../records/<record_id>)."""
# Test with and without headers
for i, headers in enumerate([[], [("Accept", "video/mp4")]]):
pid, record = indexed_records[i]
with app.test_client() as client:
res = client.delete(record_url(pid), headers=headers)
assert res.status_code == 204
res = client.get(record_url(pid))
assert res.status_code == 410
def test_delete_deleted(app, indexed_records):
"""Test deleting a perviously deleted record."""
pid, record = indexed_records[0]
with app.test_client() as client:
res = client.delete(record_url(pid))
assert res.status_code == 204
res = client.delete(record_url(pid))
assert res.status_code == 410
data = get_json(res)
assert "message" in data
assert data["status"] == 410
def test_delete_notfound(app, indexed_records):
"""Test INVALID record delete request (DELETE .../records/<record_id>)."""
with app.test_client() as client:
# Check that GET with non existing id will return 404
res = client.delete(url_for("invenio_records_rest.recid_item", pid_value=0))
assert res.status_code == 404
def test_delete_with_sqldatabase_error(app, indexed_records):
"""Test VALID record delete request (GET .../records/<record_id>)."""
pid, record = indexed_records[0]
with app.test_client() as client:
def raise_error():
raise PIDResolveRESTError()
# Force an SQLAlchemy error that will rollback the transaction.
with patch.object(PersistentIdentifier, "delete", side_effect=raise_error):
res = client.delete(record_url(pid))
assert res.status_code == 500
with app.test_client() as client:
res = client.get(record_url(pid))
assert res.status_code == 200