Example #1
0
def test_featured_product():
    """Verify that there will be only one product marked as feature."""
    program_page = ProgramPageFactory.create(featured=True)
    another_program_page = ProgramPageFactory.create(featured=True)

    program_page.refresh_from_db()
    assert not program_page.featured
    assert another_program_page.featured

    # add and mark course as featured
    course_page = CoursePageFactory.create(featured=True)
    another_program_page.refresh_from_db()
    assert not another_program_page.featured
    assert course_page.featured

    another_course_page = CoursePageFactory.create(featured=True)
    course_page.refresh_from_db()
    assert not course_page.featured
    assert another_course_page.featured

    external_course_page = ExternalCoursePageFactory.create(featured=True)
    another_course_page.refresh_from_db()
    assert not another_course_page.featured
    assert external_course_page.featured

    external_program_page = ExternalProgramPageFactory.create(featured=True)
    external_course_page.refresh_from_db()
    assert not external_course_page.featured
    assert external_program_page.featured
Example #2
0
def test_custom_detail_page_urls():
    """Verify that course/external-course/program detail pages return our custom URL path"""
    readable_id = "some:readable-id"
    external_readable_id = "some:external-readable-id"
    program_pages = ProgramPageFactory.create_batch(
        2,
        program__readable_id=factory.Iterator([readable_id,
                                               "non-matching-id"]))
    external_program_pages = ExternalProgramPageFactory.create_batch(
        2,
        readable_id=factory.Iterator([readable_id,
                                      "non-matching-external-id"]))
    course_pages = CoursePageFactory.create_batch(
        2,
        course__readable_id=factory.Iterator([readable_id, "non-matching-id"]))
    external_course_pages = ExternalCoursePageFactory.create_batch(
        2,
        readable_id=factory.Iterator(
            [external_readable_id, "non-matching-external-id"]),
    )
    assert program_pages[0].get_url() == "/programs/{}/".format(readable_id)
    assert external_program_pages[0].get_url() == "/programs/{}/".format(
        readable_id)
    assert course_pages[0].get_url() == "/courses/{}/".format(readable_id)
    assert external_course_pages[0].get_url() == "/courses/{}/".format(
        external_readable_id)
Example #3
0
def test_external_program_page_faq_property():
    """ Faqs property should return list of faqs related to given ExternalProgramPage"""
    external_program_page = ExternalProgramPageFactory.create()
    assert FrequentlyAskedQuestionPage.can_create_at(external_program_page)

    faqs_page = FrequentlyAskedQuestionPageFactory.create(
        parent=external_program_page)
    faq = FrequentlyAskedQuestionFactory.create(faqs_page=faqs_page)

    assert faqs_page.get_parent() is external_program_page
    assert list(external_program_page.faqs) == [faq]
Example #4
0
def test_external_program_page_faculty_subpage():
    """
    FacultyMembersPage should return expected values if associated with ExternalProgramPage
    """
    external_program_page = ExternalProgramPageFactory.create()

    assert not external_program_page.faculty
    FacultyMembersPageFactory.create(parent=external_program_page,
                                     members=json.dumps(
                                         _get_faculty_members()))
    _assert_faculty_members(external_program_page)
Example #5
0
def test_external_program_page_propel_career():
    """
    The propel_career property should return expected values if associated with a ExternalProgramPage
    """
    external_program_page = ExternalProgramPageFactory.create()
    propel_career_page = TextSectionFactory.create(
        parent=external_program_page,
        content="<p>content</p>",
        dark_theme=True,
        action_title="Action Title",
    )
    assert external_program_page.propel_career == propel_career_page
    assert propel_career_page.action_title == "Action Title"
    assert propel_career_page.content == "<p>content</p>"
    assert propel_career_page.dark_theme
Example #6
0
def test_external_program_page_for_teams():
    """
    The ForTeams property should return expected values if associated with an ExternalProgramPage
    """
    external_program_page = ExternalProgramPageFactory.create()
    assert ForTeamsPage.can_create_at(external_program_page)
    teams_page = ForTeamsPageFactory.create(
        parent=external_program_page,
        content="<p>content</p>",
        switch_layout=True,
        dark_theme=True,
        action_title="Action Title",
    )
    assert external_program_page.for_teams == teams_page
    assert teams_page.action_title == "Action Title"
    assert teams_page.content == "<p>content</p>"
    assert teams_page.switch_layout
    assert teams_page.dark_theme
Example #7
0
def test_external_program_page_learning_techniques():
    """
    ExternalProgramPage related subpages should return expected values if they exist
    ExternalProgramPage related LearningTechniquesPage should return expected values if it exists
    """
    external_program_page = ExternalProgramPageFactory.create(
        description="<p>desc</p>", duration="1 week")

    assert LearningTechniquesPage.can_create_at(external_program_page)
    learning_techniques_page = LearningTechniquesPageFactory(
        parent=external_program_page,
        technique_items__0__techniques__heading="heading",
        technique_items__0__techniques__sub_heading="sub_heading",
        technique_items__0__techniques__image__title="image-title",
    )
    assert learning_techniques_page.get_parent() == external_program_page
    for (technique) in learning_techniques_page.technique_items:  # pylint: disable=not-an-iterable
        assert technique.value.get("heading") == "heading"
        assert technique.value.get("sub_heading") == "sub_heading"
        assert technique.value.get("image").title == "image-title"
Example #8
0
def test_external_program_page_properties():
    """
    Wagtail-page-related properties for ExternalProgramPage should return expected values
    """
    external_program_page = ExternalProgramPageFactory.create(
        title="<p>page title</p>",
        subhead="subhead",
        description="<p>desc</p>",
        catalog_details="<p>catalog desc</p>",
        duration="1 week",
        video_title="<p>title</p>",
        video_url="http://test.com/mock.mp4",
        background_image__title="background-image",
    )

    # Saving an External Program should fail with ValidationError if course count is negative
    external_program_page.course_count = -1
    with pytest.raises(ValidationError):
        external_program_page.save()
    external_program_page.course_count = 2
    external_program_page.save()

    # Saving an External Program should fail with ValidationError if price is negative
    external_program_page.price = -1.0
    with pytest.raises(ValidationError):
        external_program_page.save()
    external_program_page.price = 1.0
    external_program_page.save()

    assert external_program_page.title == "<p>page title</p>"
    assert external_program_page.subhead == "subhead"
    assert external_program_page.description == "<p>desc</p>"
    assert external_program_page.catalog_details == "<p>catalog desc</p>"
    assert external_program_page.duration == "1 week"
    assert external_program_page.video_title == "<p>title</p>"
    assert external_program_page.video_url == "http://test.com/mock.mp4"
    assert external_program_page.background_image.title == "background-image"
    assert external_program_page.course_count == 2
Example #9
0
def test_external_program_page_testimonials():
    """
    testimonials property should return expected value if associated with an ExternalProgramPage
    """
    external_program_page = ExternalProgramPageFactory.create()
    assert UserTestimonialsPage.can_create_at(external_program_page)
    testimonials_page = UserTestimonialsPageFactory.create(
        parent=external_program_page,
        heading="heading",
        subhead="subhead",
        items__0__testimonial__name="name",
        items__0__testimonial__title="title",
        items__0__testimonial__image__title="image",
        items__0__testimonial__quote="quote",
    )
    assert external_program_page.testimonials == testimonials_page
    assert testimonials_page.heading == "heading"
    assert testimonials_page.subhead == "subhead"
    for testimonial in testimonials_page.items:  # pylint: disable=not-an-iterable
        assert testimonial.value.get("name") == "name"
        assert testimonial.value.get("title") == "title"
        assert testimonial.value.get("image").title == "image"
        assert testimonial.value.get("quote") == "quote"
Example #10
0
def test_external_program_page_who_should_enroll():
    """
    ExternalProgramPage related WhoShouldEnrollPage should return expected values if it exists
    """
    external_program_page = ExternalProgramPageFactory.create()

    assert WhoShouldEnrollPage.can_create_at(external_program_page)
    who_should_enroll_page = WhoShouldEnrollPageFactory.create(
        parent=external_program_page,
        content=json.dumps([
            {
                "type": "item",
                "value": "<p>item</p>"
            },
            {
                "type": "item",
                "value": "<p>item</p>"
            },
        ]),
    )
    assert who_should_enroll_page.get_parent() == external_program_page
    assert len(who_should_enroll_page.content) == 2
    for block in who_should_enroll_page.content:  # pylint: disable=not-an-iterable
        assert block.block_type == "item"
        assert block.value.source == "<p>item</p>"
    assert external_program_page.who_should_enroll == who_should_enroll_page
    assert not WhoShouldEnrollPage.can_create_at(external_program_page)

    # default page hedding
    assert who_should_enroll_page.heading == "Who Should Enroll"

    # test that it can be modified
    new_heading = "New heading of the page"
    who_should_enroll_page.heading = new_heading
    who_should_enroll_page.save()

    assert who_should_enroll_page.heading == new_heading
