Add tests for sponsorblock_categories

This commit is contained in:
tcely authored and GitHub committed 2025-02-02 00:07:45 -05:00
1 parent a06bd29f88
commit 9397ec7389
1 file changed
+22
+22
View File
@@ -172,6 +172,8 @@ class FrontEndTestCase(TestCase):
response = c.get('/source-add')
self.assertEqual(response.status_code, 200)
# Create a new source
data_categories = ('sponsor', 'preview',)
exected_categories = ['sponsor', 'preview']
data = {
'source_type': 'c',
'key': 'testkey',
@@ -190,6 +192,7 @@ class FrontEndTestCase(TestCase):
'prefer_60fps': False,
'prefer_hdr': False,
'fallback': 'f',
'sponsorblock_categories': data_categories,
'sub_langs': 'en',
}
response = c.post('/source-add', data)
@@ -203,6 +206,9 @@ class FrontEndTestCase(TestCase):
source_uuid = path_parts[1]
source = Source.objects.get(pk=source_uuid)
self.assertEqual(str(source.pk), source_uuid)
# Check that the SponsorBlock categories were saved
self.assertEqual(source.sponsorblock_categories.selected_choices,
exected_categories)
# Check a task was created to index the media for the new source
source_uuid = str(source.pk)
task = Task.objects.get_task('sync.tasks.index_source_task',
@@ -215,6 +221,13 @@ class FrontEndTestCase(TestCase):
# Check the source detail page loads
response = c.get(f'/source/{source_uuid}')
self.assertEqual(response.status_code, 200)
# save and refresh the Source
source.refresh_from_db()
source.save()
source.refresh_from_db()
# Check that the SponsorBlock categories remain saved
self.assertEqual(source.sponsorblock_categories.selected_choices,
exected_categories)
# Update the source key
data = {
'source_type': Source.SOURCE_TYPE_YOUTUBE_CHANNEL,
@@ -234,6 +247,7 @@ class FrontEndTestCase(TestCase):
'prefer_60fps': False,
'prefer_hdr': False,
'fallback': Source.FALLBACK_FAIL,
'sponsorblock_categories': data_categories,
'sub_langs': 'en',
}
response = c.post(f'/source-update/{source_uuid}', data)
@@ -247,6 +261,10 @@ class FrontEndTestCase(TestCase):
source_uuid = path_parts[1]
source = Source.objects.get(pk=source_uuid)
self.assertEqual(source.key, 'updatedkey')
# Check that the SponsorBlock categories remain saved
source.refresh_from_db()
self.assertEqual(source.sponsorblock_categories.selected_choices,
exected_categories)
# Update the source index schedule which should recreate the scheduled task
data = {
'source_type': Source.SOURCE_TYPE_YOUTUBE_CHANNEL,
@@ -266,6 +284,7 @@ class FrontEndTestCase(TestCase):
'prefer_60fps': False,
'prefer_hdr': False,
'fallback': Source.FALLBACK_FAIL,
'sponsorblock_categories': data_categories,
'sub_langs': 'en',
}
response = c.post(f'/source-update/{source_uuid}', data)
@@ -278,6 +297,9 @@ class FrontEndTestCase(TestCase):
self.assertEqual(path_parts[0], 'source')
source_uuid = path_parts[1]
source = Source.objects.get(pk=source_uuid)
# Check that the SponsorBlock categories remain saved
self.assertEqual(source.sponsorblock_categories.selected_choices,
exected_categories)
# Check a new task has been created by seeing if the pk has changed
new_task = Task.objects.get_task('sync.tasks.index_source_task',
args=(source_uuid,))[0]