Skip to content

Commit

Permalink
test: Tests added for CourseOverviewPage
Browse files Browse the repository at this point in the history
  • Loading branch information
marslanabdulrauf committed Nov 25, 2024
1 parent 21f47ef commit 03afb18
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
11 changes: 11 additions & 0 deletions cms/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
CertificatePage,
CompaniesLogoCarouselSection,
CourseIndexPage,
CourseOverviewPage,
CoursePage,
CoursesInProgramPage,
EnterprisePage,
Expand Down Expand Up @@ -576,3 +577,13 @@ class LearningStrategyFormPageFactory(wagtail_factories.PageFactory):

class Meta:
model = LearningStrategyFormSection


class CourseOverviewPageFactory(wagtail_factories.PageFactory):
"""CourseOverviewPage factory class"""

heading = factory.fuzzy.FuzzyText(prefix="heading ")
sub_heading = factory.LazyFunction(lambda: RichText(f"<p>{FAKE.paragraph()}</p>"))

class Meta:
model = CourseOverviewPage
28 changes: 28 additions & 0 deletions cms/models_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from cms.factories import (
CertificatePageFactory,
CompaniesLogoCarouselPageFactory,
CourseOverviewPageFactory,
CoursePageFactory,
CoursesInProgramPageFactory,
EnterprisePageFactory,
Expand Down Expand Up @@ -57,6 +58,7 @@
)
from cms.models import (
CertificatePage,
CourseOverviewPage,
CoursesInProgramPage,
ForTeamsPage,
FrequentlyAskedQuestionPage,
Expand Down Expand Up @@ -2089,3 +2091,29 @@ def test_certificatepage_saved_no_signatories_external_courseware(

resp = superuser_client.post(path, data_to_post)
assert resp.status_code == 302


def test_course_overview_page():
external_course_page = ExternalCoursePageFactory.create()
assert not external_course_page.course_overview
assert CourseOverviewPage.can_create_at(external_course_page)
overview_page = CourseOverviewPageFactory.create(
parent=external_course_page,
sub_heading="<p>paragraph content</p>",
heading="test heading",
)

# invalidate cached property
del external_course_page.child_pages

assert overview_page.get_parent() == external_course_page
assert external_course_page.course_overview == overview_page
assert overview_page.heading == "test heading"
assert overview_page.sub_heading == "<p>paragraph content</p>"

# test that it can be modified
new_heading = "new test heading"
overview_page.heading = new_heading
overview_page.save()

assert overview_page.heading == new_heading

0 comments on commit 03afb18

Please sign in to comment.