Example #11
0
def test_external_program_learning_outcomes():
    """
    ExternalProgramPage related LearningOutcomesPage should return expected values if it exists
    """
    external_program_page = ExternalProgramPageFactory.create()

    assert LearningOutcomesPage.can_create_at(external_program_page)

    learning_outcomes_page = LearningOutcomesPageFactory(
        parent=external_program_page,
        heading="heading",
        sub_heading="subheading",
        outcome_items=json.dumps([{
            "type": "outcome",
            "value": "benefit"
        }]),
    )
    assert learning_outcomes_page.get_parent() == external_program_page
    assert learning_outcomes_page.heading == "heading"
    for (block) in learning_outcomes_page.outcome_items:  # pylint: disable=not-an-iterable
        assert block.block_type == "outcome"
        assert block.value == "benefit"
    assert external_program_page.outcomes == learning_outcomes_page
    assert not LearningOutcomesPage.can_create_at(external_program_page)
Example #12
0
def test_is_external_program_page():
    """Returns True if object is type of ExternalProgramPage"""
    external_program_page = ExternalProgramPageFactory.create()
    assert external_program_page.is_external_program_page
Example #13
0
def test_filter_and_sort_catalog_pages():  # pylint:disable=too-many-locals
    """
    Test that filter_and_sort_catalog_pages removes program/course/external course pages that do not have a future start date
    or enrollment end date, and returns appropriately sorted lists of pages
    """
    now = now_in_utc()

    earlier_external_course_page = ExternalCoursePageFactory.create(
        start_date=now)
    earlier_external_program_page = ExternalProgramPageFactory.create(
        start_date=now, course_count=2)
    non_program_run = CourseRunFactory.create(course__no_program=True,
                                              start_date=(now +
                                                          timedelta(days=1)))
    first_program_run = CourseRunFactory.create(start_date=(now +
                                                            timedelta(days=2)))
    second_program_run = CourseRunFactory.create(
        start_date=(now + timedelta(days=3)))
    later_external_course_page = ExternalCoursePageFactory.create(
        start_date=now + timedelta(days=4))

    later_external_program_page = ExternalProgramPageFactory.create(
        start_date=now + timedelta(days=4))
    # Create course run with past start_date and future enrollment_end, which should appear in the catalog
    future_enrollment_end_run = CourseRunFactory.create(
        past_start=True,
        enrollment_end=(now + timedelta(days=1)),
        course__no_program=True,
    )
    # Create course run with past start_date and enrollment_end, which should NOT appear in the catalog
    past_run = CourseRunFactory.create(past_start=True,
                                       past_enrollment_end=True,
                                       course__no_program=True)
    all_runs = [
        past_run,
        future_enrollment_end_run,
        second_program_run,
        first_program_run,
        non_program_run,
    ]

    external_course_pages = [
        earlier_external_course_page, later_external_course_page
    ]

    external_program_pages = [
        earlier_external_program_page,
        later_external_program_page,
    ]

    initial_course_pages = [run.course.page for run in all_runs]
    initial_program_pages = [
        run.course.program.page
        for run in [second_program_run, first_program_run]
    ]

    all_pages, program_pages, course_pages = filter_and_sort_catalog_pages(
        initial_program_pages,
        initial_course_pages,
        external_course_pages,
        external_program_pages,
    )

    # Combined pages and course pages should not include the past course run
    assert len(all_pages) == (len(initial_program_pages) +
                              len(initial_course_pages) +
                              len(external_course_pages) +
                              len(external_program_pages) - 1)
    assert len(course_pages) == (len(initial_course_pages) +
                                 len(external_course_pages) - 1)

    assert len(program_pages) == (len(initial_program_pages) +
                                  len(external_program_pages))

    # Filtered out external course page because it does not have a `course` attribute
    assert past_run.course not in (None if page.is_external_course_page else
                                   page.course for page in course_pages)

    # Pages should be sorted by next run date
    assert [
        page if page.is_external_program_page else page.program
        for page in program_pages
    ] == [
        earlier_external_program_page,
        first_program_run.course.program,
        second_program_run.course.program,
        later_external_program_page,
    ]
    expected_course_run_sort = [
        future_enrollment_end_run,
        earlier_external_course_page,
        non_program_run,
        first_program_run,
        second_program_run,
        later_external_course_page,
    ]

    # The sort should also include external course pages as expected
    assert [
        page if page.is_external_course_page else page.course
        for page in course_pages
    ] == [
        run if isinstance(run, ExternalCoursePage) else run.course
        for run in expected_course_run_sort
    ]