Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Backend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Analyze
Contributor analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Arkindex
Backend
Commits
4ef171a1
Commit
4ef171a1
authored
3 years ago
by
ml bonhomme
Committed by
Erwan Rouchet
3 years ago
Browse files
Options
Downloads
Patches
Plain Diff
add unit test for element dot delete
parent
a5038dd3
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!1552
add unit test for element dot delete
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
arkindex/documents/tests/test_destroy_elements.py
+11
-0
11 additions, 0 deletions
arkindex/documents/tests/test_destroy_elements.py
arkindex/sql_validation/element_dot_delete.sql
+61
-0
61 additions, 0 deletions
arkindex/sql_validation/element_dot_delete.sql
with
72 additions
and
0 deletions
arkindex/documents/tests/test_destroy_elements.py
+
11
−
0
View file @
4ef171a1
...
...
@@ -467,3 +467,14 @@ class TestDestroyElements(FixtureAPITestCase):
'
user_id
'
:
self
.
user
.
id
,
'
description
'
:
'
Element deletion
'
,
})
def
test_element_dot_delete
(
self
):
"""
test Element.delete method
"""
self
.
maxDiff
=
None
self
.
client
.
force_login
(
self
.
user
)
with
self
.
assertExactQueries
(
'
element_dot_delete.sql
'
,
params
=
{
'
id
'
:
str
(
self
.
vol
.
id
)}):
self
.
vol
.
delete
()
with
self
.
assertRaises
(
Element
.
DoesNotExist
):
self
.
vol
.
refresh_from_db
()
This diff is collapsed.
Click to expand it.
arkindex/sql_validation/element_dot_delete.sql
0 → 100644
+
61
−
0
View file @
4ef171a1
DELETE
FROM
documents_transcriptionentity
te
WHERE
transcription_id
IN
(
SELECT
t
.
id
FROM
documents_transcription
t
LEFT
JOIN
documents_elementpath
elementpath
USING
(
element_id
)
WHERE
t
.
element_id
=
'{id}'
::
uuid
OR
elementpath
.
path
&&
ARRAY
[
'{id}'
::
uuid
]
)
;
DELETE
FROM
documents_transcription
WHERE
element_id
=
'{id}'
::
uuid
OR
element_id
IN
(
SELECT
element_id
FROM
documents_elementpath
WHERE
path
&&
ARRAY
[
'{id}'
::
uuid
]
)
;
DELETE
FROM
documents_classification
WHERE
element_id
=
'{id}'
::
uuid
OR
element_id
IN
(
SELECT
element_id
FROM
documents_elementpath
WHERE
path
&&
ARRAY
[
'{id}'
::
uuid
]
)
;
DELETE
FROM
documents_metadata
WHERE
element_id
=
'{id}'
::
uuid
OR
element_id
IN
(
SELECT
element_id
FROM
documents_elementpath
WHERE
path
&&
ARRAY
[
'{id}'
::
uuid
]
)
;
DELETE
FROM
dataimport_dataimportelement
WHERE
element_id
=
'{id}'
::
uuid
OR
element_id
IN
(
SELECT
element_id
FROM
documents_elementpath
WHERE
path
&&
ARRAY
[
'{id}'
::
uuid
]
)
;
UPDATE
dataimport_dataimport
SET
element_id
=
NULL
WHERE
element_id
=
'{id}'
::
uuid
OR
element_id
IN
(
SELECT
element_id
FROM
documents_elementpath
WHERE
path
&&
ARRAY
[
'{id}'
::
uuid
]
)
;
DELETE
FROM
documents_selection
selection
WHERE
element_id
=
'{id}'
::
uuid
OR
element_id
IN
(
SELECT
element_id
FROM
documents_elementpath
WHERE
path
&&
ARRAY
[
'{id}'
::
uuid
]
)
;
DELETE
FROM
dataimport_workeractivity
WHERE
element_id
=
'{id}'
::
uuid
OR
element_id
IN
(
SELECT
element_id
FROM
documents_elementpath
WHERE
path
&&
ARRAY
[
'{id}'
::
uuid
]
)
;
WITH
children_ids
(
id
)
AS
(
DELETE
FROM
documents_elementpath
WHERE
element_id
=
'{id}'
::
uuid
OR
path
&&
ARRAY
[
'{id}'
::
uuid
]
RETURNING
element_id
)
DELETE
FROM
documents_element
element
USING
children_ids
WHERE
element
.
id
=
children_ids
.
id
;
DELETE
FROM
"documents_element"
WHERE
"documents_element"
.
"id"
=
'{id}'
::
uuid
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment