Skip to content

Commit

Permalink
Use a snippet model without RevisionMixin for testing EditingSession
Browse files Browse the repository at this point in the history
We want to make sure the feature works (without the new version
detection) when using a snippet model that does not use RevisionMixin.

We don't have any tests that ensures the new version detection works
with a RevisionMixin-enabled snippet. We can add those later, but the
code itself doesn't make a special-case between snippet vs pages, so
it's probably okay to skip them.
  • Loading branch information
laymonage committed Jul 12, 2024
1 parent 1f67b5a commit 7b11422
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions wagtail/admin/tests/test_editing_sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

from wagtail.admin.models import EditingSession
from wagtail.models import GroupPagePermission, Page
from wagtail.test.testapp.models import FullFeaturedSnippet, SimplePage
from wagtail.test.testapp.models import Advert, SimplePage
from wagtail.test.utils import WagtailTestUtils

if settings.USE_TZ:
Expand Down Expand Up @@ -576,7 +576,7 @@ def test_user_must_have_edit_permission_on_page(self):

@freeze_time(TIMESTAMP_NOW)
def test_ping_snippet_model(self):
snippet = FullFeaturedSnippet.objects.create(text="Test snippet")
snippet = Advert.objects.create(text="Test snippet")

# make user a member of Editors
self.user.is_superuser = False
Expand All @@ -585,27 +585,27 @@ def test_ping_snippet_model(self):
self.user.groups.add(editors)

editors.permissions.add(
Permission.objects.get(codename="change_fullfeaturedsnippet"),
Permission.objects.get(codename="change_advert"),
)

session = EditingSession.objects.create(
user=self.user,
content_type=ContentType.objects.get_for_model(FullFeaturedSnippet),
content_type=ContentType.objects.get_for_model(Advert),
object_id=snippet.pk,
last_seen_at=TIMESTAMP_1,
)
# add two sessions from other_user to test that we correctly merge them into
# one record in the response
EditingSession.objects.create(
user=self.other_user,
content_type=ContentType.objects.get_for_model(FullFeaturedSnippet),
content_type=ContentType.objects.get_for_model(Advert),
object_id=snippet.pk,
last_seen_at=TIMESTAMP_2,
is_editing=True,
)
other_session_2 = EditingSession.objects.create(
user=self.other_user,
content_type=ContentType.objects.get_for_model(FullFeaturedSnippet),
content_type=ContentType.objects.get_for_model(Advert),
object_id=snippet.pk,
last_seen_at=TIMESTAMP_3,
is_editing=False,
Expand All @@ -614,14 +614,14 @@ def test_ping_snippet_model(self):
# session with last_seen_at too far in the past to be included in the response
EditingSession.objects.create(
user=self.other_user,
content_type=ContentType.objects.get_for_model(FullFeaturedSnippet),
content_type=ContentType.objects.get_for_model(Advert),
object_id=snippet.pk,
last_seen_at=TIMESTAMP_PAST,
)
response = self.client.post(
reverse(
"wagtailadmin_editing_sessions:ping",
args=("tests", "fullfeaturedsnippet", str(snippet.pk), session.id),
args=("tests", "advert", str(snippet.pk), session.id),
)
)
self.assertEqual(response.status_code, 200)
Expand All @@ -644,7 +644,7 @@ def test_ping_snippet_model(self):
self.assertFalse(session.is_editing)

def test_ping_snippet_model_without_permission(self):
snippet = FullFeaturedSnippet.objects.create(text="Test snippet")
snippet = Advert.objects.create(text="Test snippet")

# make user a member of Editors
self.user.is_superuser = False
Expand All @@ -654,14 +654,14 @@ def test_ping_snippet_model_without_permission(self):

session = EditingSession.objects.create(
user=self.user,
content_type=ContentType.objects.get_for_model(FullFeaturedSnippet),
content_type=ContentType.objects.get_for_model(Advert),
object_id=snippet.pk,
last_seen_at=TIMESTAMP_1,
)
response = self.client.post(
reverse(
"wagtailadmin_editing_sessions:ping",
args=("tests", "fullfeaturedsnippet", str(snippet.pk), session.id),
args=("tests", "advert", str(snippet.pk), session.id),
)
)
self.assertEqual(response.status_code, 404)
Expand Down

0 comments on commit 7b11422

Please sign in to comment.