Skip to content
Snippets Groups Projects
Commit 4ef171a1 authored by ml bonhomme's avatar ml bonhomme :bee: Committed by Erwan Rouchet
Browse files

add unit test for element dot delete

parent a5038dd3
No related branches found
No related tags found
1 merge request!1552add unit test for element dot delete
......@@ -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()
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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment