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

Fix tests for background task behaviour in Wagtail 6.4 #255

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
7 changes: 4 additions & 3 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@
class ApiTestBase(TestCase):
@classmethod
def setUpTestData(cls):
cls.a_space_odyssey = create_video("2001: A Space Odyssey")
cls.tng = create_video("Star Trek: The Next Generation")
cls.pink_floyd_time = create_audio("Pink Floyd: Time")
with cls.captureOnCommitCallbacks(execute=True):
cls.a_space_odyssey = create_video("2001: A Space Odyssey")
cls.tng = create_video("Star Trek: The Next Generation")
cls.pink_floyd_time = create_audio("Pink Floyd: Time")

def tearDown(self) -> None:
for item in Media.objects.all():
Expand Down
13 changes: 8 additions & 5 deletions tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,17 @@ def test_duration_display_as_tenths(self):
class TestMediaQuerySet(TestCase):
def test_search_method(self):
# Make a test media
media = Media.objects.create(title="Test media file", duration=100)
with self.captureOnCommitCallbacks(execute=True):
media = Media.objects.create(title="Test media file", duration=100)

# Search for it
results = Media.objects.search("Test")
self.assertEqual(list(results), [media])

def test_operators(self):
aaa_media = Media.objects.create(title="AAA Test media", duration=100)
zzz_media = Media.objects.create(title="ZZZ Test media", duration=100)
with self.captureOnCommitCallbacks(execute=True):
aaa_media = Media.objects.create(title="AAA Test media", duration=100)
zzz_media = Media.objects.create(title="ZZZ Test media", duration=100)

results = Media.objects.search("aaa test", operator="and")
self.assertEqual(list(results), [aaa_media])
Expand All @@ -129,8 +131,9 @@ def test_operators(self):
self.assertEqual(sorted_results, [aaa_media, zzz_media])

def test_custom_ordering(self):
aaa_media = Media.objects.create(title="AAA Test media", duration=100)
zzz_media = Media.objects.create(title="ZZZ Test media", duration=100)
with self.captureOnCommitCallbacks(execute=True):
aaa_media = Media.objects.create(title="AAA Test media", duration=100)
zzz_media = Media.objects.create(title="ZZZ Test media", duration=100)

results = Media.objects.order_by("title").search(
"Test", order_by_relevance=False
Expand Down
37 changes: 20 additions & 17 deletions tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -723,15 +723,16 @@ def filter_media(media, request):
self.assertEqual(response.context["media_files"][0], media)

def test_construct_queryset_hook_search(self):
media = models.Media.objects.create(
title="Test media shown",
duration=100,
type="audio",
uploaded_by_user=self.user,
)
models.Media.objects.create(
title="Test media not shown", duration=100, type="audio"
)
with self.captureOnCommitCallbacks(execute=True):
media = models.Media.objects.create(
title="Test media shown",
duration=100,
type="audio",
uploaded_by_user=self.user,
)
models.Media.objects.create(
title="Test media not shown", duration=100, type="audio"
)

def filter_media(media, request):
return media.filter(uploaded_by_user=self.user)
Expand Down Expand Up @@ -1100,19 +1101,21 @@ def test_unused_media_usage_count(self):
def test_used_media_usage_count(self):
media = models.Media.objects.get(id=1)
page = EventPage.objects.get(id=3)
event_page_related_link = EventPageRelatedMedia()
event_page_related_link.page = page
event_page_related_link.link_media = media
event_page_related_link.save()
with self.captureOnCommitCallbacks(execute=True):
event_page_related_link = EventPageRelatedMedia()
event_page_related_link.page = page
event_page_related_link.link_media = media
event_page_related_link.save()
self.assertEqual(media.get_usage().count(), 1)

def test_usage_count_appears(self):
media = models.Media.objects.get(id=1)
page = EventPage.objects.get(id=3)
event_page_related_link = EventPageRelatedMedia()
event_page_related_link.page = page
event_page_related_link.link_media = media
event_page_related_link.save()
with self.captureOnCommitCallbacks(execute=True):
event_page_related_link = EventPageRelatedMedia()
event_page_related_link.page = page
event_page_related_link.link_media = media
event_page_related_link.save()
response = self.client.get(reverse("wagtailmedia:edit", args=(1,)))
self.assertContains(response, "Used 1 time")

Expand Down
Loading