Esempio n. 1
0
    def test_single_completed_course(self):
        """Tests when a single completed course is present."""
        email = '*****@*****.**'
        name = 'Test Assessments'

        # Register.
        actions.login(email)
        actions.register(self, name)

        response = self.get('/explorer')
        # Before a course is not completed,
        # explorer page should not show 'view score' button.
        assert_does_not_contain('View score', response.body)

        # Assign a grade to the course enrolled to mark it complete.
        profile = PersonalProfile.get_by_key_name(email)
        info = {'final_grade': 'A'}
        course_info_dict = {'': info}
        profile.course_info = transforms.dumps(course_info_dict)
        profile.put()

        # Check if 'View score' text is visible on profile page.
        response = self.get('/explorer/profile')
        assert_contains('View score', response.body)

        # Check if 'Go to course' button is not visible on explorer page.
        response = self.get('/explorer')
        assert_does_not_contain('Go to course', response.body)

        # Check if 'View score' button is visible on explorer page.
        response = self.get('/explorer')
        assert_contains('View score', response.body)
Esempio n. 2
0
    def test_single_completed_course(self):
        """Tests when a single completed course is present."""
        user = self.make_test_user('*****@*****.**')
        name = 'Test Assessments'

        # Register.
        actions.login(user.email())
        actions.register(self, name)

        response = self.get('/explorer')
        # Before a course is not completed,
        # explorer page should not show 'view score' button.
        assert_does_not_contain('View score', response.body)

        # Assign a grade to the course enrolled to mark it complete.
        profile = PersonalProfile.get_by_key_name(user.user_id())
        info = {'final_grade': 'A'}
        course_info_dict = {'': info}
        profile.course_info = transforms.dumps(course_info_dict)
        profile.put()

        # Check if 'View score' text is visible on profile page.
        response = self.get('/explorer/profile')
        assert_contains('View score', response.body)

        # Check if 'Go to course' button is not visible on explorer page.
        response = self.get('/explorer')
        assert_does_not_contain('Go to course', response.body)

        # Check if 'View score' button is visible on explorer page.
        response = self.get('/explorer')
        assert_contains('View score', response.body)
Esempio n. 3
0
    def test_manage_announcements(self):
        """Test course author can manage announcements."""
        email = '*****@*****.**'
        name = 'Test Announcements'

        actions.login(email, True)
        actions.register(self, name)

        # add new
        response = actions.view_announcements(self)
        add_form = response.forms['gcb-add-announcement']
        response = self.submit(add_form)
        assert_equals(response.status_int, 302)

        # check added
        response = actions.view_announcements(self)
        assert_contains('Sample Announcement (Draft)', response.body)

        # delete draft
        response = actions.view_announcements(self)
        delete_form = response.forms['gcb-delete-announcement-1']
        response = self.submit(delete_form)
        assert_equals(response.status_int, 302)

        # check deleted
        assert_does_not_contain('Welcome to the final class!', response.body)
Esempio n. 4
0
    def test_manage_announcements(self):
        """Test course author can manage announcements."""
        email = '*****@*****.**'
        name = 'Test Announcements'

        actions.login(email, True)
        actions.register(self, name)

        # add new
        response = actions.view_announcements(self)
        add_form = response.forms['gcb-add-announcement']
        response = self.submit(add_form)
        assert_equals(response.status_int, 302)

        # check added
        response = actions.view_announcements(self)
        assert_contains('Sample Announcement (Draft)', response.body)

        # delete draft
        response = actions.view_announcements(self)
        delete_form = response.forms['gcb-delete-announcement-1']
        response = self.submit(delete_form)
        assert_equals(response.status_int, 302)

        # check deleted
        assert_does_not_contain('Welcome to the final class!', response.body)
    def test_not_enough_assignments_to_allocate(self):
        """Test for the case when there are too few assignments in the pool."""

        email = "*****@*****.**"
        name = "Student 1"
        submission = transforms.dumps(
            [
                {"index": 0, "type": "regex", "value": "S1-1", "correct": True},
                {"index": 1, "type": "choices", "value": 3, "correct": False},
                {"index": 2, "type": "regex", "value": "is-S1", "correct": True},
            ]
        )
        payload = {"answers": submission, "assessment_type": LEGACY_REVIEW_UNIT_ID}

        actions.login(email)
        actions.register(self, name)
        response = actions.submit_assessment(self, LEGACY_REVIEW_UNIT_ID, payload)

        # The student goes to the review dashboard and requests an assignment
        # to review -- but there is nothing to review.
        response = actions.request_new_review(self, LEGACY_REVIEW_UNIT_ID, expected_status_code=200)
        assert_does_not_contain("Assignment to review", response.body)
        assert_contains("Sorry, there are no new submissions ", response.body)
        assert_contains('disabled="true"', response.body)

        actions.logout()
    def test_not_enough_assignments_to_allocate(self):
        """Test for the case when there are too few assignments in the pool."""

        email = '*****@*****.**'
        name = 'Student 1'
        submission = transforms.dumps([
            {'index': 0, 'type': 'regex', 'value': 'S1-1', 'correct': True},
            {'index': 1, 'type': 'choices', 'value': 3, 'correct': False},
            {'index': 2, 'type': 'regex', 'value': 'is-S1', 'correct': True},
        ])
        payload = {
            'answers': submission, 'assessment_type': LEGACY_REVIEW_UNIT_ID}

        actions.login(email)
        actions.register(self, name)
        response = actions.submit_assessment(
            self, LEGACY_REVIEW_UNIT_ID, payload)

        # The student goes to the review dashboard and requests an assignment
        # to review -- but there is nothing to review.
        response = actions.request_new_review(
            self, LEGACY_REVIEW_UNIT_ID, expected_status_code=200)
        assert_does_not_contain('Assignment to review', response.body)
        assert_contains('Sorry, there are no new submissions ', response.body)
        assert_contains('disabled="true"', response.body)

        actions.logout()
    def test_not_enough_assignments_to_allocate(self):
        """Test for the case when there are too few assignments in the pool."""

        email = '*****@*****.**'
        name = 'Student 1'
        submission = transforms.dumps([
            {'index': 0, 'type': 'regex', 'value': 'S1-1', 'correct': True},
            {'index': 1, 'type': 'choices', 'value': 3, 'correct': False},
            {'index': 2, 'type': 'regex', 'value': 'is-S1', 'correct': True},
        ])
        payload = {
            'answers': submission, 'assessment_type': LEGACY_REVIEW_UNIT_ID}

        actions.login(email)
        actions.register(self, name)
        response = actions.submit_assessment(
            self, LEGACY_REVIEW_UNIT_ID, payload)

        # The student goes to the review dashboard and requests an assignment
        # to review -- but there is nothing to review.
        response = actions.request_new_review(
            self, LEGACY_REVIEW_UNIT_ID, expected_status_code=200)
        assert_does_not_contain('Assignment to review', response.body)
        assert_contains('Sorry, there are no new submissions ', response.body)
        assert_contains('disabled="true"', response.body)

        actions.logout()
    def test_student_progress_stats_analytics_displays_on_dashboard(self):
        """Test analytics page on course dashboard."""

        with actions.OverriddenEnvironment(
            {'course': {
                analytics.CAN_RECORD_STUDENT_EVENTS: 'true'
            }}):

            student1 = '*****@*****.**'
            name1 = 'Test Student 1'
            student2 = '*****@*****.**'
            name2 = 'Test Student 2'

            # Student 1 completes a unit.
            actions.login(student1)
            actions.register(self, name1)
            actions.view_unit(self)
            actions.logout()

            # Student 2 completes a unit.
            actions.login(student2)
            actions.register(self, name2)
            actions.view_unit(self)
            actions.logout()

            # Admin logs back in and checks if progress exists.
            email = '*****@*****.**'
            actions.login(email, is_admin=True)
            response = self.get('dashboard?action=analytics_students')
            assert_contains('Google > Dashboard > Manage > Students',
                            response.body)
            assert_contains('have not been calculated yet', response.body)

            response = response.forms['gcb-generate-analytics-data'].submit(
            ).follow()
            assert len(self.taskq.GetTasks('default')) == (
                ProgressAnalyticsTest.EXPECTED_TASK_COUNT)

            response = self.get('dashboard?action=analytics_students')
            assert_contains('is running', response.body)

            self.execute_all_deferred_tasks()

            response = self.get('dashboard?action=analytics_students')
            assert_contains('were last updated at', response.body)
            assert_contains('currently enrolled: 2', response.body)
            assert_contains('total: 2', response.body)

            assert_contains('Student Progress', response.body)
            assert_does_not_contain(
                'No student progress has been recorded for this course.',
                response.body)
            # JSON code for the completion statistics.
            assert_contains(
                '\\"u.1.l.1\\": {\\"progress\\": 0, \\"completed\\": 2}',
                response.body)
            assert_contains(
                '\\"u.1\\": {\\"progress\\": 2, \\"completed\\": 0}',
                response.body)
    def test_student_progress_stats_analytics_displays_on_dashboard(self):
        """Test analytics page on course dashboard."""

        with actions.OverriddenEnvironment(
            {'course': {analytics.CAN_RECORD_STUDENT_EVENTS: 'true'}}):

            student1 = '*****@*****.**'
            name1 = 'Test Student 1'
            student2 = '*****@*****.**'
            name2 = 'Test Student 2'

            # Student 1 completes a unit.
            actions.login(student1)
            actions.register(self, name1)
            actions.view_unit(self)
            actions.logout()

            # Student 2 completes a unit.
            actions.login(student2)
            actions.register(self, name2)
            actions.view_unit(self)
            actions.logout()

            # Admin logs back in and checks if progress exists.
            email = '*****@*****.**'
            actions.login(email, is_admin=True)
            response = self.get('dashboard?action=analytics_students')
            assert_contains(
                'Google > Dashboard > Manage > Students',
                response.body)
            assert_contains('have not been calculated yet', response.body)

            response = response.forms[
                'gcb-generate-analytics-data'].submit().follow()
            assert len(self.taskq.GetTasks('default')) == (
                ProgressAnalyticsTest.EXPECTED_TASK_COUNT)

            response = self.get('dashboard?action=analytics_students')
            assert_contains('is running', response.body)

            self.execute_all_deferred_tasks()

            response = self.get('dashboard?action=analytics_students')
            assert_contains('were last updated at', response.body)
            assert_contains('currently enrolled: 2', response.body)
            assert_contains('total: 2', response.body)

            assert_contains('Student Progress', response.body)
            assert_does_not_contain(
                'No student progress has been recorded for this course.',
                response.body)
            # JSON code for the completion statistics.
            assert_contains(
                '\\"u.1.l.1\\": {\\"progress\\": 0, \\"completed\\": 2}',
                response.body)
            assert_contains(
                '\\"u.1\\": {\\"progress\\": 2, \\"completed\\": 0}',
                response.body)
Esempio n. 10
0
    def test_student_progress_stats_analytics_displays_on_dashboard(self):
        """Test analytics page on course dashboard."""

        self.enable_progress_tracking()

        student1 = '*****@*****.**'
        name1 = 'Test Student 1'
        student2 = '*****@*****.**'
        name2 = 'Test Student 2'

        # Student 1 completes a unit.
        actions.login(student1)
        actions.register(self, name1)
        actions.view_unit(self)
        actions.logout()

        # Student 2 completes a unit.
        actions.login(student2)
        actions.register(self, name2)
        actions.view_unit(self)
        actions.logout()

        # Admin logs back in and checks if progress exists.
        email = '*****@*****.**'
        actions.login(email, is_admin=True)
        response = self.get('dashboard?action=analytics')
        assert_contains(
            'Google &gt;<a href="%s"> Dashboard </a>&gt; Analytics' %
                self.canonicalize('dashboard'),
            response.body)
        assert_contains('have not been calculated yet', response.body)

        compute_form = response.forms['gcb-compute-student-stats']
        response = self.submit(compute_form)
        assert_equals(response.status_int, 302)
        assert len(self.taskq.GetTasks('default')) == 5

        response = self.get('dashboard?action=analytics')
        assert_contains('is running', response.body)

        self.execute_all_deferred_tasks()

        response = self.get('dashboard?action=analytics')
        assert_contains('were last updated at', response.body)
        assert_contains('currently enrolled: 2', response.body)
        assert_contains('total: 2', response.body)

        assert_contains('Student Progress Statistics', response.body)
        assert_does_not_contain(
            'No student progress has been recorded for this course.',
            response.body)
        # JSON code for the completion statistics.
        assert_contains(
            '\\"u.1.l.1\\": {\\"progress\\": 0, \\"completed\\": 2}',
            response.body)
        assert_contains(
            '\\"u.1\\": {\\"progress\\": 2, \\"completed\\": 0}',
            response.body)
Esempio n. 11
0
    def test_student_progress_stats_analytics_displays_on_dashboard(self):
        """Test analytics page on course dashboard."""

        self.enable_progress_tracking()

        student1 = '*****@*****.**'
        name1 = 'Test Student 1'
        student2 = '*****@*****.**'
        name2 = 'Test Student 2'

        # Student 1 completes a unit.
        actions.login(student1)
        actions.register(self, name1)
        actions.view_unit(self)
        actions.logout()

        # Student 2 completes a unit.
        actions.login(student2)
        actions.register(self, name2)
        actions.view_unit(self)
        actions.logout()

        # Admin logs back in and checks if progress exists.
        email = '*****@*****.**'
        actions.login(email, is_admin=True)
        response = self.get('dashboard?action=analytics')
        assert_contains(
            'Google &gt; Dashboard &gt; Analytics', response.body)
        assert_contains('have not been calculated yet', response.body)

        compute_form = response.forms['gcb-compute-student-stats']
        response = self.submit(compute_form)
        assert_equals(response.status_int, 302)
        assert len(self.taskq.GetTasks('default')) == 4

        response = self.get('dashboard?action=analytics')
        assert_contains('is running', response.body)

        self.execute_all_deferred_tasks()

        response = self.get('dashboard?action=analytics')
        assert_contains('were last updated at', response.body)
        assert_contains('currently enrolled: 2', response.body)
        assert_contains('total: 2', response.body)

        assert_contains('Student Progress Statistics', response.body)
        assert_does_not_contain(
            'No student progress has been recorded for this course.',
            response.body)
        # JSON code for the completion statistics.
        assert_contains(
            '\\"u.1.l.1\\": {\\"progress\\": 0, \\"completed\\": 2}',
            response.body)
        assert_contains(
            '\\"u.1\\": {\\"progress\\": 2, \\"completed\\": 0}',
            response.body)
Esempio n. 12
0
    def test_announcements_rest(self):
        """Test REST access to announcements."""
        email = '*****@*****.**'
        name = 'Test Announcements Rest'

        actions.login(email, True)
        actions.register(self, name)

        response = actions.view_announcements(self)
        assert_does_not_contain('My Test Title', response.body)

        # REST GET existing item
        items = AnnouncementEntity.all().fetch(1)
        for item in items:
            response = self.get('rest/announcements/item?key=%s' % item.key())
            json_dict = json.loads(response.body)
            assert json_dict['status'] == 200
            assert 'message' in json_dict
            assert 'payload' in json_dict

            payload_dict = json.loads(json_dict['payload'])
            assert 'title' in payload_dict
            assert 'date' in payload_dict

            # REST PUT item
            payload_dict['title'] = u'My Test Title Мой заголовок теста'
            payload_dict['date'] = '2012/12/31'
            payload_dict['is_draft'] = True
            request = {}
            request['key'] = str(item.key())
            request['payload'] = json.dumps(payload_dict)

            # Check XSRF is required.
            response = self.put('rest/announcements/item?%s' % urllib.urlencode(
                {'request': json.dumps(request)}), {})
            assert_equals(response.status_int, 200)
            assert_contains('"status": 403', response.body)

            # Check PUT works.
            request['xsrf_token'] = json_dict['xsrf_token']
            response = self.put('rest/announcements/item?%s' % urllib.urlencode(
                {'request': json.dumps(request)}), {})
            assert_equals(response.status_int, 200)
            assert_contains('"status": 200', response.body)

            # Confirm change is visible on the page.
            response = self.get('announcements')
            assert_contains(
                u'My Test Title Мой заголовок теста (Draft)', response.body)

        # REST GET not-existing item
        response = self.get('rest/announcements/item?key=not_existent_key')
        json_dict = json.loads(response.body)
        assert json_dict['status'] == 404
Esempio n. 13
0
    def test_trigger_sample_announcements(self):
        """Test course author can trigger adding sample announcements."""
        email = '*****@*****.**'
        name = 'Test Announcements'

        actions.login(email, True)
        actions.register(self, name)

        response = actions.view_announcements(self)
        assert_contains('Example Announcement', response.body)
        assert_contains('Welcome to the final class!', response.body)
        assert_does_not_contain('No announcements yet.', response.body)
Esempio n. 14
0
    def test_trigger_sample_announcements(self):
        """Test course author can trigger adding sample announcements."""
        email = '*****@*****.**'
        name = 'Test Announcements'

        actions.login(email, True)
        actions.register(self, name)

        response = actions.view_announcements(self)
        assert_contains('Example Announcement', response.body)
        assert_contains('Welcome to the final class!', response.body)
        assert_does_not_contain('No announcements yet.', response.body)
    def test_add_reviewer(self):
        """Test that admin can add a reviewer, and cannot re-add reviewers."""

        email = '*****@*****.**'
        name = 'Test Add Reviewer'
        submission = transforms.dumps([
            {'index': 0, 'type': 'regex', 'value': 'First answer to Q1',
             'correct': True},
            {'index': 1, 'type': 'choices', 'value': 3, 'correct': False},
            {'index': 2, 'type': 'regex', 'value': 'First answer to Q3',
             'correct': True},
        ])
        payload = {
            'answers': submission, 'assessment_type': LEGACY_REVIEW_UNIT_ID}

        actions.login(email)
        actions.register(self, name)
        response = actions.submit_assessment(
            self, LEGACY_REVIEW_UNIT_ID, payload)

        # There is nothing to review on the review dashboard.
        response = actions.request_new_review(
            self, LEGACY_REVIEW_UNIT_ID, expected_status_code=200)
        assert_does_not_contain('Assignment to review', response.body)
        assert_contains('Sorry, there are no new submissions ', response.body)
        actions.logout()

        # The admin assigns the student to review his own work.
        actions.login(email, is_admin=True)
        response = actions.add_reviewer(
            self, LEGACY_REVIEW_UNIT_ID, email, email)
        assert_equals(response.status_int, 302)
        response = self.get(response.location)
        assert_does_not_contain(
            'Error 412: The reviewer is already assigned', response.body)
        assert_contains('First answer to Q1', response.body)
        assert_contains(
            'Review 1 from [email protected]', response.body)

        # The admin repeats the 'add reviewer' action. This should fail.
        response = actions.add_reviewer(
            self, LEGACY_REVIEW_UNIT_ID, email, email)
        assert_equals(response.status_int, 302)
        response = self.get(response.location)
        assert_contains(
            'Error 412: The reviewer is already assigned', response.body)
Esempio n. 16
0
    def test_course_explorer_disabled(self):
        """Tests for disabled course explorer page."""
        # This call should redirect to course page not explorer page.
        response = self.get('/')
        assert_contains('/course', response.location)

        name = 'Test explorer page off'
        email = 'student'

        # Register
        actions.login(email)
        actions.register(self, name)

        response = self.get('/course')
        # 'My courses' and 'Profile' tab should not be present in tab bar.
        assert_does_not_contain('My Courses', response.body)
        assert_does_not_contain('Profile', response.body)
    def test_course_explorer_disabled(self):
        """Tests for disabled course explorer page."""
        # This call should redirect to course page not explorer page.
        response = self.get('/')
        assert_contains('/course', response.location)

        name = 'Test explorer page off'
        email = 'student'

        # Register
        actions.login(email)
        actions.register(self, name)

        response = self.get('/course')
        # 'My courses' and 'Profile' tab should not be present in tab bar.
        assert_does_not_contain('My Courses', response.body)
        assert_does_not_contain('Profile', response.body)
Esempio n. 18
0
    def test_static_files_cache_control(self):
        """Test static/zip handlers use proper Cache-Control headers."""

        # Check static handler.
        response = self.get('/assets/css/main.css')
        assert_equals(response.status_int, 200)
        assert_contains('max-age=600', response.headers['Cache-Control'])
        assert_contains('public', response.headers['Cache-Control'])
        assert_does_not_contain('no-cache', response.headers['Cache-Control'])

        # Check zip file handler.
        response = self.get(
            '/static/inputex-3.1.0/src/inputex/assets/skins/sam/inputex.css')
        assert_equals(response.status_int, 200)
        assert_contains('max-age=600', response.headers['Cache-Control'])
        assert_contains('public', response.headers['Cache-Control'])
        assert_does_not_contain('no-cache', response.headers['Cache-Control'])
    def test_add_reviewer(self):
        """Test that admin can add a reviewer, and cannot re-add reviewers."""

        email = '*****@*****.**'
        name = 'Test Add Reviewer'
        submission = transforms.dumps([
            {'index': 0, 'type': 'regex', 'value': 'First answer to Q1',
             'correct': True},
            {'index': 1, 'type': 'choices', 'value': 3, 'correct': False},
            {'index': 2, 'type': 'regex', 'value': 'First answer to Q3',
             'correct': True},
        ])
        payload = {
            'answers': submission, 'assessment_type': LEGACY_REVIEW_UNIT_ID}

        actions.login(email)
        actions.register(self, name)
        response = actions.submit_assessment(
            self, LEGACY_REVIEW_UNIT_ID, payload)

        # There is nothing to review on the review dashboard.
        response = actions.request_new_review(
            self, LEGACY_REVIEW_UNIT_ID, expected_status_code=200)
        assert_does_not_contain('Assignment to review', response.body)
        assert_contains('Sorry, there are no new submissions ', response.body)
        actions.logout()

        # The admin assigns the student to review his own work.
        actions.login(email, is_admin=True)
        response = actions.add_reviewer(
            self, LEGACY_REVIEW_UNIT_ID, email, email)
        assert_equals(response.status_int, 302)
        response = self.get(response.location)
        assert_does_not_contain(
            'Error 412: The reviewer is already assigned', response.body)
        assert_contains('First answer to Q1', response.body)
        assert_contains(
            'Review 1 from [email protected]', response.body)

        # The admin repeats the 'add reviewer' action. This should fail.
        response = actions.add_reviewer(
            self, LEGACY_REVIEW_UNIT_ID, email, email)
        assert_equals(response.status_int, 302)
        response = self.get(response.location)
        assert_contains(
            'Error 412: The reviewer is already assigned', response.body)
Esempio n. 20
0
    def test_static_files_cache_control(self):
        """Test static/zip handlers use proper Cache-Control headers."""

        # Check static handler.
        response = self.get('/assets/css/main.css')
        assert_equals(response.status_int, 200)
        assert_contains('max-age=600', response.headers['Cache-Control'])
        assert_contains('public', response.headers['Cache-Control'])
        assert_does_not_contain('no-cache', response.headers['Cache-Control'])

        # Check zip file handler.
        response = self.get(
            '/static/inputex-3.1.0/src/inputex/assets/skins/sam/inputex.css')
        assert_equals(response.status_int, 200)
        assert_contains('max-age=600', response.headers['Cache-Control'])
        assert_contains('public', response.headers['Cache-Control'])
        assert_does_not_contain('no-cache', response.headers['Cache-Control'])
