Esempio n. 1
0
 def setUp(self):
     super(TestProgramPage, self).setUp()
     homepage = HomePage.objects.first()
     program = ProgramFactory.create(title="Test Program Title", live=True)
     self.program_page = ProgramPage(program=program, title="Test Program")
     homepage.add_child(instance=self.program_page)
     self.program_page.save_revision().publish()
Esempio n. 2
0
    def test_program_link(self):
        """Verify that program links are present in home page if ProgramPage is set"""
        program = ProgramFactory.create(live=True)
        program_page = ProgramPage(program=program, title="Test Program")
        homepage = HomePage.objects.first()
        homepage.add_child(instance=program_page)
        program_page.save_revision().publish()

        response = self.client.get('/')
        self.assertContains(response, program_page.url, status_code=200)
Esempio n. 3
0
    def test_program_page(self):
        """Verify that ProgramPage is passed in the context if and only if it's available"""
        program_with_page = ProgramFactory.create(live=True)
        program_page = ProgramPage(program=program_with_page, title="Test Program")
        homepage = HomePage.objects.first()
        homepage.add_child(instance=program_page)
        program_page.save_revision().publish()

        program_without_page = ProgramFactory.create(live=True)
        response = self.client.get('/')
        assert response.context['programs'] == [
            (program_with_page, program_page),
            (program_without_page, None),
        ]
Esempio n. 4
0
    def test_program_link(self):
        """Verify that program links are present in home page if ProgramPage is set"""
        program = ProgramFactory.create(live=True)
        program_page = ProgramPage(program=program, title="Test Program")
        homepage = HomePage.objects.first()
        homepage.add_child(instance=program_page)
        program_page.save_revision().publish()

        response = self.client.get('/')
        self.assertContains(
            response,
            program_page.url,
            status_code=200
        )
Esempio n. 5
0
    def test_program_page(self):
        """Verify that ProgramPage is passed in the context if and only if it's available"""
        program_with_page = ProgramFactory.create(live=True)
        program_page = ProgramPage(program=program_with_page,
                                   title="Test Program")
        homepage = HomePage.objects.first()
        homepage.add_child(instance=program_page)
        program_page.save_revision().publish()

        program_without_page = ProgramFactory.create(live=True)
        response = self.client.get('/')
        assert response.context['programs'] == [
            (program_with_page, program_page),
            (program_without_page, None),
        ]
Esempio n. 6
0
 def setUp(self):
     super(TestProgramPage, self).setUp()
     homepage = HomePage.objects.first()
     program = ProgramFactory.create(title="Test Program Title", live=True)
     self.program_page = ProgramPage(program=program, title="Test Program")
     homepage.add_child(instance=self.program_page)
     self.program_page.save_revision().publish()
Esempio n. 7
0
class TestProgramPage(ViewsTests):
    """
    Test that the ProgramPage view work as expected.
    """
    def setUp(self):
        super(TestProgramPage, self).setUp()
        homepage = HomePage.objects.first()
        program = Program(title="Test Program Title", live=True)
        program.save()
        self.program_page = ProgramPage(program=program, title="Test Program")
        homepage.add_child(instance=self.program_page)
        self.program_page.save_revision().publish()

    def test_program_page_context_anonymous(self):
        """
        Assert context values when anonymous
        """
        ga_tracking_id = FuzzyText().fuzz()
        with self.settings(GA_TRACKING_ID=ga_tracking_id, ):
            response = self.client.get(self.program_page.url)
            assert response.context['authenticated'] is False
            assert response.context['username'] is None
            assert response.context['title'] == "Test Program"
            js_settings = json.loads(response.context['js_settings_json'])
            assert js_settings['gaTrackingID'] == ga_tracking_id

    def test_login_button(self):
        """Verify that we see a login button"""
        response = self.client.get(self.program_page.url)
        self.assertContains(response, "Sign Up Now")

    def test_program_thumbnail_default(self):
        """Verify that a default thumbnail shows up for a live program"""
        self.create_and_login_user()

        default_image = 'images/course-thumbnail.png'
        # the default image should not show up if no program is live
        program = self.program_page.program
        program.live = False
        program.save()
        resp = self.client.get('/')
        self.assertNotContains(resp, default_image)

        # default image should show up if a program is live and no thumbnail image was set
        program.live = True
        program.save()
        resp = self.client.get('/')
        self.assertContains(resp, default_image)

    def test_program_thumbnail(self):
        """Verify that a thumbnail shows up if specified for a ProgramPage"""
        self.create_and_login_user()

        image = Image.objects.create(title='Test image',
                                     file=get_test_image_file())

        self.program_page.thumbnail_image = image
        self.program_page.save()

        resp = self.client.get('/')
        self.assertContains(resp, image.get_rendition('fill-345x265').url)
