44import ddt # type: ignore[import]
55import pytest
66from django .core .exceptions import ValidationError
7- from django .db import IntegrityError
87
98from openedx_learning .api import authoring as authoring_api
109from openedx_learning .api import authoring_models
1514
1615
1716@ddt .ddt
18- class SubSectionTestCase (SubSectionTestCase ):
17+ class SectionTestCase (SubSectionTestCase ):
1918 """ Test cases for Sections (containers of subsections) """
2019
2120 def setUp (self ) -> None :
@@ -320,7 +319,10 @@ def test_create_next_section_version_with_unpinned_and_pinned_subsections(self):
320319 section_version_v2 = authoring_api .create_next_section_version (
321320 section = section ,
322321 title = "Section" ,
323- subsections = [self .subsection_1 , self .subsection_2_v1 ], # Note the "v1" pinning 📌 the second one to version 1
322+ subsections = [
323+ self .subsection_1 ,
324+ self .subsection_2_v1
325+ ], # Note the "v1" pinning 📌 the second one to version 1
324326 created = self .now ,
325327 created_by = None ,
326328 )
@@ -341,7 +343,9 @@ def test_auto_publish_children(self):
341343 # Create a draft section with two draft subsections
342344 section = self .create_section_with_subsections ([self .subsection_1 , self .subsection_2 ])
343345 # Also create another subsection that's not in the section at all:
344- other_subsection , _os_v1 = self .create_subsection (title = "A draft subsection not in the section" , key = "subsection:3" )
346+ other_subsection , _os_v1 = self .create_subsection (
347+ title = "A draft subsection not in the section" , key = "subsection:3"
348+ )
345349
346350 assert authoring_api .contains_unpublished_changes (section .pk )
347351 assert self .subsection_1 .versioning .published is None
@@ -403,7 +407,7 @@ def test_add_subsection_after_publish(self):
403407 # Publish the empty section:
404408 authoring_api .publish_all_drafts (self .learning_package .id )
405409 section .refresh_from_db () # Reloading the section is necessary
406- assert section .versioning .has_unpublished_changes is False # Shallow check for just the section itself, not children
410+ assert section .versioning .has_unpublished_changes is False # Shallow check for the section itself, not children
407411 assert authoring_api .contains_unpublished_changes (section .pk ) is False # Deeper check
408412
409413 # Add a published subsection (unpinned):
@@ -449,7 +453,7 @@ def test_modify_unpinned_subsection_after_publish(self):
449453 # The subsection now has unpublished changes; the section doesn't directly but does contain
450454 section .refresh_from_db () # Reloading the section is necessary, or 'section.versioning' will be outdated
451455 self .subsection_1 .refresh_from_db ()
452- assert section .versioning .has_unpublished_changes is False # Shallow check should be false - section is unchanged
456+ assert section .versioning .has_unpublished_changes is False # Shallow check should be false - section unchanged
453457 assert authoring_api .contains_unpublished_changes (section .pk ) # But section DOES contain changes
454458 assert self .subsection_1 .versioning .has_unpublished_changes
455459
@@ -511,17 +515,21 @@ def test_create_two_sections_with_same_subsections(self):
511515 subsections in each section.
512516 """
513517 # Create a section with subsection 2 unpinned, subsection 2 pinned 📌, and subsection 1:
514- section1 = self .create_section_with_subsections ([self .subsection_2 , self .subsection_2_v1 , self .subsection_1 ], key = "u1" )
518+ section1 = self .create_section_with_subsections (
519+ [self .subsection_2 , self .subsection_2_v1 , self .subsection_1 ], key = "u1"
520+ )
515521 # Create a second section with subsection 1 pinned 📌, subsection 2, and subsection 1 unpinned:
516- section2 = self .create_section_with_subsections ([self .subsection_1_v1 , self .subsection_2 , self .subsection_1 ], key = "u2" )
522+ section2 = self .create_section_with_subsections (
523+ [self .subsection_1_v1 , self .subsection_2 , self .subsection_1 ], key = "u2"
524+ )
517525
518526 # Check that the contents are as expected:
519- assert [row . subsection_version for row in authoring_api . get_subsections_in_section ( section1 , published = False )] == [
520- self . subsection_2_v1 , self . subsection_2_v1 , self . subsection_1_v1 ,
521- ]
522- assert [row . subsection_version for row in authoring_api . get_subsections_in_section ( section2 , published = False )] == [
523- self . subsection_1_v1 , self . subsection_2_v1 , self . subsection_1_v1 ,
524- ]
527+ assert [
528+ row . subsection_version for row in authoring_api . get_subsections_in_section ( section1 , published = False )
529+ ] == [ self . subsection_2_v1 , self . subsection_2_v1 , self . subsection_1_v1 ,]
530+ assert [
531+ row . subsection_version for row in authoring_api . get_subsections_in_section ( section2 , published = False )
532+ ] == [ self . subsection_1_v1 , self . subsection_2_v1 , self . subsection_1_v1 ,]
525533
526534 # Modify subsection 1
527535 subsection_1_v2 = self .modify_subsection (self .subsection_1 , title = "subsection 1 v2" )
@@ -575,7 +583,7 @@ def test_publishing_shared_subsection(self):
575583
576584 # 2️⃣ Then the author edits S2 inside of Section 1 making S2v2.
577585 s2_v2 = self .modify_subsection (s2 , title = "U2 version 2" )
578- # This makes S1 and S2 both show up as Sections that CONTAIN unpublished changes, because they share the subsection.
586+ # This makes S1, S2 both show up as Sections that CONTAIN unpublished changes, because they share the subsection
579587 assert authoring_api .contains_unpublished_changes (section1 .pk )
580588 assert authoring_api .contains_unpublished_changes (section2 .pk )
581589 # (But the sections themselves are unchanged:)
@@ -603,21 +611,23 @@ def test_publishing_shared_subsection(self):
603611 Entry (s3_v1 ),
604612 ]
605613
606- # Result: someone looking at Section 2 should see the newly published subsection 2, because publishing it anywhere
607- # publishes it everywhere. But publishing U2 and Section 1 does not affect the other subsections in Section 2.
614+ # Result: someone looking at Section 2 should see the newly published subsection 2,
615+ # because publishing it anywhere publishes it everywhere.
616+ # But publishing U2 and Section 1 does not affect the other subsections in Section 2.
608617 # (Publish propagates downward, not upward)
609618 assert authoring_api .get_subsections_in_section (section2 , published = True ) == [
610619 Entry (s2_v2 ), # new published version of U2
611620 Entry (s4_v1 ), # still original version of U4 (it was never modified)
612621 Entry (s5_v1 ), # still original version of U5 (it hasn't been published)
613622 ]
614623
615- # Result: Section 2 CONTAINS unpublished changes because of the modified U5. Section 1 doesn't contain unpub changes.
624+ # Result: Section 2 CONTAINS unpublished changes because of the modified U5.
625+ # Section 1 doesn't contain unpub changes.
616626 assert authoring_api .contains_unpublished_changes (section1 .pk ) is False
617627 assert authoring_api .contains_unpublished_changes (section2 .pk )
618628
619629 # 5️⃣ Publish subsection U5, which should be the only thing unpublished in the learning package
620- self .publish_subsection (u5 )
630+ self .publish_subsection (s5 )
621631 # Result: Section 2 shows the new version of C5 and no longer contains unpublished changes:
622632 assert authoring_api .get_subsections_in_section (section2 , published = True ) == [
623633 Entry (s2_v2 ), # new published version of U2
@@ -723,11 +733,11 @@ def test_soft_deleting_subsection(self):
723733 Entry (self .subsection_1_v1 ),
724734 # subsection 2 is soft deleted from the draft.
725735 # TODO: should we return some kind of placeholder here, to indicate that a subsection is still listed in the
726- # section's subsection list but has been soft deleted, and will be fully deleted when published, or restored if
727- # reverted?
736+ # section's subsection list but has been soft deleted, and will be fully deleted when published,
737+ # or restored if reverted?
728738 ]
729- assert section .versioning .has_unpublished_changes is False # The section itself and its subsection list is not changed
730- assert authoring_api .contains_unpublished_changes (section .pk ) # But it CONTAINS an unpublished change (a deletion)
739+ assert section .versioning .has_unpublished_changes is False # The section and its subsection list is not changed
740+ assert authoring_api .contains_unpublished_changes (section .pk ) # But it CONTAINS unpublished change (deletion)
731741 # The published version of the section is not yet affected:
732742 assert authoring_api .get_subsections_in_section (section , published = True ) == [
733743 Entry (self .subsection_1_v1 ),
@@ -789,7 +799,7 @@ def test_soft_deleting_pinned_subsection(self):
789799 Entry (self .subsection_1_v1 , pinned = True ),
790800 Entry (self .subsection_2_v1 , pinned = True ),
791801 ]
792- assert section .versioning .has_unpublished_changes is False # The section itself and its subsection list is not changed
802+ assert section .versioning .has_unpublished_changes is False # The section and its subsection list is not changed
793803 assert authoring_api .contains_unpublished_changes (section .pk ) is False # nor does it contain changes
794804 # The published version of the section is also not affected:
795805 assert authoring_api .get_subsections_in_section (section , published = True ) == [
@@ -812,7 +822,7 @@ def test_soft_delete_section(self):
812822 # Delete the section:
813823 authoring_api .soft_delete_draft (section_to_delete .publishable_entity_id )
814824 section_to_delete .refresh_from_db ()
815- # Now the draft section is [soft] deleted, but the subsections, published section, and other section is unaffected:
825+ # Now draft section is [soft] deleted, but the subsections, published section, and other section is unaffected:
816826 assert section_to_delete .versioning .draft is None # Section is soft deleted.
817827 assert section_to_delete .versioning .published is not None
818828 self .subsection_1 .refresh_from_db ()
@@ -911,7 +921,7 @@ def test_sections_containing(self):
911921 subsection_1_v2 = self .modify_subsection (self .subsection_1 , title = "modified subsection 1" )
912922
913923 # Create a few sections, some of which contain subsection 1 and others which don't:
914- # Note: it is important that some of these sections contain other subsections, to ensure the complex JOINs required
924+ # Note: it is important that some of these sections contain other subsections, to ensure complex JOINs required
915925 # for this query are working correctly, especially in the case of ignore_pinned=True.
916926 # Section 1 ✅ has subsection 1, pinned 📌 to V1
917927 section1_1pinned = self .create_section_with_subsections ([self .subsection_1_v1 , self .subsection_2 ], key = "s1" )
@@ -946,7 +956,9 @@ def test_sections_containing(self):
946956 with self .assertNumQueries (1 ):
947957 result2 = [
948958 c .section for c in
949- authoring_api .get_containers_with_entity (self .subsection_1 .pk , ignore_pinned = True ).select_related ("section" )
959+ authoring_api .get_containers_with_entity (
960+ self .subsection_1 .pk , ignore_pinned = True
961+ ).select_related ("section" )
950962 ]
951963 assert result2 == [section4_unpinned ]
952964
@@ -1042,5 +1054,5 @@ def test_get_container_children_count(self):
10421054 # Test that I can get a [PublishLog] history of a given section and all its children, including children that aren't
10431055 # currently in the section and excluding children that are only in other sections.
10441056 # Test that I can get a [PublishLog] history of a given section and its children, that includes changes made to the
1045- # child subsections while they were part of the section but excludes changes made to those children while they were
1057+ # child subsections while they were part of section but excludes changes made to those children while they were
10461058 # not part of the section. 🫣
0 commit comments