diff --git a/taiga/projects/custom_attributes/migrations/0003_triggers_on_delete_customattribute.py b/taiga/projects/custom_attributes/migrations/0003_triggers_on_delete_customattribute.py index 8a984a63..43285e38 100644 --- a/taiga/projects/custom_attributes/migrations/0003_triggers_on_delete_customattribute.py +++ b/taiga/projects/custom_attributes/migrations/0003_triggers_on_delete_customattribute.py @@ -59,7 +59,7 @@ class Migration(migrations.Migration): migrations.RunSQL( """ CREATE TRIGGER "update_userstorycustomvalues_after_remove_userstorycustomattribute" - BEFORE DELETE ON custom_attributes_userstorycustomattribute + AFTER DELETE ON custom_attributes_userstorycustomattribute FOR EACH ROW EXECUTE PROCEDURE clean_key_in_custom_attributes_values('custom_attributes_userstorycustomattributesvalues'); """, @@ -72,7 +72,7 @@ class Migration(migrations.Migration): migrations.RunSQL( """ CREATE TRIGGER "update_taskcustomvalues_after_remove_taskcustomattribute" - BEFORE DELETE ON custom_attributes_taskcustomattribute + AFTER DELETE ON custom_attributes_taskcustomattribute FOR EACH ROW EXECUTE PROCEDURE clean_key_in_custom_attributes_values('custom_attributes_taskcustomattributesvalues'); """, @@ -85,7 +85,7 @@ class Migration(migrations.Migration): migrations.RunSQL( """ CREATE TRIGGER "update_issuecustomvalues_after_remove_issuecustomattribute" - BEFORE DELETE ON custom_attributes_issuecustomattribute + AFTER DELETE ON custom_attributes_issuecustomattribute FOR EACH ROW EXECUTE PROCEDURE clean_key_in_custom_attributes_values('custom_attributes_issuecustomattributesvalues'); """, diff --git a/tests/integration/test_custom_attributes_issues.py b/tests/integration/test_custom_attributes_issues.py index b33b7e71..65152aa5 100644 --- a/tests/integration/test_custom_attributes_issues.py +++ b/tests/integration/test_custom_attributes_issues.py @@ -15,6 +15,7 @@ # along with this program. If not, see . +from django.db.transaction import atomic from django.core.urlresolvers import reverse from taiga.base.utils import json @@ -171,12 +172,11 @@ def test_issue_custom_attributes_values_delete_issue(client): # Test tristres triggers :-P ######################################################### -def test_trigger_update_issuecustomvalues_afeter_remove_issuecustomattribute(): +def test_trigger_update_issuecustomvalues_afeter_remove_issuecustomattribute(client): issue = f.IssueFactory() member = f.MembershipFactory(user=issue.project.owner, project=issue.project, is_owner=True) - custom_attr_1 = f.IssueCustomAttributeFactory(project=issue.project) ct1_id = "{}".format(custom_attr_1.id) custom_attr_2 = f.IssueCustomAttributeFactory(project=issue.project) @@ -189,8 +189,12 @@ def test_trigger_update_issuecustomvalues_afeter_remove_issuecustomattribute(): assert ct1_id in custom_attrs_val.attributes_values.keys() assert ct2_id in custom_attrs_val.attributes_values.keys() - custom_attr_2.delete() - custom_attrs_val = custom_attrs_val.__class__.objects.get(id=custom_attrs_val.id) + url = reverse("issue-custom-attributes-detail", kwargs={"pk": custom_attr_2.pk}) + client.login(member.user) + response = client.json.delete(url) + assert response.status_code == 204 + custom_attrs_val = custom_attrs_val.__class__.objects.get(id=custom_attrs_val.id) + assert not custom_attr_2.__class__.objects.filter(pk=custom_attr_2.pk).exists() assert ct1_id in custom_attrs_val.attributes_values.keys() assert ct2_id not in custom_attrs_val.attributes_values.keys() diff --git a/tests/integration/test_custom_attributes_tasks.py b/tests/integration/test_custom_attributes_tasks.py index ecb909de..fee38830 100644 --- a/tests/integration/test_custom_attributes_tasks.py +++ b/tests/integration/test_custom_attributes_tasks.py @@ -172,7 +172,7 @@ def test_task_custom_attributes_values_delete_task(client): # Test tristres triggers :-P ######################################################### -def test_trigger_update_taskcustomvalues_afeter_remove_taskcustomattribute(): +def test_trigger_update_taskcustomvalues_afeter_remove_taskcustomattribute(client): task = f.TaskFactory() member = f.MembershipFactory(user=task.project.owner, project=task.project, @@ -191,8 +191,12 @@ def test_trigger_update_taskcustomvalues_afeter_remove_taskcustomattribute(): assert ct1_id in custom_attrs_val.attributes_values.keys() assert ct2_id in custom_attrs_val.attributes_values.keys() - custom_attr_2.delete() - custom_attrs_val = custom_attrs_val.__class__.objects.get(id=custom_attrs_val.id) + url = reverse("task-custom-attributes-detail", kwargs={"pk": custom_attr_2.pk}) + client.login(member.user) + response = client.json.delete(url) + assert response.status_code == 204 + custom_attrs_val = custom_attrs_val.__class__.objects.get(id=custom_attrs_val.id) + assert not custom_attr_2.__class__.objects.filter(pk=custom_attr_2.pk).exists() assert ct1_id in custom_attrs_val.attributes_values.keys() assert ct2_id not in custom_attrs_val.attributes_values.keys() diff --git a/tests/integration/test_custom_attributes_user_stories.py b/tests/integration/test_custom_attributes_user_stories.py index 362f5497..6e602269 100644 --- a/tests/integration/test_custom_attributes_user_stories.py +++ b/tests/integration/test_custom_attributes_user_stories.py @@ -150,7 +150,7 @@ def test_userstory_custom_attributes_values_update_with_error_invalid_key(client # Test tristres triggers :-P ######################################################### -def test_trigger_update_userstorycustomvalues_afeter_remove_userstorycustomattribute(): +def test_trigger_update_userstorycustomvalues_afeter_remove_userstorycustomattribute(client): user_story = f.UserStoryFactory() member = f.MembershipFactory(user=user_story.project.owner, project=user_story.project, @@ -169,8 +169,11 @@ def test_trigger_update_userstorycustomvalues_afeter_remove_userstorycustomattri assert ct1_id in custom_attrs_val.attributes_values.keys() assert ct2_id in custom_attrs_val.attributes_values.keys() - custom_attr_2.delete() - custom_attrs_val = custom_attrs_val.__class__.objects.get(id=custom_attrs_val.id) + url = reverse("userstory-custom-attributes-detail", kwargs={"pk": custom_attr_2.pk}) + client.login(member.user) + response = client.json.delete(url) + assert response.status_code == 204 + custom_attrs_val = custom_attrs_val.__class__.objects.get(id=custom_attrs_val.id) assert ct1_id in custom_attrs_val.attributes_values.keys() assert ct2_id not in custom_attrs_val.attributes_values.keys()