3434from contentcuration .models import UserHistory
3535from contentcuration .tests import testdata
3636from contentcuration .tests .base import StudioTestCase
37+ from contentcuration .tests .helpers import EagerTasksTestMixin
3738from contentcuration .viewsets .sync .constants import DELETED
3839
3940
@@ -550,14 +551,17 @@ def test_make_content_id_unique(self):
550551
551552
552553@mock .patch (
553- "contentcuration.utils.publish.ensure_versioned_database_exists" , return_value = None
554+ "contentcuration.tasks.ensure_versioned_database_exists_task.fetch_or_enqueue" ,
555+ return_value = None ,
554556)
555- class CommunityLibrarySubmissionTestCase (PermissionQuerysetTestCase ):
557+ class CommunityLibrarySubmissionTestCase (
558+ EagerTasksTestMixin , PermissionQuerysetTestCase
559+ ):
556560 @property
557561 def base_queryset (self ):
558562 return CommunityLibrarySubmission .objects .all ()
559563
560- def test_create_submission (self , mock_ensure_db_exists ):
564+ def test_create_submission (self , mock_ensure_db_exists_task_fetch_or_enqueue ):
561565 # Smoke test
562566 channel = testdata .channel ()
563567 author = testdata .user ()
@@ -587,20 +591,26 @@ def test_save__author_not_editor(self, mock_ensure_db_exists):
587591 with self .assertRaises (ValidationError ):
588592 submission .save ()
589593
590- def test_save__nonpositive_channel_version (self , mock_ensure_db_exists ):
594+ def test_save__nonpositive_channel_version (
595+ self , mock_ensure_db_exists_task_fetch_or_enqueue
596+ ):
591597 submission = testdata .community_library_submission ()
592598 submission .channel_version = 0
593599 with self .assertRaises (ValidationError ):
594600 submission .save ()
595601
596- def test_save__matching_channel_version (self , mock_ensure_db_exists ):
602+ def test_save__matching_channel_version (
603+ self , mock_ensure_db_exists_task_fetch_or_enqueue
604+ ):
597605 submission = testdata .community_library_submission ()
598606 submission .channel .version = 5
599607 submission .channel .save ()
600608 submission .channel_version = 5
601609 submission .save ()
602610
603- def test_save__impossibly_high_channel_version (self , mock_ensure_db_exists ):
611+ def test_save__impossibly_high_channel_version (
612+ self , mock_ensure_db_exists_task_fetch_or_enqueue
613+ ):
604614 submission = testdata .community_library_submission ()
605615 submission .channel .version = 5
606616 submission .channel .save ()
@@ -609,40 +619,50 @@ def test_save__impossibly_high_channel_version(self, mock_ensure_db_exists):
609619 submission .save ()
610620
611621 def test_save__ensure_versioned_database_exists_on_create (
612- self , mock_ensure_db_exists
622+ self , mock_ensure_db_exists_task_fetch_or_enqueue
613623 ):
614624 submission = testdata .community_library_submission ()
615625
616- mock_ensure_db_exists .assert_called_once_with (submission .channel )
626+ mock_ensure_db_exists_task_fetch_or_enqueue .assert_called_once_with (
627+ user = submission .author ,
628+ channel_id = submission .channel .id ,
629+ channel_version = submission .channel .version ,
630+ )
617631
618632 def test_save__dont_ensure_versioned_database_exists_on_update (
619- self , mock_ensure_db_exists
633+ self , mock_ensure_db_exists_task_fetch_or_enqueue
620634 ):
621635 submission = testdata .community_library_submission ()
622- mock_ensure_db_exists .reset_mock ()
636+ mock_ensure_db_exists_task_fetch_or_enqueue .reset_mock ()
623637
624638 submission .description = "Updated description"
625639 submission .save ()
626640
627- mock_ensure_db_exists .assert_not_called ()
641+ mock_ensure_db_exists_task_fetch_or_enqueue .assert_not_called ()
628642
629- def test_filter_view_queryset__anonymous (self , mock_ensure_db_exists ):
643+ def test_filter_view_queryset__anonymous (
644+ self , mock_ensure_db_exists_task_fetch_or_enqueue
645+ ):
630646 _ = testdata .community_library_submission ()
631647
632648 queryset = CommunityLibrarySubmission .filter_view_queryset (
633649 self .base_queryset , user = self .anonymous_user
634650 )
635651 self .assertFalse (queryset .exists ())
636652
637- def test_filter_view_queryset__forbidden_user (self , mock_ensure_db_exists ):
653+ def test_filter_view_queryset__forbidden_user (
654+ self , mock_ensure_db_exists_task_fetch_or_enqueue
655+ ):
638656 _ = testdata .community_library_submission ()
639657
640658 queryset = CommunityLibrarySubmission .filter_view_queryset (
641659 self .base_queryset , user = self .forbidden_user
642660 )
643661 self .assertFalse (queryset .exists ())
644662
645- def test_filter_view_queryset__channel_editor (self , mock_ensure_db_exists ):
663+ def test_filter_view_queryset__channel_editor (
664+ self , mock_ensure_db_exists_task_fetch_or_enqueue
665+ ):
646666 submission_a = testdata .community_library_submission ()
647667 submission_b = testdata .community_library_submission ()
648668
@@ -656,31 +676,39 @@ def test_filter_view_queryset__channel_editor(self, mock_ensure_db_exists):
656676 self .assertQuerysetContains (queryset , pk = submission_a .id )
657677 self .assertQuerysetDoesNotContain (queryset , pk = submission_b .id )
658678
659- def test_filter_view_queryset__admin (self , mock_ensure_db_exists ):
679+ def test_filter_view_queryset__admin (
680+ self , mock_ensure_db_exists_task_fetch_or_enqueue
681+ ):
660682 submission_a = testdata .community_library_submission ()
661683
662684 queryset = CommunityLibrarySubmission .filter_view_queryset (
663685 self .base_queryset , user = self .admin_user
664686 )
665687 self .assertQuerysetContains (queryset , pk = submission_a .id )
666688
667- def test_filter_edit_queryset__anonymous (self , mock_ensure_db_exists ):
689+ def test_filter_edit_queryset__anonymous (
690+ self , mock_ensure_db_exists_task_fetch_or_enqueue
691+ ):
668692 _ = testdata .community_library_submission ()
669693
670694 queryset = CommunityLibrarySubmission .filter_edit_queryset (
671695 self .base_queryset , user = self .anonymous_user
672696 )
673697 self .assertFalse (queryset .exists ())
674698
675- def test_filter_edit_queryset__forbidden_user (self , mock_ensure_db_exists ):
699+ def test_filter_edit_queryset__forbidden_user (
700+ self , mock_ensure_db_exists_task_fetch_or_enqueue
701+ ):
676702 _ = testdata .community_library_submission ()
677703
678704 queryset = CommunityLibrarySubmission .filter_edit_queryset (
679705 self .base_queryset , user = self .forbidden_user
680706 )
681707 self .assertFalse (queryset .exists ())
682708
683- def test_filter_edit_queryset__channel_editor (self , mock_ensure_db_exists ):
709+ def test_filter_edit_queryset__channel_editor (
710+ self , mock_ensure_db_exists_task_fetch_or_enqueue
711+ ):
684712 submission = testdata .community_library_submission ()
685713
686714 user = testdata .user ()
@@ -692,7 +720,9 @@ def test_filter_edit_queryset__channel_editor(self, mock_ensure_db_exists):
692720 )
693721 self .assertFalse (queryset .exists ())
694722
695- def test_filter_edit_queryset__author (self , mock_ensure_db_exists ):
723+ def test_filter_edit_queryset__author (
724+ self , mock_ensure_db_exists_task_fetch_or_enqueue
725+ ):
696726 submission_a = testdata .community_library_submission ()
697727 submission_b = testdata .community_library_submission ()
698728
@@ -702,15 +732,17 @@ def test_filter_edit_queryset__author(self, mock_ensure_db_exists):
702732 self .assertQuerysetContains (queryset , pk = submission_a .id )
703733 self .assertQuerysetDoesNotContain (queryset , pk = submission_b .id )
704734
705- def test_filter_edit_queryset__admin (self , mock_ensure_db_exists ):
735+ def test_filter_edit_queryset__admin (
736+ self , mock_ensure_db_exists_task_fetch_or_enqueue
737+ ):
706738 submission_a = testdata .community_library_submission ()
707739
708740 queryset = CommunityLibrarySubmission .filter_edit_queryset (
709741 self .base_queryset , user = self .admin_user
710742 )
711743 self .assertQuerysetContains (queryset , pk = submission_a .id )
712744
713- def test_mark_live (self , mock_ensure_db_exists ):
745+ def test_mark_live (self , mock_ensure_db_exists_task_fetch_or_enqueue ):
714746 submission_a = testdata .community_library_submission ()
715747 submission_b = testdata .community_library_submission ()
716748
0 commit comments