def test_multiple_course(self): """Tests when multiple courses are available.""" sites.setup_courses('course:/test::ns_test, course:/:/') name = 'Test completed course' email = 'Student' # Make the course available. get_environ_old = sites.ApplicationContext.get_environ def get_environ_new(self): environ = get_environ_old(self) environ['course']['now_available'] = True return environ sites.ApplicationContext.get_environ = get_environ_new actions.login(email) actions.register(self, name) response = self.get('/explorer/courses') # Assert if 'View course list' text is shown on my course page. assert_contains('View course list', response.body) # Clean up app_context. sites.ApplicationContext.get_environ = get_environ_old sites.reset_courses()
def test_cancel_map_reduce(self): email = '*****@*****.**' actions.login(email, is_admin=True) response = self.get('dashboard?action=analytics&tab=peer_review') response = response.forms[ 'gcb-run-visualization-peer_review'].submit().follow() # Launch 1st stage of map/reduce job; we must do this in order to # get the pipeline woken up enough to have built a root pipeline # record. Without this, we do not have an ID to use when canceling. self.execute_all_deferred_tasks(iteration_limit=1) # Cancel the job. response = response.forms[ 'gcb-cancel-visualization-peer_review'].submit().follow() assert_contains('Canceled by ' + email, response.body) # Now permit any pending tasks to complete, and expect the job's # status message to remain at "Canceled by ...". # # If the cancel didn't take effect, the map/reduce should have run to # completion and the job's status would change to completed, changing # the message. This is verified in # model_jobs.JobOperationsTest.test_killed_job_can_still_complete self.execute_all_deferred_tasks() response = self.get(response.request.url) assert_contains('Canceled by ' + email, 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_student_cannot_see_reviews_prematurely(self): """Test that students cannot see others' reviews prematurely.""" 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) # Student 1 cannot see the reviews for his assignment yet, because he # has not submitted the two required reviews. response = self.get("assessment?name=%s" % LEGACY_REVIEW_UNIT_ID) assert_equals(response.status_int, 200) assert_contains("Due date for this assignment", response.body) assert_contains("After you have completed the required number of peer reviews", 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_cannot_see_reviews_prematurely(self): """Test that students cannot see others' reviews prematurely.""" 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) # Student 1 cannot see the reviews for his assignment yet, because he # has not submitted the two required reviews. response = self.get('assessment?name=%s' % LEGACY_REVIEW_UNIT_ID) assert_equals(response.status_int, 200) assert_contains('Due date for this assignment', response.body) assert_contains( 'After you have completed the required number of peer reviews', response.body) actions.logout()
def test_attempt_activity_event(self): """Test activity attempt generates event.""" email = '*****@*****.**' name = 'Test Attempt Activity Event' actions.login(email) actions.register(self, name) # Enable event recording. config.Registry.db_overrides[ lessons.CAN_PERSIST_ACTIVITY_EVENTS.name] = True # Prepare event. request = {} request['source'] = 'test-source' request['payload'] = json.dumps({'Alice': 'Bob'}) # Check XSRF token is required. response = self.post('rest/events?%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'] = XsrfTokenManager.create_xsrf_token( 'event-post') response = self.post('rest/events?%s' % urllib.urlencode( {'request': json.dumps(request)}), {}) assert_equals(response.status_int, 200) assert not response.body # Clean up. config.Registry.db_overrides = {}
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)
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)
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_cancel_map_reduce(self): email = '*****@*****.**' actions.login(email, is_admin=True) response = self.get('dashboard?action=peer_review') response = response.forms['gcb-run-visualization-peer_review'].submit( ).follow() # Launch 1st stage of map/reduce job; we must do this in order to # get the pipeline woken up enough to have built a root pipeline # record. Without this, we do not have an ID to use when canceling. self.execute_all_deferred_tasks(iteration_limit=1) # Cancel the job. response = response.forms[ 'gcb-cancel-visualization-peer_review'].submit().follow() assert_contains('Canceled by ' + email, response.body) # Now permit any pending tasks to complete, and expect the job's # status message to remain at "Canceled by ...". # # If the cancel didn't take effect, the map/reduce should have run to # completion and the job's status would change to completed, changing # the message. This is verified in # model_jobs.JobOperationsTest.test_killed_job_can_still_complete self.execute_all_deferred_tasks() response = self.get(response.request.url) assert_contains('Canceled by ' + email, response.body)
def test_non_admin_has_no_access(self): """Test non admin has no access to pages or REST endpoints.""" email = '*****@*****.**' actions.login(email) # Add datastore override. prop = config.ConfigPropertyEntity( key_name='gcb_config_update_interval_sec') prop.value = '5' prop.is_draft = False prop.put() # Check user has no access to specific pages and actions. response = self.testapp.get('/admin?action=settings') assert_equals(response.status_int, 302) response = self.testapp.get( '/admin?action=config_edit&name=gcb_admin_user_emails') assert_equals(response.status_int, 302) response = self.testapp.post( '/admin?action=config_reset&name=gcb_admin_user_emails') assert_equals(response.status_int, 302) # Check user has no rights to GET verb. response = self.testapp.get( '/rest/config/item?key=gcb_config_update_interval_sec') assert_equals(response.status_int, 200) json_dict = json.loads(response.body) assert json_dict['status'] == 401 assert json_dict['message'] == 'Access denied.' # Check user has no rights to PUT verb. payload_dict = {} payload_dict['value'] = '666' payload_dict['is_draft'] = False request = {} request['key'] = 'gcb_config_update_interval_sec' request['payload'] = json.dumps(payload_dict) # Check XSRF token is required. response = self.testapp.put('/rest/config/item?%s' % urllib.urlencode( {'request': json.dumps(request)}), {}) assert_equals(response.status_int, 200) assert_contains('"status": 403', response.body) # Check user still has no rights to PUT verb even if he somehow # obtained a valid XSRF token. request['xsrf_token'] = XsrfTokenManager.create_xsrf_token( 'config-property-put') response = self.testapp.put('/rest/config/item?%s' % urllib.urlencode( {'request': json.dumps(request)}), {}) assert_equals(response.status_int, 200) json_dict = json.loads(response.body) assert json_dict['status'] == 401 assert json_dict['message'] == 'Access denied.'
def test_admin_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 the admin site link actions.login('*****@*****.**', is_admin=True) response = self.get('/explorer') assert_contains('Admin Site', response.body)
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 submit_assessment(self, name, args): """Test student taking an assessment.""" response = self.get('assessment?name=%s' % name) assert_contains( '<script src="assets/js/assessment-%s.js"></script>' % name, response.body) # Extract XSRF token from the page. match = re.search(r'assessmentXsrfToken = [\']([^\']+)', response.body) assert match xsrf_token = match.group(1) args['xsrf_token'] = xsrf_token response = self.post('answer', args) assert_equals(response.status_int, 200) return response
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_anonymous_access(self): """Tests for disabled course explorer page.""" # disable the explorer config.Registry.test_overrides[ course_explorer.GCB_ENABLE_COURSE_EXPLORER_PAGE.name] = False self.assertFalse(course_explorer.GCB_ENABLE_COURSE_EXPLORER_PAGE.value) # check root URL's properly redirect to login response = self.get('/') assert_equals(response.status_int, 302) assert_contains( 'http://localhost/admin/welcome', response.location) response = self.get('/assets/img/your_logo_here.png') assert_equals(response.status_int, 302) assert_contains('accounts/Login', response.location) # check explorer pages are not accessible not_accessibles = [ '/explorer', '/explorer/courses', '/explorer/profile', '/explorer/assets/img/your_logo_here.png'] for not_accessible in not_accessibles: response = self.get(not_accessible, expect_errors=True) assert_equals(response.status_int, 404) # 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 explorer pages are accessible accessibles = [ '/explorer', '/explorer/courses', '/explorer/assets/img/your_logo_here.png'] for accessible in accessibles: response = self.get(accessible, expect_errors=True) assert_equals(response.status_int, 200) # check student pages are not accessible response = self.get('/explorer/profile') assert_equals(response.status_int, 302) self.assertEqual('http://localhost/explorer', response.location)
def test_anonymous_access(self): """Tests for disabled course explorer page.""" # disable the explorer config.Registry.test_overrides[ course_explorer.GCB_ENABLE_COURSE_EXPLORER_PAGE.name] = False self.assertFalse(course_explorer.GCB_ENABLE_COURSE_EXPLORER_PAGE.value) # check root URL's properly redirect to login response = self.get('/') assert_equals(response.status_int, 302) assert_contains( 'http://localhost/admin?action=welcome', response.location) response = self.get('/assets/img/your_logo_here.png') assert_equals(response.status_int, 302) assert_contains('accounts/Login', response.location) # check explorer pages are not accessible not_accessibles = [ '/explorer', '/explorer/courses', '/explorer/profile', '/explorer/assets/img/your_logo_here.png'] for not_accessible in not_accessibles: response = self.get(not_accessible, expect_errors=True) assert_equals(response.status_int, 404) # 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 explorer pages are accessible accessibles = [ '/explorer', '/explorer/courses', '/explorer/assets/img/your_logo_here.png'] for accessible in accessibles: response = self.get(accessible, expect_errors=True) assert_equals(response.status_int, 200) # check student pages are not accessible response = self.get('/explorer/profile') assert_equals(response.status_int, 302) self.assertEqual('http://localhost/explorer', response.location)
def test_i18n(self): """Test course is properly internationalized.""" response = self.get('/courses/%s/preview' % self.course_ru.path) # Assertions below fail because Russian is not being rendered. Why? assert_contains('Вход', response.body) assert_contains('Регистрация', response.body) assert_contains('Расписание', response.body) assert_contains('Курс', response.body)
def test_attempt_activity_event(self): """Test activity attempt generates event.""" email = '*****@*****.**' name = 'Test Attempt Activity Event' actions.login(email) actions.register(self, name) # Enable event recording. config.Registry.db_overrides[ lessons.CAN_PERSIST_ACTIVITY_EVENTS.name] = True # Prepare event. request = {} request['source'] = 'test-source' request['payload'] = json.dumps({'Alice': u'Bob (тест данные)'}) # Check XSRF token is required. response = self.post('rest/events?%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'] = XsrfTokenManager.create_xsrf_token( 'event-post') response = self.post('rest/events?%s' % urllib.urlencode( {'request': json.dumps(request)}), {}) assert_equals(response.status_int, 200) assert not response.body # Check event is properly recorded. old_namespace = namespace_manager.get_namespace() namespace_manager.set_namespace(self.namespace) try: events = models.EventEntity.all().fetch(1000) assert 1 == len(events) assert_contains( u'Bob (тест данные)', json.loads(events[0].data)['Alice']) finally: namespace_manager.set_namespace(old_namespace) # Clean up. config.Registry.db_overrides = {}
def test_csv_supports_utf8(self): """Test UTF-8 content in CSV file is handled correctly.""" title_ru = u'Найди факты быстрее' csv_file = os.path.join(self.course_ru.home, 'data/unit.csv') self.modify_file( csv_file, ',Find facts faster,', ',%s,' % title_ru) self.modify_file( os.path.join(self.course_ru.home, 'data/lesson.csv'), ',Find facts faster,', ',%s,' % title_ru) rows = [] for row in csv.reader(open(csv_file)): rows.append(row) assert title_ru == rows[6][3].decode('utf-8') response = self.get('/courses/%s/preview' % self.course_ru.path) assert_contains(title_ru, response.body) # Tests student perspective. self.walk_the_course(self.course_ru, first_time=True) self.walk_the_course(self.course_ru, first_time=False) # Test course author dashboard. self.walk_the_course( self.course_ru, first_time=False, is_admin=True, logout=False) def assert_page_contains(page_name, text_array): dashboard_url = '/courses/%s/dashboard' % self.course_ru.path response = self.get('%s?action=%s' % (dashboard_url, page_name)) for text in text_array: assert_contains(text, response.body) assert_page_contains('', [ title_ru, self.course_ru.unit_title, self.course_ru.lesson_title]) assert_page_contains( 'assets', [self.course_ru.title, self.course_ru.home]) assert_page_contains( 'settings', [self.course_ru.title, self.course_ru.home]) # Clean up. actions.logout()
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_analytics_are_individually_cancelable_and_runnable(self): """Test run/cancel controls for individual analytics jobs.""" # Submit all analytics. email = '*****@*****.**' actions.login(email, is_admin=True) response = self.get('dashboard?action=peer_review') response = response.forms[ 'gcb-generate-analytics-data'].submit().follow() # Ensure that analytics appear to be running and have cancel buttons. assert_contains('is running', response.body) assert_contains('Cancel', response.body) # Now that all analytics are pending, ensure that update-all button # is hidden. dom = self.parse_html_string(response.body) update_all = dom.find('.//div[@id="analytics-update-all"]') cancel_all = dom.find('.//div[@id="analytics-cancel-all"]') self.assertEquals(update_all.get('class'), 'gcb-button-toolbar not-displayed') self.assertEquals(cancel_all.get('class'), 'gcb-button-toolbar ') # Click the cancel button for one of the slower jobs. response = response.forms[ 'gcb-cancel-visualization-peer_review'].submit().follow() # Verify that page shows job was canceled. assert_contains('error updating peer review statistics', response.body) assert_contains('Canceled by ' + email, response.body) # We should now have our update-statistics button back. self.assertIsNotNone(response.forms['gcb-generate-analytics-data']) # Should also have a button to run the canceled job; click that. response = response.forms[ 'gcb-run-visualization-peer_review'].submit().follow() # All jobs should now again be running, and update-all button hidden. dom = self.parse_html_string(response.body) update_all = dom.find('.//div[@id="analytics-update-all"]') cancel_all = dom.find('.//div[@id="analytics-cancel-all"]') self.assertEquals(update_all.get('class'), 'gcb-button-toolbar not-displayed') self.assertEquals(cancel_all.get('class'), 'gcb-button-toolbar ')
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)
def test_two_students_dont_see_each_other_pages(self): """Test a user can't see another user pages.""" email1 = '*****@*****.**' name1 = 'User 1' email2 = '*****@*****.**' name2 = 'User 2' # Login as one user and view 'unit' and other pages, which are not # cached. actions.login(email1) actions.register(self, name1) actions.Permissions.assert_enrolled(self) response = actions.view_unit(self) assert_contains(email1, response.body) actions.logout() # Login as another user and check that 'unit' and other pages show # the correct new email. actions.login(email2) actions.register(self, name2) actions.Permissions.assert_enrolled(self) response = actions.view_unit(self) assert_contains(email2, response.body) actions.logout()
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)
def test_analytics_are_individually_cancelable_and_runnable(self): """Test run/cancel controls for individual analytics jobs.""" # Submit all analytics. email = '*****@*****.**' actions.login(email, is_admin=True) response = self.get('dashboard?action=peer_review') response = response.forms['gcb-generate-analytics-data'].submit( ).follow() # Ensure that analytics appear to be running and have cancel buttons. assert_contains('is running', response.body) assert_contains('Cancel', response.body) # Now that all analytics are pending, ensure that update-all button # is hidden. dom = self.parse_html_string(response.body) update_all = dom.find('.//div[@id="analytics-update-all"]') cancel_all = dom.find('.//div[@id="analytics-cancel-all"]') self.assertEquals(update_all.get('class'), 'gcb-button-toolbar not-displayed') self.assertEquals(cancel_all.get('class'), 'gcb-button-toolbar ') # Click the cancel button for one of the slower jobs. response = response.forms[ 'gcb-cancel-visualization-peer_review'].submit().follow() # Verify that page shows job was canceled. assert_contains('error updating peer review statistics', response.body) assert_contains('Canceled by ' + email, response.body) # We should now have our update-statistics button back. self.assertIsNotNone(response.forms['gcb-generate-analytics-data']) # Should also have a button to run the canceled job; click that. response = response.forms['gcb-run-visualization-peer_review'].submit( ).follow() # All jobs should now again be running, and update-all button hidden. dom = self.parse_html_string(response.body) update_all = dom.find('.//div[@id="analytics-update-all"]') cancel_all = dom.find('.//div[@id="analytics-cancel-all"]') self.assertEquals(update_all.get('class'), 'gcb-button-toolbar not-displayed') self.assertEquals(cancel_all.get('class'), 'gcb-button-toolbar ')
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
def test_course_pass(self): """Test student passing final exam.""" email = '*****@*****.**' name = 'Test Pass' post = {'assessment_type': 'postcourse', 'score': '100.00'} # Register. actions.login(email) actions.register(self, name) # Submit answer. response = self.submit_assessment('Post', post) assert_equals(response.status_int, 200) assert_contains('Your score is 70%', response.body) assert_contains('you have passed the course', response.body) # Check that the result shows up on the profile page. response = actions.check_profile(self, name) assert_contains('70', response.body) assert_contains('100', 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)
def test_analytics_are_individually_cancelable_and_runnable(self): """Test run/cancel controls for individual analytics jobs.""" # Submit all analytics. email = '*****@*****.**' actions.login(email, is_admin=True) response = self.get('dashboard?action=analytics&tab=peer_review') response = response.forms[ 'gcb-generate-analytics-data'].submit().follow() # Ensure that analytics appear to be running and have cancel buttons. assert_contains('is running', response.body) assert_contains('Cancel Statistic Calculation', response.body) # Now that all analytics are pending, ensure that we do _not_ have # an update-all button. with self.assertRaises(KeyError): response = response.forms['gcb-generate-analytics-data'] # Click the cancel button for one of the slower jobs. response = response.forms[ 'gcb-cancel-visualization-peer_review'].submit().follow() # Verify that page shows job was canceled. assert_contains('error updating peer review statistics', response.body) assert_contains('Canceled by ' + email, response.body) # We should now have our update-statistics button back. self.assertIsNotNone(response.forms['gcb-generate-analytics-data']) # Should also have a button to run the canceled job; click that. response = response.forms[ 'gcb-run-visualization-peer_review'].submit().follow() # All jobs should now again be running, and update-all button gone. with self.assertRaises(KeyError): response = response.forms['gcb-generate-analytics-data']
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)
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)
def test_python_console(self): """Test access rights to the Python console.""" email = '*****@*****.**' # Check normal user has no access. actions.login(email) response = self.testapp.get('/admin?action=console') assert_equals(response.status_int, 302) response = self.testapp.post('/admin?action=console') assert_equals(response.status_int, 302) # Check delegated admin has no access. os.environ['gcb_admin_user_emails'] = '[%s]' % email actions.login(email) response = self.testapp.get('/admin?action=console') assert_equals(response.status_int, 200) assert_contains( 'You must be an actual admin user to continue.', response.body) response = self.testapp.get('/admin?action=console') assert_equals(response.status_int, 200) assert_contains( 'You must be an actual admin user to continue.', response.body) del os.environ['gcb_admin_user_emails'] # Check actual admin has access. actions.login(email, True) response = self.testapp.get('/admin?action=console') assert_equals(response.status_int, 200) response.form.set('code', 'print "foo" + "bar"') response = self.submit(response.form) assert_contains('foobar', response.body)
def test_reviewer_cannot_impersonate_another_reviewer(self): """Test that one reviewer cannot use another's review step key.""" 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) actions.logout() # Student 3 logs in, and submits the assignment. actions.login(email3) actions.register(self, name3) response = actions.submit_assessment(self, LEGACY_REVIEW_UNIT_ID, payload3) # Student 3 tries to view Student 1's assignment using Student 2's # review step key, but is not allowed to. response = actions.view_review(self, LEGACY_REVIEW_UNIT_ID, review_step_key_2_for_1, expected_status_code=404) # Student 3 logs out. actions.logout()
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_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_independence_of_draft_reviews(self): """Test that draft reviews do not interfere with each other.""" 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) actions.logout() # Student 3 logs in and 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_equals(response.status_int, 200) 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_equals(response.status_int, 200) 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) self.assertNotEqual(review_step_key_1_for_someone, review_step_key_1_for_someone_else) # Student 1 submits two draft reviews. response = actions.submit_review( self, LEGACY_REVIEW_UNIT_ID, review_step_key_1_for_someone, get_review_payload('R1forFirst', is_draft=True)) assert_contains('Your review has been saved.', response.body) response = actions.submit_review( self, LEGACY_REVIEW_UNIT_ID, review_step_key_1_for_someone_else, get_review_payload('R1forSecond', is_draft=True)) assert_contains('Your review has been saved.', response.body) # The two draft reviews should still be different when subsequently # accessed. response = self.get( 'review?unit=%s&key=%s' % (LEGACY_REVIEW_UNIT_ID, review_step_key_1_for_someone)) assert_contains('R1forFirst', response.body) response = self.get( 'review?unit=%s&key=%s' % (LEGACY_REVIEW_UNIT_ID, review_step_key_1_for_someone_else)) assert_contains('R1forSecond', response.body) # Student 1 logs out. actions.logout()
def test_peer_review_analytics(self): """Test analytics page on course dashboard.""" student1 = '*****@*****.**' name1 = 'Test Student 1' student2 = '*****@*****.**' name2 = 'Test Student 2' peer = {'assessment_type': 'ReviewAssessmentExample'} # Student 1 submits a peer review assessment. actions.login(student1) actions.register(self, name1) actions.submit_assessment(self, 'ReviewAssessmentExample', peer) actions.logout() # Student 2 submits the same peer review assessment. actions.login(student2) actions.register(self, name2) actions.submit_assessment(self, 'ReviewAssessmentExample', peer) actions.logout() email = '*****@*****.**' # The admin looks at the analytics page on the dashboard. actions.login(email, is_admin=True) response = self.get('dashboard?action=analytics') assert_contains( 'Google ><a href="%s"> Dashboard </a>> 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('Peer Review Statistics', response.body) assert_contains('Sample peer review assignment', response.body) # JSON code for the completion statistics. assert_contains('"[{\\"stats\\": [2]', response.body) actions.logout() # Student2 requests a review. actions.login(student2) response = actions.request_new_review(self, LEGACY_REVIEW_UNIT_ID) review_step_key_2_for_1 = get_review_step_key(response) assert_contains('Assignment to review', response.body) # Student2 submits the review. 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) actions.logout() actions.login(email, is_admin=True) response = self.get('dashboard?action=analytics') assert_contains( 'Google ><a href="%s"> Dashboard </a>> Analytics' % self.canonicalize('dashboard'), response.body) compute_form = response.forms['gcb-compute-student-stats'] response = self.submit(compute_form) self.execute_all_deferred_tasks() response = self.get('dashboard?action=analytics') assert_contains('Peer Review Statistics', response.body) # JSON code for the completion statistics. assert_contains('"[{\\"stats\\": [1, 1]', response.body) actions.logout()