Esempio n. 8
0
class TestProgramPage(ViewsTests):
    """
    Test that the ProgramPage view work as expected.
    """
    def setUp(self):
        super(TestProgramPage, self).setUp()
        homepage = HomePage.objects.first()
        program = ProgramFactory.create(title="Test Program Title", live=True)
        self.program_page = ProgramPage(program=program, title="Test Program")
        homepage.add_child(instance=self.program_page)
        self.program_page.save_revision().publish()

    def test_bundles(self):
        """
        Assert javascript files rendered on program page
        """
        with patch('ui.templatetags.render_bundle._get_bundle') as get_bundle:
            self.client.get(self.program_page.url)

        bundles = [bundle[0][1] for bundle in get_bundle.call_args_list]
        assert set(bundles) == {
            'common',
            'public',
            'sentry_client',
            'style',
            'style_public',
            'zendesk_widget',
        }

    def test_context_anonymous(self):
        """
        Assert context values when anonymous which are different than for the logged in user
        """
        response = self.client.get(self.program_page.url)
        assert response.context['authenticated'] is False
        assert response.context['username'] is None
        assert response.context['is_staff'] is False
        js_settings = json.loads(response.context['js_settings_json'])
        assert js_settings['user'] is None

    @ddt.data(*Role.ASSIGNABLE_ROLES)
    def test_context_has_role(self, role):
        """
        Assert context values when staff or instructor which are different than for regular logged in user
        """
        with mute_signals(post_save):
            profile = ProfileFactory.create()
        Role.objects.create(
            role=role,
            program=self.program_page.program,
            user=profile.user,
        )
        self.client.force_login(profile.user)
        response = self.client.get(self.program_page.url)
        assert response.context['authenticated'] is True
        assert response.context['username'] is None
        assert response.context['is_staff'] is True

    def test_context(self):
        """
        Assert context values for logged in user
        """
        with mute_signals(post_save):
            profile = ProfileFactory.create()
        self.client.force_login(profile.user)

        # ProgramFaculty and ProgramCourse are asserted via ProgramPageSerializer below
        FacultyFactory.create_batch(3, program_page=self.program_page)
        courses = self.program_page.program.course_set.all()
        ProgramCourseFactory.create_batch(len(courses),
                                          program_page=self.program_page,
                                          course=Iterator(courses))

        ga_tracking_id = FuzzyText().fuzz()
        with self.settings(
                GA_TRACKING_ID=ga_tracking_id,
                ENVIRONMENT='environment',
                VERSION='version',
        ):
            response = self.client.get(self.program_page.url)
            assert response.context['authenticated'] is True
            assert response.context['username'] is None
            assert response.context['title'] == self.program_page.title
            assert response.context['is_public'] is True
            assert response.context['has_zendesk_widget'] is True
            assert response.context['is_staff'] is False
            self.assertContains(response, 'Share this page')
            js_settings = json.loads(response.context['js_settings_json'])
            assert js_settings == {
                'gaTrackingID': ga_tracking_id,
                'environment': 'environment',
                'sentry_dsn': None,
                'host': 'testserver',
                'release_version': 'version',
                'user': serialize_maybe_user(profile.user),
                'program': ProgramPageSerializer(self.program_page).data,
            }

    def test_info_links(self):
        """
        If present, info links should be displayed
        """
        info_links = InfoLinksFactory.create_batch(
            3, program_page=self.program_page)
        response = self.client.get(self.program_page.url)
        for info_link in info_links:
            self.assertContains(response, info_link.title_url)

    def test_semester_date(self):
        """
        If present, semester data should be displayed
        """
        semester_dates = SemesterDateFactory.create_batch(
            3, program_page=self.program_page)
        response = self.client.get(self.program_page.url)
        for semester_date in semester_dates:
            self.assertContains(response, semester_date.semester_name)

    def test_login_button(self):
        """Verify that we see a login button"""
        CourseFactory.create(program=self.program_page.program)
        response = self.client.get(self.program_page.url)
        self.assertContains(response, "Sign Up Now")

    def test_program_thumbnail_default(self):
        """Verify that a default thumbnail shows up for a live program"""
        self.create_and_login_user()

        default_image = 'images/course-thumbnail.png'
        # the default image should not show up if no program is live
        program = self.program_page.program
        program.live = False
        program.save()
        resp = self.client.get('/')
        self.assertNotContains(resp, default_image)

        # default image should show up if a program is live and no thumbnail image was set
        program.live = True
        program.save()
        resp = self.client.get('/')
        self.assertContains(resp, default_image)

    def test_program_thumbnail(self):
        """Verify that a thumbnail shows up if specified for a ProgramPage"""
        self.create_and_login_user()

        image = Image.objects.create(title='Test image',
                                     file=get_test_image_file())

        self.program_page.thumbnail_image = image
        self.program_page.save()

        resp = self.client.get('/')
        self.assertContains(resp, image.get_rendition('fill-690x530').url)

    def test_course_listing(self):
        """
        Verify that courses are being serialized to JS in the correct order
        """
        # Create several courses in the program
        courses = [
            CourseFactory.create(
                program=self.program_page.program,
                position_in_program=i,
            ) for i in range(5)
        ]
        # render the page
        response = self.client.get(self.program_page.url)
        js_settings = json.loads(response.context['js_settings_json'])
        # check that the courses are in the response
        self.assertIn("program", js_settings)
        self.assertIn("courses", js_settings["program"])
        self.assertEqual(len(js_settings["program"]["courses"]), 5)
        # check that they're in the correct order
        for course, js_course in zip(courses,
                                     js_settings["program"]["courses"]):
            self.assertEqual(course.title, js_course["title"])
            self.assertEqual(course.description, js_course["description"])
            self.assertEqual(course.url, js_course["url"])

    def test_no_courses(self):
        """
        Verify that no courses result in a different button
        """
        program_subscribe_link = "https://fakeurl.com"
        self.program_page.program_subscribe_link = program_subscribe_link
        self.program_page.save()

        response = self.client.get(self.program_page.url)
        js_settings = json.loads(response.context['js_settings_json'])
        self.assertIn("program", js_settings)
        self.assertIn("courses", js_settings["program"])
        self.assertEqual(len(js_settings["program"]["courses"]), 0)
        self.assertContains(response, "I'm interested")
        self.assertContains(response, program_subscribe_link)
