Skip to content

Commit

Permalink
Concept hard delete request test
Browse files Browse the repository at this point in the history
  • Loading branch information
snyaggarwal committed Apr 1, 2022
1 parent ea9a078 commit 7b3d96a
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions core/integration_tests/tests_concepts.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import unittest
from unittest.mock import patch

from django.conf import settings
from mock import ANY
Expand Down Expand Up @@ -377,6 +378,54 @@ def test_delete_204(self):
self.assertTrue(concept.retired)
self.assertTrue(latest_version.comment, 'Deleting it')

def test_db_hard_delete_204(self):
names = [LocalizedTextFactory()]
concept = ConceptFactory(parent=self.source, names=names)
concepts_url = f"/orgs/{self.organization.mnemonic}/sources/{self.source.mnemonic}/concepts/{concept.mnemonic}/"

response = self.client.delete(
concepts_url + '?db=true&hardDelete=true',
{'update_comment': 'Deleting it'},
HTTP_AUTHORIZATION='Token ' + self.token,
format='json'
)

self.assertEqual(response.status_code, 204)
self.assertFalse(Concept.objects.filter(id=concept.id).exists())
self.assertFalse(Concept.objects.filter(mnemonic=concept.mnemonic).exists())

def test_hard_delete_204(self):
names = [LocalizedTextFactory()]
concept = ConceptFactory(parent=self.source, names=names)
concepts_url = f"/orgs/{self.organization.mnemonic}/sources/{self.source.mnemonic}/concepts/{concept.mnemonic}/"

response = self.client.delete(
concepts_url + '?hardDelete=true',
{'update_comment': 'Deleting it'},
HTTP_AUTHORIZATION='Token ' + self.token,
format='json'
)

self.assertEqual(response.status_code, 204)
self.assertFalse(Concept.objects.filter(id=concept.id).exists())
self.assertFalse(Concept.objects.filter(mnemonic=concept.mnemonic).exists())

@patch('core.concepts.views.delete_concept')
def test_async_hard_delete_204(self, delete_conceot_task_mock):
names = [LocalizedTextFactory()]
concept = ConceptFactory(parent=self.source, names=names)
concepts_url = f"/orgs/{self.organization.mnemonic}/sources/{self.source.mnemonic}/concepts/{concept.mnemonic}/"

response = self.client.delete(
concepts_url + '?async=true&hardDelete=true',
{'update_comment': 'Deleting it'},
HTTP_AUTHORIZATION='Token ' + self.token,
format='json'
)

self.assertEqual(response.status_code, 204)
delete_conceot_task_mock.delay.assert_called_once_with(concept.id)

def test_delete_404(self):
concepts_url = f"/orgs/{self.organization.mnemonic}/sources/{self.source.mnemonic}/concepts/foobar/"

Expand Down

0 comments on commit 7b3d96a

Please sign in to comment.