Esempio n. 21
0
    def test_student_access(self):
        # enable course explorer
        config.Registry.test_overrides[course_explorer.GCB_ENABLE_COURSE_EXPLORER_PAGE.name] = True
        self.assertTrue(course_explorer.GCB_ENABLE_COURSE_EXPLORER_PAGE.value)

        # check not being logged in
        response = self.get("/explorer")
        assert_contains("Explore Courses", response.body)
        assert_does_not_contain("My Courses", response.body)

        # login and check logged in student perspective
        config.Registry.test_overrides[sites.GCB_COURSES_CONFIG.name] = "course:/:/"

        email = "student"
        actions.login(email)
        response = self.get("/explorer")
        assert_contains("Explore Courses", response.body)
        assert_contains("My Courses", response.body)
Esempio n. 22
0
    def test_student_access(self):
        # enable course explorer
        config.Registry.test_overrides[
            course_explorer.GCB_ENABLE_COURSE_EXPLORER_PAGE.name] = True
        self.assertTrue(course_explorer.GCB_ENABLE_COURSE_EXPLORER_PAGE.value)

        # check not being logged in
        response = self.get('/explorer')
        assert_contains('Explore Courses', response.body)
        assert_does_not_contain('My Courses', response.body)

        # login and check logged in student perspective
        config.Registry.test_overrides[
            sites.GCB_COURSES_CONFIG.name] = 'course:/:/'

        email = 'student'
        actions.login(email)
        response = self.get('/explorer')
        assert_contains('Explore Courses', response.body)
        assert_contains('My Courses', response.body)
Esempio n. 23
0
    def test_lesson_activity_navigation(self):
        """Test navigation between lesson/activity pages."""

        email = '*****@*****.**'
        name = 'Test Lesson Activity Navigation'

        actions.login(email)
        actions.register(self, name)

        response = self.get('unit?unit=1&lesson=1')
        assert_does_not_contain('Previous Page', response.body)
        assert_contains('Next Page', response.body)

        response = self.get('unit?unit=2&lesson=3')
        assert_contains('Previous Page', response.body)
        assert_contains('Next Page', response.body)

        response = self.get('unit?unit=3&lesson=5')
        assert_contains('Previous Page', response.body)
        assert_does_not_contain('Next Page', response.body)
        assert_contains('End', response.body)
Esempio n. 24
0
    def test_lesson_activity_navigation(self):
        """Test navigation between lesson/activity pages."""

        email = '*****@*****.**'
        name = 'Test Lesson Activity Navigation'

        actions.login(email)
        actions.register(self, name)

        response = self.get('unit?unit=1&lesson=1')
        assert_does_not_contain('Previous Page', response.body)
        assert_contains('Next Page', response.body)

        response = self.get('unit?unit=2&lesson=3')
        assert_contains('Previous Page', response.body)
        assert_contains('Next Page', response.body)

        response = self.get('unit?unit=3&lesson=5')
        assert_contains('Previous Page', response.body)
        assert_does_not_contain('Next Page', response.body)
        assert_contains('End', response.body)
    def test_add_reviewer(self):
        """Test that admin can add a reviewer, and cannot re-add reviewers."""

        email = "*****@*****.**"
        name = "Test Add Reviewer"
        submission = transforms.dumps(
            [
                {"index": 0, "type": "regex", "value": "First answer to Q1", "correct": True},
                {"index": 1, "type": "choices", "value": 3, "correct": False},
                {"index": 2, "type": "regex", "value": "First answer to Q3", "correct": True},
            ]
        )
        payload = {"answers": submission, "assessment_type": LEGACY_REVIEW_UNIT_ID}

        actions.login(email)
        actions.register(self, name)
        response = actions.submit_assessment(self, LEGACY_REVIEW_UNIT_ID, payload)

        # There is nothing to review on the review dashboard.
        response = actions.request_new_review(self, LEGACY_REVIEW_UNIT_ID, expected_status_code=200)
        assert_does_not_contain("Assignment to review", response.body)
        assert_contains("Sorry, there are no new submissions ", response.body)
        actions.logout()

        # The admin assigns the student to review his own work.
        actions.login(email, is_admin=True)
        response = actions.add_reviewer(self, LEGACY_REVIEW_UNIT_ID, email, email)
        assert_equals(response.status_int, 302)
        response = self.get(response.location)
        assert_does_not_contain("Error 412: The reviewer is already assigned", response.body)
        assert_contains("First answer to Q1", response.body)
        assert_contains("Review 1 from [email protected]", response.body)

        # The admin repeats the 'add reviewer' action. This should fail.
        response = actions.add_reviewer(self, LEGACY_REVIEW_UNIT_ID, email, email)
        assert_equals(response.status_int, 302)
        response = self.get(response.location)
        assert_contains("Error 412: The reviewer is already assigned", response.body)
Esempio n. 26
0
    def test_view_announcements(self):
        """Test student aspect of announcements."""
        email = '*****@*****.**'
        name = 'Test Announcements'

        actions.login(email)
        actions.register(self, name)

        # Check no announcements yet.
        response = actions.view_announcements(self)
        assert_does_not_contain('Example Announcement', response.body)
        assert_does_not_contain('Welcome to the final class!', response.body)
        assert_contains('No announcements yet.', response.body)
        actions.logout()

        # Login as admin and add announcements.
        actions.login('*****@*****.**', True)
        actions.register(self, 'admin')
        response = actions.view_announcements(self)
        actions.logout()

        # Check we can see non-draft announcements.
        actions.login(email)
        response = actions.view_announcements(self)
        assert_contains('Example Announcement', response.body)
        assert_does_not_contain('Welcome to the final class!', response.body)
        assert_does_not_contain('No announcements yet.', response.body)

        # Check no access to access to draft announcements via REST handler.
        items = AnnouncementEntity.all().fetch(1000)
        for item in items:
            response = self.get('rest/announcements/item?key=%s' % item.key())
            if item.is_draft:
                json_dict = json.loads(response.body)
                assert json_dict['status'] == 401
            else:
                assert_equals(response.status_int, 200)
Esempio n. 27
0
    def test_view_announcements(self):
        """Test student aspect of announcements."""
        email = '*****@*****.**'
        name = 'Test Announcements'

        actions.login(email)
        actions.register(self, name)

        # Check no announcements yet.
        response = actions.view_announcements(self)
        assert_does_not_contain('Example Announcement', response.body)
        assert_does_not_contain('Welcome to the final class!', response.body)
        assert_contains('No announcements yet.', response.body)
        actions.logout()

        # Login as admin and add announcements.
        actions.login('*****@*****.**', True)
        actions.register(self, 'admin')
        response = actions.view_announcements(self)
        actions.logout()

        # Check we can see non-draft announcements.
        actions.login(email)
        response = actions.view_announcements(self)
        assert_contains('Example Announcement', response.body)
        assert_does_not_contain('Welcome to the final class!', response.body)
        assert_does_not_contain('No announcements yet.', response.body)

        # Check no access to access to draft announcements via REST handler.
        items = AnnouncementEntity.all().fetch(1000)
        for item in items:
            response = self.get('rest/announcements/item?key=%s' % item.key())
            if item.is_draft:
                json_dict = json.loads(response.body)
                assert json_dict['status'] == 401
            else:
                assert_equals(response.status_int, 200)
Esempio n. 28
0
    def test_single_uncompleted_course(self):
        """Tests for a single available course."""
        # This call should redirect to explorer page.
        response = self.get('/')
        assert_contains('/explorer', response.location)

        name = 'Test student courses page'
        email = 'Student'

        actions.login(email)

        # Test the explorer page.
        response = self.get('/explorer')
        assert_equals(response.status_int, 200)
        assert_contains('Register', response.body)

        # Navbar should not contain profile tab.
        assert_does_not_contain(
            '<a href="/explorer/profile">Profile</a>', response.body)

        # Test 'my courses' page when a student is not enrolled in any course.
        response = self.get('/explorer/courses')
        assert_equals(response.status_int, 200)
        assert_contains('You are not currently enrolled in any course',
                        response.body)

        # Test 'my courses' page when a student is enrolled in all courses.
        actions.register(self, name)
        response = self.get('/explorer/courses')
        assert_equals(response.status_int, 200)
        assert_contains('Go to course', response.body)
        assert_does_not_contain('You are not currently enrolled in any course',
                                response.body)

        # After the student registers for a course,
        # profile tab should be visible in navbar.
        assert_contains(
            '<a href="/explorer/profile">Profile</a>', response.body)

        # Test profile page.
        response = self.get('/explorer/profile')
        assert_contains('<td>%s</td>' % email, response.body)
        assert_contains('<td>%s</td>' % name, response.body)
        assert_contains('Progress', response.body)
        assert_does_not_contain('View score', response.body)
