Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed: mark revision relation as protected #54

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion wagtail_ab_testing/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class AbTest(models.Model):
page = models.ForeignKey('wagtailcore.Page', on_delete=models.CASCADE, related_name='ab_tests')
name = models.CharField(max_length=255)
hypothesis = models.TextField(blank=True)
variant_revision = models.ForeignKey('wagtailcore.Revision', on_delete=models.CASCADE, related_name='+')
variant_revision = models.ForeignKey('wagtailcore.Revision', on_delete=models.PROTECT, related_name='+')
goal_event = models.CharField(max_length=255)
goal_page = models.ForeignKey('wagtailcore.Page', null=True, blank=True, on_delete=models.SET_NULL, related_name='+')
sample_size = models.PositiveIntegerField(validators=[MinValueValidator(1)])
Expand Down
9 changes: 8 additions & 1 deletion wagtail_ab_testing/test/tests/test_abtest_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from django.test import TestCase
from freezegun import freeze_time

from django.db.models.deletion import ProtectedError
from wagtail.models import Page

from wagtail_ab_testing.models import AbTest, AbTestHourlyLog
Expand Down Expand Up @@ -165,6 +165,13 @@ def test_confidence_improves_with_more_participants(self):

self.assertEqual(self.ab_test.check_for_winner(), AbTest.VERSION_CONTROL)

def test_check_raise_protect_error(self):
"""
Test to check if ProtectedError is raised when associated revision is deleted
"""
with self.assertRaises(ProtectedError):
self.ab_test.variant_revision.delete()


class TestAutoCancelOnUnpublish(TestCase):
def setUp(self):
Expand Down