@@ -549,12 +549,15 @@ def test_make_content_id_unique(self):
549549 self .assertNotEqual (copied_node_old_content_id , copied_node .content_id )
550550
551551
552+ @mock .patch (
553+ "contentcuration.utils.publish.ensure_versioned_database_exists" , return_value = None
554+ )
552555class CommunityLibrarySubmissionTestCase (PermissionQuerysetTestCase ):
553556 @property
554557 def base_queryset (self ):
555558 return CommunityLibrarySubmission .objects .all ()
556559
557- def test_create_submission (self ):
560+ def test_create_submission (self , mock_ensure_db_exists ):
558561 # Smoke test
559562 channel = testdata .channel ()
560563 author = testdata .user ()
@@ -577,51 +580,69 @@ def test_create_submission(self):
577580 submission .full_clean ()
578581 submission .save ()
579582
580- def test_save__author_not_editor (self ):
583+ def test_save__author_not_editor (self , mock_ensure_db_exists ):
581584 submission = testdata .community_library_submission ()
582585 user = testdata .user ("some@email.com" )
583586 submission .author = user
584587 with self .assertRaises (ValidationError ):
585588 submission .save ()
586589
587- def test_save__nonpositive_channel_version (self ):
590+ def test_save__nonpositive_channel_version (self , mock_ensure_db_exists ):
588591 submission = testdata .community_library_submission ()
589592 submission .channel_version = 0
590593 with self .assertRaises (ValidationError ):
591594 submission .save ()
592595
593- def test_save__matching_channel_version (self ):
596+ def test_save__matching_channel_version (self , mock_ensure_db_exists ):
594597 submission = testdata .community_library_submission ()
595598 submission .channel .version = 5
596599 submission .channel .save ()
597600 submission .channel_version = 5
598601 submission .save ()
599602
600- def test_save__impossibly_high_channel_version (self ):
603+ def test_save__impossibly_high_channel_version (self , mock_ensure_db_exists ):
601604 submission = testdata .community_library_submission ()
602605 submission .channel .version = 5
603606 submission .channel .save ()
604607 submission .channel_version = 6
605608 with self .assertRaises (ValidationError ):
606609 submission .save ()
607610
608- def test_filter_view_queryset__anonymous (self ):
611+ def test_save__ensure_versioned_database_exists_on_create (
612+ self , mock_ensure_db_exists
613+ ):
614+ submission = testdata .community_library_submission ()
615+
616+ mock_ensure_db_exists .assert_called_once_with (submission .channel )
617+
618+ def test_save__dont_ensure_versioned_database_exists_on_update (
619+ self , mock_ensure_db_exists
620+ ):
621+ submission = testdata .community_library_submission ()
622+ mock_ensure_db_exists .reset_mock ()
623+
624+ submission .description = "Updated description"
625+ submission .save ()
626+
627+ mock_ensure_db_exists .assert_not_called ()
628+
629+ def test_filter_view_queryset__anonymous (self , mock_ensure_db_exists ):
609630 _ = testdata .community_library_submission ()
610631
611632 queryset = CommunityLibrarySubmission .filter_view_queryset (
612633 self .base_queryset , user = self .anonymous_user
613634 )
614635 self .assertFalse (queryset .exists ())
615636
616- def test_filter_view_queryset__forbidden_user (self ):
637+ def test_filter_view_queryset__forbidden_user (self , mock_ensure_db_exists ):
617638 _ = testdata .community_library_submission ()
618639
619640 queryset = CommunityLibrarySubmission .filter_view_queryset (
620641 self .base_queryset , user = self .forbidden_user
621642 )
622643 self .assertFalse (queryset .exists ())
623644
624- def test_filter_view_queryset__channel_editor (self ):
645+ def test_filter_view_queryset__channel_editor (self , mock_ensure_db_exists ):
625646 submission_a = testdata .community_library_submission ()
626647 submission_b = testdata .community_library_submission ()
627648
@@ -635,31 +656,31 @@ def test_filter_view_queryset__channel_editor(self):
635656 self .assertQuerysetContains (queryset , pk = submission_a .id )
636657 self .assertQuerysetDoesNotContain (queryset , pk = submission_b .id )
637658
638- def test_filter_view_queryset__admin (self ):
659+ def test_filter_view_queryset__admin (self , mock_ensure_db_exists ):
639660 submission_a = testdata .community_library_submission ()
640661
641662 queryset = CommunityLibrarySubmission .filter_view_queryset (
642663 self .base_queryset , user = self .admin_user
643664 )
644665 self .assertQuerysetContains (queryset , pk = submission_a .id )
645666
646- def test_filter_edit_queryset__anonymous (self ):
667+ def test_filter_edit_queryset__anonymous (self , mock_ensure_db_exists ):
647668 _ = testdata .community_library_submission ()
648669
649670 queryset = CommunityLibrarySubmission .filter_edit_queryset (
650671 self .base_queryset , user = self .anonymous_user
651672 )
652673 self .assertFalse (queryset .exists ())
653674
654- def test_filter_edit_queryset__forbidden_user (self ):
675+ def test_filter_edit_queryset__forbidden_user (self , mock_ensure_db_exists ):
655676 _ = testdata .community_library_submission ()
656677
657678 queryset = CommunityLibrarySubmission .filter_edit_queryset (
658679 self .base_queryset , user = self .forbidden_user
659680 )
660681 self .assertFalse (queryset .exists ())
661682
662- def test_filter_edit_queryset__channel_editor (self ):
683+ def test_filter_edit_queryset__channel_editor (self , mock_ensure_db_exists ):
663684 submission = testdata .community_library_submission ()
664685
665686 user = testdata .user ()
@@ -671,7 +692,7 @@ def test_filter_edit_queryset__channel_editor(self):
671692 )
672693 self .assertFalse (queryset .exists ())
673694
674- def test_filter_edit_queryset__author (self ):
695+ def test_filter_edit_queryset__author (self , mock_ensure_db_exists ):
675696 submission_a = testdata .community_library_submission ()
676697 submission_b = testdata .community_library_submission ()
677698
@@ -681,7 +702,7 @@ def test_filter_edit_queryset__author(self):
681702 self .assertQuerysetContains (queryset , pk = submission_a .id )
682703 self .assertQuerysetDoesNotContain (queryset , pk = submission_b .id )
683704
684- def test_filter_edit_queryset__admin (self ):
705+ def test_filter_edit_queryset__admin (self , mock_ensure_db_exists ):
685706 submission_a = testdata .community_library_submission ()
686707
687708 queryset = CommunityLibrarySubmission .filter_edit_queryset (
0 commit comments