Esempio n. 29
0
    def test_single_uncompleted_course(self):
        """Tests for a single available course."""
        # This call should redirect to explorer page.
        response = self.get('/')
        assert_contains('/explorer', response.location)

        name = 'Test student courses page'
        email = 'Student'

        actions.login(email)

        # Test the explorer page.
        response = self.get('/explorer')
        assert_equals(response.status_int, 200)
        assert_contains('Register', response.body)

        # Navbar should not contain profile tab.
        assert_does_not_contain('<a href="/explorer/profile">Profile</a>',
                                response.body)

        # Test 'my courses' page when a student is not enrolled in any course.
        response = self.get('/explorer/courses')
        assert_equals(response.status_int, 200)
        assert_contains('You are not currently enrolled in any course',
                        response.body)

        # Test 'my courses' page when a student is enrolled in all courses.
        actions.register(self, name)
        response = self.get('/explorer/courses')
        assert_equals(response.status_int, 200)
        assert_contains('Go to course', response.body)
        assert_does_not_contain('You are not currently enrolled in any course',
                                response.body)

        # After the student registers for a course,
        # profile tab should be visible in navbar.
        assert_contains('<a href="/explorer/profile">Profile</a>',
                        response.body)

        # Test profile page.
        response = self.get('/explorer/profile')
        assert_contains('<td>%s</td>' % email, response.body)
        assert_contains('<td>%s</td>' % name, response.body)
        assert_contains('Progress', response.body)
        assert_does_not_contain('View score', response.body)
    def test_submit_assignment(self):
        """Test submission of peer-reviewed assignments."""

        # Override course.yaml settings by patching app_context.
        get_environ_old = sites.ApplicationContext.get_environ

        def get_environ_new(self):
            environ = get_environ_old(self)
            environ['course']['browsable'] = False
            return environ

        sites.ApplicationContext.get_environ = get_environ_new

        email = '*****@*****.**'
        name = 'Test Peer Reviewed Assignment Submission'
        submission = transforms.dumps([
            {'index': 0, 'type': 'regex', 'value': 'First answer to Q1',
             'correct': True},
            {'index': 1, 'type': 'choices', 'value': 3, 'correct': False},
            {'index': 2, 'type': 'regex', 'value': 'First answer to Q3',
             'correct': True},
        ])
        second_submission = transforms.dumps([
            {'index': 0, 'type': 'regex', 'value': 'Second answer to Q1',
             'correct': True},
            {'index': 1, 'type': 'choices', 'value': 3, 'correct': False},
            {'index': 2, 'type': 'regex', 'value': 'Second answer to Q3',
             'correct': True},
        ])

        # Check that the sample peer-review assignment shows up in the preview
        # page.
        response = actions.view_preview(self)
        assert_contains('Sample peer review assignment', response.body)
        assert_does_not_contain('Review peer assignments', response.body)

        actions.login(email)
        actions.register(self, name)

        # Check that the sample peer-review assignment shows up in the course
        # page and that it can be visited.
        response = actions.view_course(self)
        assert_contains('Sample peer review assignment', response.body)
        assert_contains('Review peer assignments', response.body)
        assert_contains(
            '<a href="assessment?name=%s">' % LEGACY_REVIEW_UNIT_ID,
            response.body)
        assert_contains('<span> Review peer assignments </span>', response.body,
                        collapse_whitespace=True)
        assert_does_not_contain('<a href="reviewdashboard', response.body,
                                collapse_whitespace=True)

        # Check that the progress circle for this assignment is unfilled.
        assert_contains(
            'progress-notstarted-%s' % LEGACY_REVIEW_UNIT_ID, response.body)
        assert_does_not_contain(
            'progress-completed-%s' % LEGACY_REVIEW_UNIT_ID, response.body)

        # Try to access an invalid assignment.
        response = self.get(
            'assessment?name=FakeAssessment', expect_errors=True)
        assert_equals(response.status_int, 404)

        # The student should not be able to see others' reviews because he/she
        # has not submitted an assignment yet.
        response = self.get('assessment?name=%s' % LEGACY_REVIEW_UNIT_ID)
        assert_does_not_contain('Submitted assignment', response.body)
        assert_contains('Due date for this assignment', response.body)
        assert_does_not_contain('Reviews received', response.body)

        # The student should not be able to access the review dashboard because
        # he/she has not submitted the assignment yet.
        response = self.get(
            'reviewdashboard?unit=%s' % LEGACY_REVIEW_UNIT_ID,
            expect_errors=True)
        assert_contains('You must submit the assignment for', response.body)

        # The student submits the assignment.
        response = actions.submit_assessment(
            self,
            LEGACY_REVIEW_UNIT_ID,
            {'answers': submission, 'assessment_type': LEGACY_REVIEW_UNIT_ID}
        )
        assert_contains(
            'Thank you for completing this assignment', response.body)
        assert_contains('Review peer assignments', response.body)

        # The student views the submitted assignment, which has become readonly.
        response = self.get('assessment?name=%s' % LEGACY_REVIEW_UNIT_ID)
        assert_contains('First answer to Q1', response.body)
        assert_contains('Submitted assignment', response.body)

        # The student tries to re-submit the same assignment. This should fail.
        response = actions.submit_assessment(
            self,
            LEGACY_REVIEW_UNIT_ID,
            {'answers': second_submission,
             'assessment_type': LEGACY_REVIEW_UNIT_ID},
            presubmit_checks=False
        )
        assert_contains(
            'You have already submitted this assignment.', response.body)
        assert_contains('Review peer assignments', response.body)

        # The student views the submitted assignment. The new answers have not
        # been saved.
        response = self.get('assessment?name=%s' % LEGACY_REVIEW_UNIT_ID)
        assert_contains('First answer to Q1', response.body)
        assert_does_not_contain('Second answer to Q1', response.body)

        # The student checks the course page and sees that the progress
        # circle for this assignment has been filled, and that the 'Review
        # peer assignments' link is now available.
        response = actions.view_course(self)
        assert_contains(
            'progress-completed-%s' % LEGACY_REVIEW_UNIT_ID, response.body)
        assert_does_not_contain(
            '<span> Review peer assignments </span>', response.body,
            collapse_whitespace=True)
        assert_contains(
            '<a href="reviewdashboard?unit=%s">' % LEGACY_REVIEW_UNIT_ID,
            response.body, collapse_whitespace=True)

        # The student should also be able to now view the review dashboard.
        response = self.get('reviewdashboard?unit=%s' % LEGACY_REVIEW_UNIT_ID)
        assert_contains('Assignments for your review', response.body)
        assert_contains('Review a new assignment', response.body)

        actions.logout()

        # Clean up app_context.
        sites.ApplicationContext.get_environ = get_environ_old
    def test_draft_review_behaviour(self):
        """Test correctness of draft review visibility."""

        email1 = '*****@*****.**'
        name1 = 'Student 1'
        submission1 = transforms.dumps([
            {'index': 0, 'type': 'regex', 'value': 'S1-1', 'correct': True},
            {'index': 1, 'type': 'choices', 'value': 3, 'correct': False},
            {'index': 2, 'type': 'regex', 'value': 'is-S1', 'correct': True},
        ])
        payload1 = {
            'answers': submission1, 'assessment_type': LEGACY_REVIEW_UNIT_ID}

        email2 = '*****@*****.**'
        name2 = 'Student 2'
        submission2 = transforms.dumps([
            {'index': 0, 'type': 'regex', 'value': 'S2-1', 'correct': True},
            {'index': 1, 'type': 'choices', 'value': 3, 'correct': False},
            {'index': 2, 'type': 'regex', 'value': 'not-S1', 'correct': True},
        ])
        payload2 = {
            'answers': submission2, 'assessment_type': LEGACY_REVIEW_UNIT_ID}

        email3 = '*****@*****.**'
        name3 = 'Student 3'
        submission3 = transforms.dumps([
            {'index': 0, 'type': 'regex', 'value': 'S3-1', 'correct': True},
            {'index': 1, 'type': 'choices', 'value': 3, 'correct': False},
            {'index': 2, 'type': 'regex', 'value': 'not-S1', 'correct': True},
        ])
        payload3 = {
            'answers': submission3, 'assessment_type': LEGACY_REVIEW_UNIT_ID}

        # Student 1 submits the assignment.
        actions.login(email1)
        actions.register(self, name1)
        response = actions.submit_assessment(
            self, LEGACY_REVIEW_UNIT_ID, payload1)
        actions.logout()

        # Student 2 logs in and submits the assignment.
        actions.login(email2)
        actions.register(self, name2)
        response = actions.submit_assessment(
            self, LEGACY_REVIEW_UNIT_ID, payload2)

        # Student 2 requests a review, and is given Student 1's assignment.
        response = actions.request_new_review(self, LEGACY_REVIEW_UNIT_ID)
        review_step_key_2_for_1 = get_review_step_key(response)
        assert_contains('S1-1', response.body)

        # Student 2 saves her review as a draft.
        review_2_for_1_payload = get_review_payload(
            'R2for1', is_draft=True)

        response = actions.submit_review(
            self, LEGACY_REVIEW_UNIT_ID, review_step_key_2_for_1,
            review_2_for_1_payload)
        assert_contains('Your review has been saved.', response.body)

        response = self.get('reviewdashboard?unit=%s' % LEGACY_REVIEW_UNIT_ID)
        assert_equals(response.status_int, 200)
        assert_contains('(Draft)', response.body)

        # Student 2's draft is still changeable.
        response = actions.view_review(
            self, LEGACY_REVIEW_UNIT_ID, review_step_key_2_for_1)
        assert_contains('Submit Review', response.body)
        response = actions.submit_review(
            self, LEGACY_REVIEW_UNIT_ID, review_step_key_2_for_1,
            review_2_for_1_payload)
        assert_contains('Your review has been saved.', response.body)

        # Student 2 logs out.
        actions.logout()

        # Student 3 submits the assignment.
        actions.login(email3)
        actions.register(self, name3)
        response = actions.submit_assessment(
            self, LEGACY_REVIEW_UNIT_ID, payload3)
        actions.logout()

        # Student 1 logs in and requests two assignments to review.
        actions.login(email1)
        response = self.get('/reviewdashboard?unit=%s' % LEGACY_REVIEW_UNIT_ID)

        response = actions.request_new_review(self, LEGACY_REVIEW_UNIT_ID)
        assert_contains('Assignment to review', response.body)
        assert_contains('not-S1', response.body)

        review_step_key_1_for_someone = get_review_step_key(response)

        response = actions.request_new_review(self, LEGACY_REVIEW_UNIT_ID)
        assert_contains('Assignment to review', response.body)
        assert_contains('not-S1', response.body)

        review_step_key_1_for_someone_else = get_review_step_key(response)

        response = self.get('reviewdashboard?unit=%s' % LEGACY_REVIEW_UNIT_ID)
        assert_equals(response.status_int, 200)
        assert_contains('disabled="true"', response.body)

        # Student 1 submits both reviews, fulfilling his quota.
        review_1_for_other_payload = get_review_payload('R1for')

        response = actions.submit_review(
            self, LEGACY_REVIEW_UNIT_ID, review_step_key_1_for_someone,
            review_1_for_other_payload)
        assert_contains(
            'Your review has been submitted successfully', response.body)

        response = actions.submit_review(
            self, LEGACY_REVIEW_UNIT_ID, review_step_key_1_for_someone_else,
            review_1_for_other_payload)
        assert_contains(
            'Your review has been submitted successfully', response.body)

        response = self.get('/reviewdashboard?unit=%s' % LEGACY_REVIEW_UNIT_ID)
        assert_contains('(Completed)', response.body)
        assert_does_not_contain('(Draft)', response.body)

        # Although Student 1 has submitted 2 reviews, he cannot view Student
        # 2's review because it is still in Draft status.
        response = self.get('assessment?name=%s' % LEGACY_REVIEW_UNIT_ID)
        assert_equals(response.status_int, 200)
        assert_contains(
            'You have not received any peer reviews yet.', response.body)
        assert_does_not_contain('R2for1', response.body)

        # Student 1 logs out.
        actions.logout()

        # Student 2 submits her review for Student 1's assignment.
        actions.login(email2)

        response = self.get('review?unit=%s&key=%s' % (
            LEGACY_REVIEW_UNIT_ID, review_step_key_2_for_1))
        assert_does_not_contain('Submitted review', response.body)

        response = actions.submit_review(
            self, LEGACY_REVIEW_UNIT_ID, review_step_key_2_for_1,
            get_review_payload('R2for1'))
        assert_contains(
            'Your review has been submitted successfully', response.body)

        # Her review is now read-only.
        response = self.get('review?unit=%s&key=%s' % (
            LEGACY_REVIEW_UNIT_ID, review_step_key_2_for_1))
        assert_contains('Submitted review', response.body)
        assert_contains('R2for1', response.body)

        # Student 2 logs out.
        actions.logout()

        # Now Student 1 can see the review he has received from Student 2.
        actions.login(email1)
        response = self.get('assessment?name=%s' % LEGACY_REVIEW_UNIT_ID)
        assert_equals(response.status_int, 200)
        assert_contains('R2for1', response.body)
    def test_draft_review_behaviour(self):
        """Test correctness of draft review visibility."""

        email1 = "*****@*****.**"
        name1 = "Student 1"
        submission1 = transforms.dumps(
            [
                {"index": 0, "type": "regex", "value": "S1-1", "correct": True},
                {"index": 1, "type": "choices", "value": 3, "correct": False},
                {"index": 2, "type": "regex", "value": "is-S1", "correct": True},
            ]
        )
        payload1 = {"answers": submission1, "assessment_type": LEGACY_REVIEW_UNIT_ID}

        email2 = "*****@*****.**"
        name2 = "Student 2"
        submission2 = transforms.dumps(
            [
                {"index": 0, "type": "regex", "value": "S2-1", "correct": True},
                {"index": 1, "type": "choices", "value": 3, "correct": False},
                {"index": 2, "type": "regex", "value": "not-S1", "correct": True},
            ]
        )
        payload2 = {"answers": submission2, "assessment_type": LEGACY_REVIEW_UNIT_ID}

        email3 = "*****@*****.**"
        name3 = "Student 3"
        submission3 = transforms.dumps(
            [
                {"index": 0, "type": "regex", "value": "S3-1", "correct": True},
                {"index": 1, "type": "choices", "value": 3, "correct": False},
                {"index": 2, "type": "regex", "value": "not-S1", "correct": True},
            ]
        )
        payload3 = {"answers": submission3, "assessment_type": LEGACY_REVIEW_UNIT_ID}

        # Student 1 submits the assignment.
        actions.login(email1)
        actions.register(self, name1)
        response = actions.submit_assessment(self, LEGACY_REVIEW_UNIT_ID, payload1)
        actions.logout()

        # Student 2 logs in and submits the assignment.
        actions.login(email2)
        actions.register(self, name2)
        response = actions.submit_assessment(self, LEGACY_REVIEW_UNIT_ID, payload2)

        # Student 2 requests a review, and is given Student 1's assignment.
        response = actions.request_new_review(self, LEGACY_REVIEW_UNIT_ID)
        review_step_key_2_for_1 = get_review_step_key(response)
        assert_contains("S1-1", response.body)

        # Student 2 saves her review as a draft.
        review_2_for_1_payload = get_review_payload("R2for1", is_draft=True)

        response = actions.submit_review(self, LEGACY_REVIEW_UNIT_ID, review_step_key_2_for_1, review_2_for_1_payload)
        assert_contains("Your review has been saved.", response.body)

        response = self.get("reviewdashboard?unit=%s" % LEGACY_REVIEW_UNIT_ID)
        assert_equals(response.status_int, 200)
        assert_contains("(Draft)", response.body)

        # Student 2's draft is still changeable.
        response = actions.view_review(self, LEGACY_REVIEW_UNIT_ID, review_step_key_2_for_1)
        assert_contains("Submit Review", response.body)
        response = actions.submit_review(self, LEGACY_REVIEW_UNIT_ID, review_step_key_2_for_1, review_2_for_1_payload)
        assert_contains("Your review has been saved.", response.body)

        # Student 2 logs out.
        actions.logout()

        # Student 3 submits the assignment.
        actions.login(email3)
        actions.register(self, name3)
        response = actions.submit_assessment(self, LEGACY_REVIEW_UNIT_ID, payload3)
        actions.logout()

        # Student 1 logs in and requests two assignments to review.
        actions.login(email1)
        response = self.get("/reviewdashboard?unit=%s" % LEGACY_REVIEW_UNIT_ID)

        response = actions.request_new_review(self, LEGACY_REVIEW_UNIT_ID)
        assert_contains("Assignment to review", response.body)
        assert_contains("not-S1", response.body)

        review_step_key_1_for_someone = get_review_step_key(response)

        response = actions.request_new_review(self, LEGACY_REVIEW_UNIT_ID)
        assert_contains("Assignment to review", response.body)
        assert_contains("not-S1", response.body)

        review_step_key_1_for_someone_else = get_review_step_key(response)

        response = self.get("reviewdashboard?unit=%s" % LEGACY_REVIEW_UNIT_ID)
        assert_equals(response.status_int, 200)
        assert_contains('disabled="true"', response.body)

        # Student 1 submits both reviews, fulfilling his quota.
        review_1_for_other_payload = get_review_payload("R1for")

        response = actions.submit_review(
            self, LEGACY_REVIEW_UNIT_ID, review_step_key_1_for_someone, review_1_for_other_payload
        )
        assert_contains("Your review has been submitted successfully", response.body)

        response = actions.submit_review(
            self, LEGACY_REVIEW_UNIT_ID, review_step_key_1_for_someone_else, review_1_for_other_payload
        )
        assert_contains("Your review has been submitted successfully", response.body)

        response = self.get("/reviewdashboard?unit=%s" % LEGACY_REVIEW_UNIT_ID)
        assert_contains("(Completed)", response.body)
        assert_does_not_contain("(Draft)", response.body)

        # Although Student 1 has submitted 2 reviews, he cannot view Student
        # 2's review because it is still in Draft status.
        response = self.get("assessment?name=%s" % LEGACY_REVIEW_UNIT_ID)
        assert_equals(response.status_int, 200)
        assert_contains("You have not received any peer reviews yet.", response.body)
        assert_does_not_contain("R2for1", response.body)

        # Student 1 logs out.
        actions.logout()

        # Student 2 submits her review for Student 1's assignment.
        actions.login(email2)

        response = self.get("review?unit=%s&key=%s" % (LEGACY_REVIEW_UNIT_ID, review_step_key_2_for_1))
        assert_does_not_contain("Submitted review", response.body)

        response = actions.submit_review(
            self, LEGACY_REVIEW_UNIT_ID, review_step_key_2_for_1, get_review_payload("R2for1")
        )
        assert_contains("Your review has been submitted successfully", response.body)

        # Her review is now read-only.
        response = self.get("review?unit=%s&key=%s" % (LEGACY_REVIEW_UNIT_ID, review_step_key_2_for_1))
        assert_contains("Submitted review", response.body)
        assert_contains("R2for1", response.body)

        # Student 2 logs out.
        actions.logout()

        # Now Student 1 can see the review he has received from Student 2.
        actions.login(email1)
        response = self.get("assessment?name=%s" % LEGACY_REVIEW_UNIT_ID)
        assert_equals(response.status_int, 200)
        assert_contains("R2for1", response.body)