Esempio n. 9
0
class TestProgramPage(ViewsTests):
    """
    Test that the ProgramPage view work as expected.
    """
    def setUp(self):
        super(TestProgramPage, self).setUp()
        homepage = HomePage.objects.first()
        program = ProgramFactory.create(title="Test Program Title", live=True)
        self.program_page = ProgramPage(program=program, title="Test Program")
        homepage.add_child(instance=self.program_page)
        self.program_page.save_revision().publish()

    def test_bundles(self):
        """
        Assert javascript files rendered on program page
        """
        with patch('ui.templatetags.render_bundle._get_bundle') as get_bundle:
            self.client.get(self.program_page.url)

        bundles = [bundle[0][1] for bundle in get_bundle.call_args_list]
        assert set(bundles) == {
            'common',
            'public',
            'sentry_client',
            'style',
            'style_public',
            'zendesk_widget',
        }

    def test_context_anonymous(self):
        """
        Assert context values when anonymous which are different than for the logged in user
        """
        response = self.client.get(self.program_page.url)
        assert response.context['authenticated'] is False
        assert response.context['username'] is None
        assert response.context['is_staff'] is False
        js_settings = json.loads(response.context['js_settings_json'])
        assert js_settings['user'] is None

    @ddt.data(
        *Role.ASSIGNABLE_ROLES
    )
    def test_context_has_role(self, role):
        """
        Assert context values when staff or instructor which are different than for regular logged in user
        """
        with mute_signals(post_save):
            profile = ProfileFactory.create()
        Role.objects.create(
            role=role,
            program=self.program_page.program,
            user=profile.user,
        )
        self.client.force_login(profile.user)
        response = self.client.get(self.program_page.url)
        assert response.context['authenticated'] is True
        assert response.context['username'] is None
        assert response.context['is_staff'] is True

    def test_context(self):
        """
        Assert context values for logged in user
        """
        with mute_signals(post_save):
            profile = ProfileFactory.create()
        self.client.force_login(profile.user)

        # ProgramFaculty and ProgramCourse are asserted via ProgramPageSerializer below
        FacultyFactory.create_batch(3, program_page=self.program_page)
        courses = self.program_page.program.course_set.all()
        ProgramCourseFactory.create_batch(
            len(courses), program_page=self.program_page, course=Iterator(courses)
        )

        ga_tracking_id = FuzzyText().fuzz()
        with self.settings(
            GA_TRACKING_ID=ga_tracking_id,
            ENVIRONMENT='environment',
            VERSION='version',
        ):
            response = self.client.get(self.program_page.url)
            assert response.context['authenticated'] is True
            assert response.context['username'] is None
            assert response.context['title'] == self.program_page.title
            assert response.context['is_public'] is True
            assert response.context['has_zendesk_widget'] is True
            assert response.context['is_staff'] is False
            self.assertContains(response, 'Share this page')
            js_settings = json.loads(response.context['js_settings_json'])
            assert js_settings == {
                'gaTrackingID': ga_tracking_id,
                'environment': 'environment',
                'sentry_dsn': None,
                'host': 'testserver',
                'release_version': 'version',
                'user': serialize_maybe_user(profile.user),
                'program': ProgramPageSerializer(self.program_page).data,
            }

    def test_info_links(self):
        """
        If present, info links should be displayed
        """
        info_links = InfoLinksFactory.create_batch(3, program_page=self.program_page)
        response = self.client.get(self.program_page.url)
        for info_link in info_links:
            self.assertContains(response, info_link.title_url)

    def test_semester_date(self):
        """
        If present, semester data should be displayed
        """
        semester_dates = SemesterDateFactory.create_batch(3, program_page=self.program_page)
        response = self.client.get(self.program_page.url)
        for semester_date in semester_dates:
            self.assertContains(response, semester_date.semester_name)

    def test_login_button(self):
        """Verify that we see a login button"""
        CourseFactory.create(program=self.program_page.program)
        response = self.client.get(self.program_page.url)
        self.assertContains(response, "Sign Up Now")

    def test_program_thumbnail_default(self):
        """Verify that a default thumbnail shows up for a live program"""
        self.create_and_login_user()

        default_image = 'images/course-thumbnail.png'
        # the default image should not show up if no program is live
        program = self.program_page.program
        program.live = False
        program.save()
        resp = self.client.get('/')
        self.assertNotContains(resp, default_image)

        # default image should show up if a program is live and no thumbnail image was set
        program.live = True
        program.save()
        resp = self.client.get('/')
        self.assertContains(resp, default_image)

    def test_program_thumbnail(self):
        """Verify that a thumbnail shows up if specified for a ProgramPage"""
        self.create_and_login_user()

        image = Image.objects.create(title='Test image',
                                     file=get_test_image_file())

        self.program_page.thumbnail_image = image
        self.program_page.save()

        resp = self.client.get('/')
        self.assertContains(resp, image.get_rendition('fill-690x530').url)

    def test_course_listing(self):
        """
        Verify that courses are being serialized to JS in the correct order
        """
        # Create several courses in the program
        courses = [
            CourseFactory.create(
                program=self.program_page.program,
                position_in_program=i,
            )
            for i in range(5)
        ]
        # render the page
        response = self.client.get(self.program_page.url)
        js_settings = json.loads(response.context['js_settings_json'])
        # check that the courses are in the response
        self.assertIn("program", js_settings)
        self.assertIn("courses", js_settings["program"])
        self.assertEqual(len(js_settings["program"]["courses"]), 5)
        # check that they're in the correct order
        for course, js_course in zip(courses, js_settings["program"]["courses"]):
            self.assertEqual(course.title, js_course["title"])
            self.assertEqual(course.description, js_course["description"])
            self.assertEqual(course.url, js_course["url"])

    def test_no_courses(self):
        """
        Verify that no courses result in a different button
        """
        program_subscribe_link = "https://fakeurl.com"
        self.program_page.program_subscribe_link = program_subscribe_link
        self.program_page.save()

        response = self.client.get(self.program_page.url)
        js_settings = json.loads(response.context['js_settings_json'])
        self.assertIn("program", js_settings)
        self.assertIn("courses", js_settings["program"])
        self.assertEqual(len(js_settings["program"]["courses"]), 0)
        self.assertContains(response, "I'm interested")
        self.assertContains(response, program_subscribe_link)