def test_custom_detail_page_urls_handled(): """Verify that custom URL paths for our course/program are served by the standard Wagtail view""" readable_id = "some:readable-id" CoursePageFactory.create(course__readable_id=readable_id) resolver_match = resolve("/courses/{}/".format(readable_id)) assert (resolver_match.func.__module__ == "wagtail.core.views") # pylint: disable=protected-access assert resolver_match.func.__name__ == "serve" # pylint: disable=protected-access
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
def test_certificate_for_course_page(): """ The Certificate property should return expected values if associated with a CertificatePage """ course_page = CoursePageFactory.create(certificate_page=None) assert CertificatePage.can_create_at(course_page) assert not SignatoryPage.can_create_at(course_page) certificate_page = CertificatePageFactory.create( parent=course_page, product_name="product_name", CEUs="1.8", signatories__0__signatory__name="Name", signatories__0__signatory__title_1="Title_1", signatories__0__signatory__title_2="Title_2", signatories__0__signatory__organization="Organization", signatories__0__signatory__signature_image__title="Image", ) assert certificate_page.get_parent() == course_page assert certificate_page.CEUs == "1.8" assert certificate_page.product_name == "product_name" for signatory in certificate_page.signatories: # pylint: disable=not-an-iterable assert signatory.value.name == "Name" assert signatory.value.title_1 == "Title_1" assert signatory.value.title_2 == "Title_2" assert signatory.value.organization == "Organization" assert signatory.value.signature_image.title == "Image"
def test_course_page_learning_outcomes(): """ CoursePage related LearningOutcomesPage should return expected values if it exists """ course_page = CoursePageFactory.create() assert course_page.outcomes is None assert LearningOutcomesPage.can_create_at(course_page) learning_outcomes_page = LearningOutcomesPageFactory( parent=course_page, heading="heading", sub_heading="<p>subheading</p>", outcome_items=json.dumps([{ "type": "outcome", "value": "benefit" }]), ) assert learning_outcomes_page.get_parent() == course_page assert learning_outcomes_page.heading == "heading" assert learning_outcomes_page.sub_heading == "<p>subheading</p>" for (block) in learning_outcomes_page.outcome_items: # pylint: disable=not-an-iterable assert block.block_type == "outcome" assert block.value == "benefit" assert course_page.outcomes == learning_outcomes_page assert not LearningOutcomesPage.can_create_at(course_page)
def test_is_course_page(): """Returns True if object is type of CoursePage""" program_page = ProgramPageFactory.create() course_page = CoursePageFactory.create() assert not program_page.is_course_page assert course_page.is_course_page
def test_course_page(): """ page property should return an associated Wagtail page if one exists """ course = CourseFactory.create(page=None) assert course.page is None page = CoursePageFactory.create(course=course) assert course.page == page
def test_course_page_program_page(): """ Verify `program_page` property from the course page returns expected value """ program_page = ProgramPageFactory.create() course_page = CoursePageFactory.create( course__program=program_page.program) assert course_page.program_page == program_page
def test_program_page_course_pages(): """ Verify `course_pages` property from the program page returns expected value """ program_page = ProgramPageFactory.create() assert list(program_page.course_pages) == [] course_page = CoursePageFactory.create( course__program=program_page.program) assert list(program_page.course_pages) == [course_page]
def test_course_page_faq_property(): """ Faqs property should return list of faqs related to given CoursePage""" course_page = CoursePageFactory.create() assert FrequentlyAskedQuestionPage.can_create_at(course_page) faqs_page = FrequentlyAskedQuestionPageFactory.create(parent=course_page) faq = FrequentlyAskedQuestionFactory.create(faqs_page=faqs_page) assert faqs_page.get_parent() is course_page assert list(course_page.faqs) == [faq]
def test_course_page_faculty_subpage(): """ FacultyMembersPage should return expected values if associated with CoursePage """ course_page = CoursePageFactory.create() assert not course_page.faculty FacultyMembersPageFactory.create(parent=course_page, members=json.dumps( _get_faculty_members())) _assert_faculty_members(course_page)
def test_course_certificate_invalid_view(user_client, user, wagtail_basics): """ Test that certificate page returns a 404 if CertificatePage does not exist for that course """ home = HomePageFactory.create(parent=wagtail_basics.root, slug="home") home.save_revision().publish() course_page = CoursePageFactory.create(parent=home, certificate_page=None) course_page.save_revision().publish() course_run_certificate = CourseRunCertificateFactory.create( user=user, course_run__course=course_page.course ) resp = user_client.get(course_run_certificate.link) assert resp.status_code == status.HTTP_404_NOT_FOUND
def test_course_page_propel_career(): """ The propel_career property should return expected values if associated with a CoursePage """ course_page = CoursePageFactory.create() propel_career_page = TextSectionFactory.create( parent=course_page, content="<p>content</p>", dark_theme=True, action_title="Action Title", ) assert course_page.propel_career == propel_career_page assert propel_career_page.action_title == "Action Title" assert propel_career_page.action_url assert propel_career_page.content == "<p>content</p>" assert propel_career_page.dark_theme
def test_basket_thumbnail_courserun(basket_and_coupons, mock_context): """Basket thumbnail should be serialized for a courserun""" thumbnail_filename = "abcde.jpg" course_page = CoursePageFactory.create( thumbnail_image__file__filename=thumbnail_filename ) run = CourseRunFactory.create(course=course_page.course) product_version = ProductVersionFactory.create(product__content_object=run) data = FullProductVersionSerializer( instance=product_version, context=mock_context ).data assert ( data["thumbnail_url"] == course_page.thumbnail_image.get_rendition( CATALOG_COURSE_IMG_WAGTAIL_FILL ).url )
def test_course_page_child_page_url(): """ The live URL of child pages should be of the correct format: <site_root>/courses/<course__readable_id>/<child_page__slug> """ course_page = CoursePageFactory.create(course__readable_id="course:test") child_page = TextSectionFactory.create(parent=course_page) course_page_url = course_page.get_full_url() child_page_url = child_page.get_full_url() if WAGTAIL_APPEND_SLASH: assert child_page_url == "{}{}/".format(course_page_url, child_page.slug) else: assert child_page_url == "{}/{}".format(course_page_url, child_page.slug)
def test_instructors(has_page): """CourseRun.instructors should list instructors from the related CMS page, or provide an empty list""" faculty_names = ["Teacher One", "Teacher Two"] course_run = CourseRunFactory.create(course__page=None) if has_page: course_page = CoursePageFactory.create(course=course_run.course) FacultyMembersPageFactory.create( parent=course_page, **{ f"members__{idx}__member__name": name for idx, name in enumerate(faculty_names) }, ) assert course_run.instructors == ([{ "name": name } for name in faculty_names] if has_page else [])
def test_course_page_for_teams(): """ The ForTeams property should return expected values if associated with a CoursePage """ course_page = CoursePageFactory.create() assert ForTeamsPage.can_create_at(course_page) teams_page = ForTeamsPageFactory.create( parent=course_page, content="<p>content</p>", switch_layout=True, dark_theme=True, action_title="Action Title", ) assert course_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
def test_course_page_learning_techniques(): """ CoursePage related subpages should return expected values if they exist CoursePage related LearningTechniquesPage should return expected values if it exists """ course_page = CoursePageFactory.create() assert LearningTechniquesPage.can_create_at(course_page) learning_techniques_page = LearningTechniquesPageFactory( parent=course_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() == course_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"
def test_course_certificate_view(user_client, user, wagtail_basics): """ Test that certificate page show correctly """ home = HomePageFactory.create(parent=wagtail_basics.root, slug="home") home.save_revision().publish() course_page = CoursePageFactory.create(parent=home) course_page.save_revision().publish() course_run = CourseRunFactory.create(course=course_page.course) course_run_certificate = CourseRunCertificateFactory.create( user=user, course_run=course_run ) resp = user_client.get(course_run_certificate.link) assert resp.status_code == status.HTTP_200_OK assert resp.context_data["page"] == course_page.certificate_page assert resp.context_data["page"].certificate == course_run_certificate
def test_course_page_properties(): """ Wagtail-page-related properties should return expected values """ course_page = CoursePageFactory.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", ) assert course_page.title == "<p>page title</p>" assert course_page.subhead == "subhead" assert course_page.description == "<p>desc</p>" assert course_page.catalog_details == "<p>catalog desc</p>" assert course_page.duration == "1 week" assert course_page.video_title == "<p>title</p>" assert course_page.video_url == "http://test.com/mock.mp4" assert course_page.background_image.title == "background-image"
def test_course_certificate_view_revoked_state(user_client, user, wagtail_basics): """ Test that certificate page return 404 for revoked certificate. """ home = HomePageFactory.create(parent=wagtail_basics.root, slug="home") home.save_revision().publish() course_page = CoursePageFactory.create(parent=home) course_page.save_revision().publish() course_run = CourseRunFactory.create(course=course_page.course) course_run_certificate = CourseRunCertificateFactory.create( user=user, course_run=course_run, is_revoked=False ) resp = user_client.get(course_run_certificate.link) assert resp.status_code == status.HTTP_200_OK course_run_certificate.is_revoked = True course_run_certificate.save() resp = user_client.get(course_run_certificate.link) assert resp.status_code == status.HTTP_404_NOT_FOUND
def test_course_page_testimonials(): """ testimonials property should return expected value if associated with a CoursePage """ course_page = CoursePageFactory.create() assert UserTestimonialsPage.can_create_at(course_page) testimonials_page = UserTestimonialsPageFactory.create( parent=course_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 course_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"