Esempio n. 33
0
    def test_submit_assignment(self):
        """Test submission of peer-reviewed assignments."""

        # Override course.yaml settings by patching app_context.
        get_environ_old = sites.ApplicationContext.get_environ

        def get_environ_new(self):
            environ = get_environ_old(self)
            environ['course']['browsable'] = False
            return environ

        sites.ApplicationContext.get_environ = get_environ_new

        email = '*****@*****.**'
        name = 'Test Peer Reviewed Assignment Submission'
        submission = transforms.dumps([
            {
                'index': 0,
                'type': 'regex',
                'value': 'First answer to Q1',
                'correct': True
            },
            {
                'index': 1,
                'type': 'choices',
                'value': 3,
                'correct': False
            },
            {
                'index': 2,
                'type': 'regex',
                'value': 'First answer to Q3',
                'correct': True
            },
        ])
        second_submission = transforms.dumps([
            {
                'index': 0,
                'type': 'regex',
                'value': 'Second answer to Q1',
                'correct': True
            },
            {
                'index': 1,
                'type': 'choices',
                'value': 3,
                'correct': False
            },
            {
                'index': 2,
                'type': 'regex',
                'value': 'Second answer to Q3',
                'correct': True
            },
        ])

        # Check that the sample peer-review assignment shows up in the preview
        # page.
        response = actions.view_preview(self)
        assert_contains('Sample peer review assignment', response.body)
        assert_does_not_contain('Review peer assignments', response.body)

        actions.login(email)
        actions.register(self, name)

        # Check that the sample peer-review assignment shows up in the course
        # page and that it can be visited.
        response = actions.view_course(self)
        assert_contains('Sample peer review assignment', response.body)
        assert_contains('Review peer assignments', response.body)
        assert_contains(
            '<a href="assessment?name=%s">' % LEGACY_REVIEW_UNIT_ID,
            response.body)
        assert_contains('<span> Review peer assignments </span>',
                        response.body,
                        collapse_whitespace=True)
        assert_does_not_contain('<a href="reviewdashboard',
                                response.body,
                                collapse_whitespace=True)

        # Check that the progress circle for this assignment is unfilled.
        assert_contains('progress-notstarted-%s' % LEGACY_REVIEW_UNIT_ID,
                        response.body)
        assert_does_not_contain(
            'progress-completed-%s' % LEGACY_REVIEW_UNIT_ID, response.body)

        # Try to access an invalid assignment.
        response = self.get('assessment?name=FakeAssessment',
                            expect_errors=True)
        assert_equals(response.status_int, 404)

        # The student should not be able to see others' reviews because he/she
        # has not submitted an assignment yet.
        response = self.get('assessment?name=%s' % LEGACY_REVIEW_UNIT_ID)
        assert_does_not_contain('Submitted assignment', response.body)
        assert_contains('Due date for this assignment', response.body)
        assert_does_not_contain('Reviews received', response.body)

        # The student should not be able to access the review dashboard because
        # he/she has not submitted the assignment yet.
        response = self.get('reviewdashboard?unit=%s' % LEGACY_REVIEW_UNIT_ID,
                            expect_errors=True)
        assert_contains('You must submit the assignment for', response.body)

        # The student submits the assignment.
        response = actions.submit_assessment(
            self, LEGACY_REVIEW_UNIT_ID, {
                'answers': submission,
                'assessment_type': LEGACY_REVIEW_UNIT_ID
            })
        assert_contains('Thank you for completing this assignment',
                        response.body)
        assert_contains('Review peer assignments', response.body)

        # The student views the submitted assignment, which has become readonly.
        response = self.get('assessment?name=%s' % LEGACY_REVIEW_UNIT_ID)
        assert_contains('First answer to Q1', response.body)
        assert_contains('Submitted assignment', response.body)

        # The student tries to re-submit the same assignment. This should fail.
        response = actions.submit_assessment(
            self,
            LEGACY_REVIEW_UNIT_ID, {
                'answers': second_submission,
                'assessment_type': LEGACY_REVIEW_UNIT_ID
            },
            presubmit_checks=False)
        assert_contains('You have already submitted this assignment.',
                        response.body)
        assert_contains('Review peer assignments', response.body)

        # The student views the submitted assignment. The new answers have not
        # been saved.
        response = self.get('assessment?name=%s' % LEGACY_REVIEW_UNIT_ID)
        assert_contains('First answer to Q1', response.body)
        assert_does_not_contain('Second answer to Q1', response.body)

        # The student checks the course page and sees that the progress
        # circle for this assignment has been filled, and that the 'Review
        # peer assignments' link is now available.
        response = actions.view_course(self)
        assert_contains('progress-completed-%s' % LEGACY_REVIEW_UNIT_ID,
                        response.body)
        assert_does_not_contain('<span> Review peer assignments </span>',
                                response.body,
                                collapse_whitespace=True)
        assert_contains('<a href="reviewdashboard?unit=%s">' %
                        LEGACY_REVIEW_UNIT_ID,
                        response.body,
                        collapse_whitespace=True)

        # The student should also be able to now view the review dashboard.
        response = self.get('reviewdashboard?unit=%s' % LEGACY_REVIEW_UNIT_ID)
        assert_contains('Assignments for your review', response.body)
        assert_contains('Review a new assignment', response.body)

        actions.logout()

        # Clean up app_context.
        sites.ApplicationContext.get_environ = get_environ_old
