Skip to content

Commit

Permalink
Merge pull request #54 from disconnect821/fix/mark-revision-relation-…
Browse files Browse the repository at this point in the history
…as-protected

Fixed: mark revision relation as protected
  • Loading branch information
Stormheg authored Oct 5, 2023
2 parents fa35ddd + c680ae2 commit a866303
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
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

0 comments on commit a866303

Please sign in to comment.