Esempio n. 34
0
    def test_draft_review_behaviour(self):
        """Test correctness of draft review visibility."""

        email1 = '*****@*****.**'
        name1 = 'Student 1'
        submission1 = transforms.dumps([
            {
                'index': 0,
                'type': 'regex',
                'value': 'S1-1',
                'correct': True
            },
            {
                'index': 1,
                'type': 'choices',
                'value': 3,
                'correct': False
            },
            {
                'index': 2,
                'type': 'regex',
                'value': 'is-S1',
                'correct': True
            },
        ])
        payload1 = {
            'answers': submission1,
            'assessment_type': LEGACY_REVIEW_UNIT_ID
        }

        email2 = '*****@*****.**'
        name2 = 'Student 2'
        submission2 = transforms.dumps([
            {
                'index': 0,
                'type': 'regex',
                'value': 'S2-1',
                'correct': True
            },
            {
                'index': 1,
                'type': 'choices',
                'value': 3,
                'correct': False
            },
            {
                'index': 2,
                'type': 'regex',
                'value': 'not-S1',
                'correct': True
            },
        ])
        payload2 = {
            'answers': submission2,
            'assessment_type': LEGACY_REVIEW_UNIT_ID
        }

        email3 = '*****@*****.**'
        name3 = 'Student 3'
        submission3 = transforms.dumps([
            {
                'index': 0,
                'type': 'regex',
                'value': 'S3-1',
                'correct': True
            },
            {
                'index': 1,
                'type': 'choices',
                'value': 3,
                'correct': False
            },
            {
                'index': 2,
                'type': 'regex',
                'value': 'not-S1',
                'correct': True
            },
        ])
        payload3 = {
            'answers': submission3,
            'assessment_type': LEGACY_REVIEW_UNIT_ID
        }

        # Student 1 submits the assignment.
        actions.login(email1)
        actions.register(self, name1)
        response = actions.submit_assessment(self, LEGACY_REVIEW_UNIT_ID,
                                             payload1)
        actions.logout()

        # Student 2 logs in and submits the assignment.
        actions.login(email2)
        actions.register(self, name2)
        response = actions.submit_assessment(self, LEGACY_REVIEW_UNIT_ID,
                                             payload2)

        # Student 2 requests a review, and is given Student 1's assignment.
        response = actions.request_new_review(self, LEGACY_REVIEW_UNIT_ID)
        review_step_key_2_for_1 = get_review_step_key(response)
        assert_contains('S1-1', response.body)

        # Student 2 saves her review as a draft.
        review_2_for_1_payload = get_review_payload('R2for1', is_draft=True)

        response = actions.submit_review(self, LEGACY_REVIEW_UNIT_ID,
                                         review_step_key_2_for_1,
                                         review_2_for_1_payload)
        assert_contains('Your review has been saved.', response.body)

        response = self.get('reviewdashboard?unit=%s' % LEGACY_REVIEW_UNIT_ID)
        assert_equals(response.status_int, 200)
        assert_contains('(Draft)', response.body)

        # Student 2's draft is still changeable.
        response = actions.view_review(self, LEGACY_REVIEW_UNIT_ID,
                                       review_step_key_2_for_1)
        assert_contains('Submit Review', response.body)
        response = actions.submit_review(self, LEGACY_REVIEW_UNIT_ID,
                                         review_step_key_2_for_1,
                                         review_2_for_1_payload)
        assert_contains('Your review has been saved.', response.body)

        # Student 2 logs out.
        actions.logout()

        # Student 3 submits the assignment.
        actions.login(email3)
        actions.register(self, name3)
        response = actions.submit_assessment(self, LEGACY_REVIEW_UNIT_ID,
                                             payload3)
        actions.logout()

        # Student 1 logs in and requests two assignments to review.
        actions.login(email1)
        response = self.get('/reviewdashboard?unit=%s' % LEGACY_REVIEW_UNIT_ID)

        response = actions.request_new_review(self, LEGACY_REVIEW_UNIT_ID)
        assert_contains('Assignment to review', response.body)
        assert_contains('not-S1', response.body)

        review_step_key_1_for_someone = get_review_step_key(response)

        response = actions.request_new_review(self, LEGACY_REVIEW_UNIT_ID)
        assert_contains('Assignment to review', response.body)
        assert_contains('not-S1', response.body)

        review_step_key_1_for_someone_else = get_review_step_key(response)

        response = self.get('reviewdashboard?unit=%s' % LEGACY_REVIEW_UNIT_ID)
        assert_equals(response.status_int, 200)
        assert_contains('disabled="true"', response.body)

        # Student 1 submits both reviews, fulfilling his quota.
        review_1_for_other_payload = get_review_payload('R1for')

        response = actions.submit_review(self, LEGACY_REVIEW_UNIT_ID,
                                         review_step_key_1_for_someone,
                                         review_1_for_other_payload)
        assert_contains('Your review has been submitted successfully',
                        response.body)

        response = actions.submit_review(self, LEGACY_REVIEW_UNIT_ID,
                                         review_step_key_1_for_someone_else,
                                         review_1_for_other_payload)
        assert_contains('Your review has been submitted successfully',
                        response.body)

        response = self.get('/reviewdashboard?unit=%s' % LEGACY_REVIEW_UNIT_ID)
        assert_contains('(Completed)', response.body)
        assert_does_not_contain('(Draft)', response.body)

        # Although Student 1 has submitted 2 reviews, he cannot view Student
        # 2's review because it is still in Draft status.
        response = self.get('assessment?name=%s' % LEGACY_REVIEW_UNIT_ID)
        assert_equals(response.status_int, 200)
        assert_contains('You have not received any peer reviews yet.',
                        response.body)
        assert_does_not_contain('R2for1', response.body)

        # Student 1 logs out.
        actions.logout()

        # Student 2 submits her review for Student 1's assignment.
        actions.login(email2)

        response = self.get('review?unit=%s&key=%s' %
                            (LEGACY_REVIEW_UNIT_ID, review_step_key_2_for_1))
        assert_does_not_contain('Submitted review', response.body)

        response = actions.submit_review(self, LEGACY_REVIEW_UNIT_ID,
                                         review_step_key_2_for_1,
                                         get_review_payload('R2for1'))
        assert_contains('Your review has been submitted successfully',
                        response.body)

        # Her review is now read-only.
        response = self.get('review?unit=%s&key=%s' %
                            (LEGACY_REVIEW_UNIT_ID, review_step_key_2_for_1))
        assert_contains('Submitted review', response.body)
        assert_contains('R2for1', response.body)

        # Student 2 logs out.
        actions.logout()

        # Now Student 1 can see the review he has received from Student 2.
        actions.login(email1)
        response = self.get('assessment?name=%s' % LEGACY_REVIEW_UNIT_ID)
        assert_equals(response.status_int, 200)
        assert_contains('R2for1', response.body)