def test_pages(self): """ Basic page rendering """ crs = CourseOffering.objects.get(slug=TEST_COURSE_SLUG) memb = Member.objects.get(offering=crs, person__userid="ggbaker") person = Person.objects.get(userid='ggbaker') p = Page(offering=crs, label="Index") p.save() v = PageVersion(page=p, title="Index Page", wikitext="Original Contents", editor=memb) v.save() p = Page(offering=crs, label="OtherPage") p.save() v = PageVersion(page=p, title="Other Page", wikitext="Original Contents", editor=memb) v.save() c = Client() c.login_user('ggbaker') # test the basic rendering of the core pages test_views(self, c, 'pages.views.', ['index_page', 'all_pages', 'new_page', 'new_file', 'import_site'], {'course_slug': crs.slug}) test_views(self, c, 'pages.views.', ['view_page', 'page_history', 'edit_page', 'import_page'], {'course_slug': crs.slug, 'page_label': 'OtherPage'})
def test_pages(self): offering = CourseOffering.objects.get(slug=TEST_COURSE_SLUG) student = Member.objects.get(offering=offering, person__userid='0aaa0') instr = Member.objects.get(offering=offering, person__userid='ggbaker') c = Client() c.login_user('ggbaker') test_views(self, c, 'offering:discipline:', ['index', 'new', 'newgroup', 'new_nonstudent'], {'course_slug': offering.slug}) cluster = DisciplineGroup(name='TheCluster', offering=offering) cluster.save() case = DisciplineCaseInstrStudent(student=student.person, owner=instr.person, offering=offering, group=cluster) case.save() test_views(self, c, 'offering:discipline:', ['showgroup'], {'course_slug': offering.slug, 'group_slug': cluster.slug}) test_views(self, c, 'offering:discipline:', ['show', 'edit_related', 'edit_attach', 'new_file'], {'course_slug': offering.slug, 'case_slug': case.slug}) # have a look at each form for step in STEP_FORM: test_views(self, c, 'offering:discipline:', ['edit_case_info'], {'course_slug': offering.slug, 'case_slug': case.slug, 'field': step}) # minimally-finish the case so we can check the letter case.letter_sent = 'MAIL' case.letter_text = 'foo' case.save() test_views(self, c, 'offering:discipline:', ['view_letter'], {'course_slug': offering.slug, 'case_slug': case.slug})
def test_pages(self): """ Test basic page rendering """ c = Client() c.login_user('ggbaker') test_views(self, c, 'reminders:', ['index', 'create'], {}) rem = Reminder.objects.first() test_views(self, c, 'reminders:', ['view', 'edit'], {'reminder_slug': rem.slug})
def test_pages(self): "Test a bunch of page views" offering = CourseOffering.objects.get(slug=TEST_COURSE_SLUG) activity = Activity.objects.get(offering=offering, slug='rep') activity.due_date = datetime.datetime.now() + datetime.timedelta(days=1) # make sure it's submittable activity.save() client = Client() # instructor views client.login_user("ggbaker") component1 = URL.Component(activity=activity, title='Sample URL 1', description='Please submit some URL.', check=False, prefix='') component1.save() component2 = URL.Component(activity=activity, title='Sample URL 2', description='Please submit some URL.', check=False, prefix='') component2.save() test_views(self, client, 'submission.views.', ['show_components', 'add_component'], {'course_slug': offering.slug, 'activity_slug': activity.slug}) url = reverse('submission.views.edit_single', kwargs={'course_slug': offering.slug, 'activity_slug': activity.slug}) \ + '?id=' + unicode(component1.id) basic_page_tests(self, client, url) url = reverse('submission.views.add_component', kwargs={'course_slug': offering.slug, 'activity_slug': activity.slug}) \ + '?type=url' basic_page_tests(self, client, url) # student views: with none, some, and all submitted client.login_user("0aaa0") # test various permutations of success to make sure everything returns okay name1 = '%i-url' % (component1.id) name2 = '%i-url' % (component2.id) submissions = [ ({}, False), ({name1: '', name2: ''}, False), ({name1: '', name2: 'do i look like a url to you?'}, False), ({name1: 'http://www.sfu.ca/', name2: ''}, False), ({name1: 'http://www.cs.sfu.ca/', name2: 'http://example.com/'}, True), ({name1: 'http://www.sfu.ca/', name2: 'http://example.com/'}, True), ] for submitdata, redir in submissions: test_views(self, client, 'submission.views.', ['show_components', 'show_components_submission_history'], {'course_slug': offering.slug, 'activity_slug': activity.slug}) url = reverse('submission.views.show_components', kwargs={'course_slug': offering.slug, 'activity_slug': activity.slug}) response = client.post(url, submitdata) if redir: # success: we expect a redirect self.assertEqual(response.status_code, 302) else: # some problems: expect a page reporting that self.assertEqual(response.status_code, 200) validate_content(self, response.content, url)
def test_pages(self): client = Client() asset_slug = 'cmpt-something' asset_id = 1 client.login_user('dzhao') test_views(self, client, 'inventory:', ['inventory_index', 'new_asset'], {}) test_views(self, client, 'inventory:', ['edit_asset', 'view_asset'], {'asset_slug': asset_slug}) url = reverse('inventory:delete_asset', kwargs={'asset_id': asset_id}) response = client.post(url, follow=True) self.assertEquals(response.status_code, 200)
def test_pages(self): """ Basic page rendering """ crs = self._sample_setup() c = Client() c.login_user('ggbaker') # test the basic rendering of the core pages test_views(self, c, 'pages.views.', ['index_page', 'all_pages', 'new_page', 'new_file', 'import_site'], {'course_slug': crs.slug}) test_views(self, c, 'pages.views.', ['view_page', 'page_history', 'edit_page', 'import_page'], {'course_slug': crs.slug, 'page_label': 'OtherPage'})
def test_pages(self): # Presumably, our booking that starts more than 5 years ago is the one generated in the fixtures. If there are # others that old, it should at least be the first. unit = Unit.objects.get(slug='cmpt') booking = BookingRecord.objects.filter(start_time__lte=self.long_start, location__unit=unit).first() location = booking.location roomtype = location.room_type client = Client() userid = Role.objects_fresh.filter(role='SPAC', unit=unit)[0].person.userid client.login_user(userid) test_views(self, client, 'space:', ['index', 'list_roomtypes', 'add_roomtype', 'manage_safety_items', 'add_safety_item'], {}) test_views(self, client, 'space:', ['view_location', 'edit_location', 'add_booking'], {'location_slug': location.slug}) test_views(self, client, 'space:', ['view_roomtype', 'edit_roomtype'], {'roomtype_slug': roomtype.slug}) test_views(self, client, 'space:', ['view_booking', 'edit_booking', 'add_booking_attachment'], {'booking_slug': booking.slug}) # Now, we should be able to delete stuff properly. url = reverse('space:delete_booking', kwargs={'booking_id': booking.id}) response = client.post(url, follow=True) self.assertEqual(response.status_code, 200) url = reverse('space:delete_location', kwargs={'location_id': location.id}) response = client.post(url, follow=True) self.assertEqual(response.status_code, 200) url = reverse('space:delete_roomtype', kwargs={'roomtype_id': roomtype.id}) response = client.post(url, follow=True) self.assertEqual(response.status_code, 200)
def test_grad_pages(self): """ Check overall pages for the grad module and make sure they all load """ client = Client() client.login_user('dzhao') gs = self.__make_test_grad() prog = gs.program GradRequirement(program=prog, description="Some New Requirement").save() Supervisor(student=GradStudent.objects.all()[0], supervisor=Person.objects.get(userid='ggbaker'), supervisor_type='SEN').save() lt = LetterTemplate( unit=gs.program.unit, label='Template', content="This is the\n\nletter for {{first_name}}.") lt.save() test_views(self, client, 'grad:', [ 'programs', 'new_program', 'requirements', 'new_requirement', 'letter_templates', 'new_letter_template', 'manage_scholarshiptypes', 'search', 'funding_report', 'all_promises', 'new_scholarshiptype' ], {}) test_views(self, client, 'grad:', ['manage_letter_template'], {'letter_template_slug': lt.slug}) test_views(self, client, 'grad:', ['edit_scholarshiptype'], {'st_id': 1}) test_views(self, client, 'grad:', ['not_found'], {}, qs='search=grad')
def test_pages(self): client = Client() today = datetime.date.today() long_start = today + datetime.timedelta(days=5 * 365) # Our test even is probably the only one that starts at least 5 years from whatever day it is when we run this event = OutreachEvent.objects.current([ Unit.objects.get(slug='cmpt') ]).filter(start_date__gt=long_start).first() registration = OutreachEventRegistration.objects.filter( event=event).first() # Anyone should be able to register test_views(self, client, 'outreach:', ['register', 'register_success'], {'event_slug': event.slug}) # Log in as someone with the correct role. userid = Role.objects_fresh.filter( role='OUTR', unit=Unit.objects.get(slug='cmpt'))[0].person.userid client.login_user(userid) test_views(self, client, 'outreach:', ['outreach_index', 'view_all_registrations'], {}) test_views(self, client, 'outreach:', ['edit_event', 'view_event', 'view_event_registrations'], {'event_slug': event.slug}) test_views(self, client, 'outreach:', ['view_registration', 'edit_registration'], {'registration_id': registration.id}) url = reverse('outreach:toggle_registration_attendance', kwargs={'registration_id': registration.id}) response = client.post(url, follow=True) self.assertEqual(response.status_code, 200)
def test_pages(self): """ Basic page rendering """ crs = self._sample_setup() c = Client() c.login_user('ggbaker') # test the basic rendering of the core pages test_views(self, c, 'offering:pages:', ['index_page', 'all_pages', 'new_page', 'new_file'], {'course_slug': crs.slug}) test_views(self, c, 'offering:pages:', ['view_page', 'page_history', 'edit_page'], {'course_slug': crs.slug, 'page_label': 'OtherPage'})
def test_submission_types(self): "Minimally test each submission type" offering = CourseOffering.objects.get(slug=TEST_COURSE_SLUG) activity = Activity.objects.get(offering=offering, slug='rep') activity.due_date = datetime.datetime.now() + datetime.timedelta(days=1) # make sure it's submittable activity.save() client = Client() # instructor views client.login_user("ggbaker") for Type in ALL_TYPE_CLASSES: label = Type.label test_views(self, client, 'submission.views.', ['add_component'], {'course_slug': offering.slug, 'activity_slug': activity.slug}, qs='type='+label)
def test_dst(self): """ Test news item in the ambiguous DST switchover """ instr = self.instructor n = NewsItem(user=instr, author=instr, source_app='foo', title='The Title', content='Content') n.save() c = Client() c.login_user(instr.userid) test_views(self, c, '', ['dashboard:index', 'news:news_list'], {}) n.published = datetime.datetime(2014, 11, 2, 1, 30, 0) # there are two of this time because of the DST transition n.save() test_views(self, c, '', ['dashboard:index', 'news:news_list'], {})
def test_submission_types(self): "Minimally test each submission type" offering = CourseOffering.objects.get(slug=TEST_COURSE_SLUG) activity = Activity.objects.get(offering=offering, slug='rep') activity.due_date = datetime.datetime.now() + datetime.timedelta( days=1) # make sure it's submittable activity.save() client = Client() # instructor views client.login_user("ggbaker") for Type in ALL_TYPE_CLASSES: label = Type.label test_views(self, client, 'offering:submission:', ['add_component'], { 'course_slug': offering.slug, 'activity_slug': activity.slug }, qs='type=' + label)
def test_pages(self): """ Basic page rendering """ crs = CourseOffering.objects.get(slug=TEST_COURSE_SLUG) memb = Member.objects.get(offering=crs, person__userid="ggbaker") person = Person.objects.get(userid='ggbaker') p = Page(offering=crs, label="Index") p.save() v = PageVersion(page=p, title="Index Page", wikitext="Original Contents", editor=memb) v.save() p = Page(offering=crs, label="OtherPage") p.save() v = PageVersion(page=p, title="Other Page", wikitext="Original Contents", editor=memb) v.save() c = Client() c.login_user('ggbaker') # test the basic rendering of the core pages test_views( self, c, 'pages.views.', ['index_page', 'all_pages', 'new_page', 'new_file', 'import_site'], {'course_slug': crs.slug}) test_views(self, c, 'pages.views.', ['view_page', 'page_history', 'edit_page', 'import_page'], { 'course_slug': crs.slug, 'page_label': 'OtherPage' })
def test_pages(self): client = Client() today = datetime.date.today() long_start = today + datetime.timedelta(days=5*365) # Our test even is probably the only one that starts at least 5 years from whatever day it is when we run this event = OutreachEvent.objects.current([Unit.objects.get(slug='cmpt')]).filter(start_date__gt=long_start).first() registration = OutreachEventRegistration.objects.filter(event=event).first() # Anyone should be able to register test_views(self, client, 'outreach:', ['register', 'register_success'], {'event_slug': event.slug}) # Log in as someone with the correct role. userid = Role.objects_fresh.filter(role='OUTR', unit=Unit.objects.get(slug='cmpt'))[0].person.userid client.login_user(userid) test_views(self, client, 'outreach:', ['outreach_index', 'view_all_registrations'], {}) test_views(self, client, 'outreach:', ['edit_event', 'view_event', 'view_event_registrations'], {'event_slug': event.slug}) test_views(self, client, 'outreach:', ['view_registration', 'edit_registration'], {'registration_id': registration.id}) url=reverse('outreach:toggle_registration_attendance', kwargs={'registration_id': registration.id}) response = client.post(url, follow=True) self.assertEqual(response.status_code, 200)
def test_pages(self): client = Client() userid = Role.objects_fresh.filter(role='SPAC', unit=Unit.objects.get(slug='cmpt'))[0].person.userid client.login_user(userid) test_views(self, client, 'space:', ['index', 'list_roomtypes', 'add_roomtype'], {}) test_views(self, client, 'space:', ['view_location', 'edit_location', 'add_booking'], {'location_slug': self.location.slug}) test_views(self, client, 'space:', ['view_roomtype', 'edit_roomtype'], {'roomtype_slug': self.roomtype.slug}) test_views(self, client, 'space:', ['view_booking', 'edit_booking', 'add_booking_attachment'], {'booking_slug': self.booking.slug}) # Now, we should be able to delete stuff properly. url = reverse('space:delete_booking', kwargs={'booking_id': self.booking.id}) response = client.post(url, follow=True) self.assertEqual(response.status_code, 200) url = reverse('space:delete_location', kwargs={'location_id': self.location.id}) response = client.post(url, follow=True) self.assertEqual(response.status_code, 200) url = reverse('space:delete_roomtype', kwargs={'roomtype_id': self.roomtype.id}) response = client.post(url, follow=True) self.assertEqual(response.status_code, 200)
def test_pages(self): client = Client() account_slug = 'cmpt-234-sfufa-account' contract_slug = 'a-test-sessionalcontract' contract = SessionalContract.objects.get(slug=contract_slug) contract_id = contract.id # as instructor client.login_user('dzhao') test_views(self, client, 'sessionals:', ['sessionals_index', 'manage_accounts', 'new_account', 'manage_configs', 'new_config', 'new_contract'], {}) test_views(self, client, 'sessionals:', ['edit_account', 'view_account'], {'account_slug': account_slug}) test_views(self, client, 'sessionals:', ['view_contract', 'edit_contract'], {'contract_slug': contract_slug}) url = reverse('sessionals:delete_contract', kwargs={'contract_id': contract_id}) response = client.post(url, follow=True) self.assertEqual(response.status_code, 200)
def test_pages(self): person = Person.objects.filter()[0] c = Client() # as instructor c.login_user(person.userid) test_views(self, c, 'dashboard.views.', ['index', 'index_full', 'news_list', 'config', 'calendar', 'create_calendar_url', 'disable_calendar_url', 'news_config', 'create_news_url', 'disable_news_url', 'list_docs', 'photo_agreement'], {}) test_views(self, c, 'dashboard.views.', ['view_doc'], {'doc_slug': 'impersonate'}) # admin views for signatures r = Role.objects.filter(role='ADMN')[0] c.login_user(r.person.userid) test_views(self, c, 'dashboard.views.', ['signatures', 'new_signature'], {})
def test_pages(self): client = Client() account_slug = 'cmpt-234-sfufa-account' contract_slug = 'a-test-sessionalcontract' contract = SessionalContract.objects.get(slug=contract_slug) contract_id = contract.id # as instructor client.login_user('dzhao') test_views(self, client, 'sessionals:', [ 'sessionals_index', 'manage_accounts', 'new_account', 'manage_configs', 'new_config', 'new_contract' ], {}) test_views(self, client, 'sessionals:', ['edit_account', 'view_account'], {'account_slug': account_slug}) test_views(self, client, 'sessionals:', ['view_contract', 'edit_contract'], {'contract_slug': contract_slug}) url = reverse('sessionals:delete_contract', kwargs={'contract_id': contract_id}) response = client.post(url, follow=True) self.assertEquals(response.status_code, 200)
def test_grad_pages(self): """ Check overall pages for the grad module and make sure they all load """ client = Client() test_auth(client, 'ggbaker') gs = self.__make_test_grad() prog = gs.program GradRequirement(program=prog, description="Some New Requirement").save() Supervisor(student=GradStudent.objects.all()[0], supervisor=Person.objects.get(userid='ggbaker'), supervisor_type='SEN').save() lt = LetterTemplate(unit=gs.program.unit, label='Template', content="This is the\n\nletter for {{first_name}}.") lt.save() test_views(self, client, 'grad.views.', ['programs', 'new_program', 'requirements', 'new_requirement', 'letter_templates', 'new_letter_template', 'manage_scholarshipType', 'search', 'funding_report', 'all_promises'], {}) test_views(self, client, 'grad.views.', ['manage_letter_template'], {'letter_template_slug': lt.slug}) test_views(self, client, 'grad.views.', ['not_found'], {}, qs='search=grad')
def test_pages(self): """ Render as many pages as possible, to make sure they work, are valid, etc. """ c = Client() c.login_user('ggbaker') # test as an instructor test_views(self, c, 'offering:quiz:', ['index', 'preview_student', 'edit', 'question_add', 'submissions', 'special_cases', 'special_case_add', 'marking', 'strange_history', 'photo_compare'], {'course_slug': self.offering.slug, 'activity_slug': self.activity.slug}) test_views(self, c, 'offering:quiz:', ['question_add_version'], {'course_slug': self.offering.slug, 'activity_slug': self.activity.slug, 'question_id': str(self.q1.id)}) test_views(self, c, 'offering:quiz:', ['question_edit'], {'course_slug': self.offering.slug, 'activity_slug': self.activity.slug, 'question_id': str(self.q1.id), 'version_id': str(self.v11.id)}) test_views(self, c, 'offering:quiz:', ['question_edit'], {'course_slug': self.offering.slug, 'activity_slug': self.activity.slug, 'question_id': str(self.q2.id), 'version_id': str(self.v21.id)}) test_views(self, c, 'offering:quiz:', ['view_submission', 'submission_history'], {'course_slug': self.offering.slug, 'activity_slug': self.activity.slug, 'userid': self.s1.person.userid}) test_views(self, c, 'offering:quiz:', ['mark_student'], {'course_slug': self.offering.slug, 'activity_slug': self.activity.slug, 'member_id': self.s1.id}) # test as a student c.login_user(self.s0.person.userid) test_views(self, c, 'offering:quiz:', ['index'], {'course_slug': self.offering.slug, 'activity_slug': self.activity.slug})
def test_pages(self): c = Client() # TUG/instructor views c.login_user('dzhao') offering = CourseOffering.objects.get(slug=TEST_COURSE_SLUG) ta = Member.objects.filter(offering=offering, role="TA")[0] test_views(self, c, 'offering:', ['new_tug'], { 'course_slug': offering.slug, 'userid': ta.person.userid }) # create TUG to view/edit tug = TUG(member=ta, base_units=5) for f in list(tug.config_meta.keys()): tug.config[f] = {'weekly': 1, 'total': 13, 'note': 'somenote'} tug.save() test_views(self, c, 'offering:', ['view_tug', 'edit_tug'], { 'course_slug': offering.slug, 'userid': ta.person.userid }) # admin views c.login_user('dzhao') test_views(self, c, 'tugs:', ['all_tugs_admin'], {}) test_views(self, c, 'ta:', ['view_postings'], {}) post = TAPosting.objects.filter(unit__label='CMPT')[0] test_views(self, c, 'ta:', [ 'new_application', 'new_application_manual', 'view_all_applications', 'print_all_applications', 'print_all_applications_by_course', 'view_late_applications', 'assign_tas', 'all_contracts' ], {'post_slug': post.slug}) test_views(self, c, 'ta:', ['assign_bus'], { 'post_slug': post.slug, 'course_slug': offering.slug }) contr = TAContract.objects.filter(posting=post)[0] test_views(self, c, 'ta:', [ 'edit_application', 'view_application', 'preview_offer', 'view_contract', 'edit_contract' ], { 'post_slug': post.slug, 'userid': contr.application.person.userid }) # applicant views c.login_user(contr.application.person.userid) test_views(self, c, 'ta:', ['accept_contract'], { 'post_slug': post.slug, 'userid': contr.application.person.userid })
def test_pages(self): """ Render as many pages as possible, to make sure they work, are valid, etc. """ c = Client() # as department admin c.login_user('dzhao') test_views(self, c, 'faculty:', [ 'index', 'search_index', 'salary_index', 'status_index', 'manage_event_index', 'teaching_capacity', 'fallout_report', 'course_accreditation', 'manage_faculty_roles' ], {}) test_views(self, c, 'faculty:', [ 'summary', 'teaching_summary', 'salary_summary', 'otherinfo', 'event_type_list', 'study_leave_credits', 'timeline', 'faculty_member_info', 'edit_faculty_member_info', 'faculty_wizard' ], {'userid': 'ggbaker'}) test_views(self, c, 'faculty:', [ 'view_event', 'change_event', 'new_attachment', 'new_text_attachment', 'new_memo_no_template' ], { 'userid': 'ggbaker', 'event_slug': '2000-appointment-to-position' }) test_views(self, c, 'faculty:', ['manage_memo_template'], { 'event_type': 'appoint', 'slug': 'cmpt-welcome' }) test_views( self, c, 'faculty:', ['new_memo'], { 'userid': 'ggbaker', 'event_slug': '2000-appointment-to-position', 'memo_template_slug': 'cmpt-welcome' }) test_views( self, c, 'faculty:', ['manage_memo', 'view_memo'], { 'userid': 'ggbaker', 'event_slug': '2000-appointment-to-position', 'memo_slug': '2000-appointment-to-position-welcome' }) test_views(self, c, 'faculty:', ['teaching_credit_override'], { 'userid': 'ggbaker', 'course_slug': TEST_COURSE_SLUG }) test_views(self, c, 'faculty:', ['event_config_add'], {'event_type': 'fellow'}) # grant views test_views(self, c, 'faculty:', ['grant_index'], {}) test_views(self, c, 'faculty:', ['convert_grant'], {'gid': TempGrant.objects.all()[0].id}) test_views(self, c, 'faculty:', ['edit_grant', 'view_grant'], { 'unit_slug': 'cmpt', 'grant_slug': 'baker-startup-grant' }) # TODO: CSV views, JSON view # per-handler views for Handler in HANDLERS: try: slug = Handler.EVENT_TYPE.lower() test_views(self, c, 'faculty:', ['create_event'], { 'userid': 'ggbaker', 'event_type': slug }) test_views(self, c, 'faculty:', ['event_config', 'new_memo_template'], {'event_type': slug}) # the search form test_views(self, c, 'faculty:', ['search_events'], {'event_type': slug}) # search with some results test_views(self, c, 'faculty:', ['search_events'], {'event_type': slug}, qs='only_current=on') except: print("failure with Handler==%s" % (Handler)) raise
def test_otp_auth(self): c = Client() person = Person.objects.get(userid='ggbaker') url = reverse('dashboard:index') # no auth: should redirect to 2fa login, and then to password login resp = c.get(url) self.assertEqual(resp.status_code, 302) self.assertTrue(resp['location'].startswith(str(settings.LOGIN_URL) + '?')) nexturl = resp['location'] resp = c.get(nexturl) self.assertEqual(resp.status_code, 302) self.assertTrue(resp['location'].startswith(str(settings.PASSWORD_LOGIN_URL) + '?')) # do the standard Django auth: should be okay for now, since user doesn't need 2FA. c.login_user('ggbaker') user = User.objects.get(username='******') session_info = SessionInfo.for_sessionstore(c.session) resp = c.get(url) self.assertEqual(resp.status_code, 200) # set the user's account to need 2FA: now should be redirected to create a TOPT. person.config['2fa'] = True person.save() resp = c.get(url) self.assertEqual(resp.status_code, 302) self.assertTrue(resp['location'].startswith(str(settings.LOGIN_URL) + '?')) nexturl = resp['location'] resp = c.get(nexturl) self.assertEqual(resp.status_code, 302) self.assertTrue(resp['location'].startswith(reverse('otp:add_topt'))) test_views(self, c, 'otp:', ['add_topt'], {}) # create a fake TOTP device for the user TOTPDevice.objects.filter(user=user).delete() key = '0'*20 device = TOTPDevice(user=user, name='test device', confirmed=True, key=key) device.save() # ... now we should see the 2FA screen resp = c.get(url) self.assertEqual(resp.status_code, 302) self.assertTrue(resp['location'].startswith(str(settings.LOGIN_URL) + '?')) nexturl = resp['location'] resp = c.get(nexturl) self.assertEqual(resp.status_code, 200) test_views(self, c, 'otp:', ['login_2fa'], {}) # if we fake the 2FA login, we should be seeing pages again session_info.last_2fa = timezone.now() session_info.save() # (mock django_otp's login()) from django_otp import DEVICE_ID_SESSION_KEY session = c.session session._session[DEVICE_ID_SESSION_KEY] = device.persistent_id session.save() resp = c.get(url) self.assertEqual(resp.status_code, 200) # now fiddle with the ages of things and check for the right failures # old password login: should redirect -> login -> password login session_info.last_auth = timezone.now() - datetime.timedelta(days=8) session_info.save() resp = c.get(url, follow=True) self.assertEqual(len(resp.redirect_chain), 2) self.assertTrue(resp.redirect_chain[-1][0].startswith(str(settings.PASSWORD_LOGIN_URL) + '?')) # old 2fa: should redirect -> 2fa login session_info.last_auth = timezone.now() - datetime.timedelta(hours=1) session_info.last_2fa = timezone.now() - datetime.timedelta(days=32) session_info.save() resp = c.get(url, follow=True) self.assertEqual(len(resp.redirect_chain), 1) self.assertTrue(resp.redirect_chain[-1][0].startswith(str(settings.LOGIN_URL) + '?'))
def test_pages(self): """ Test basic page rendering """ c = Client() c.login_user('dzhao') test_views(self, c, 'ra.views.', [ 'search', 'new', 'accounts_index', 'new_account', 'projects_index', 'new_project', 'semester_config', 'browse' ], {}) test_views(self, c, 'ra.views.', ['found'], {}, qs='search=grad') ra = RAAppointment.objects.filter(unit__label='CMPT')[0] p = ra.person test_views(self, c, 'ra.views.', ['student_appointments', 'new_student'], {'userid': p.userid}) test_views(self, c, 'ra.views.', [ 'edit', 'reappoint', 'view', ], {'ra_slug': ra.slug}) test_views(self, c, 'ra.views.', ['edit_letter'], {'ra_slug': ra.slug}) acct = Account.objects.filter(unit__label='CMPT')[0] test_views(self, c, 'ra.views.', ['edit_account'], {'account_slug': acct.slug}) proj = Project.objects.filter(unit__label='CMPT')[0] test_views(self, c, 'ra.views.', ['edit_project'], {'project_slug': proj.slug})
def test_pages(self): "Test a bunch of page views" offering = CourseOffering.objects.get(slug=TEST_COURSE_SLUG) activity = Activity.objects.get(offering=offering, slug='rep') activity.due_date = datetime.datetime.now() + datetime.timedelta( days=1) # make sure it's submittable activity.save() client = Client() # instructor views client.login_user("ggbaker") component1 = URL.Component(activity=activity, title='Sample URL 1', description='Please submit some URL.', check=False, prefix='') component1.save() component2 = URL.Component(activity=activity, title='Sample URL 2', description='Please submit some URL.', check=False, prefix='') component2.save() test_views(self, client, 'offering:submission:', ['show_components', 'add_component'], { 'course_slug': offering.slug, 'activity_slug': activity.slug }) url = reverse('offering:submission:edit_single', kwargs={'course_slug': offering.slug, 'activity_slug': activity.slug}) \ + '?id=' + unicode(component1.id) basic_page_tests(self, client, url) url = reverse('offering:submission:add_component', kwargs={'course_slug': offering.slug, 'activity_slug': activity.slug}) \ + '?type=url' basic_page_tests(self, client, url) # student views: with none, some, and all submitted client.login_user("0aaa0") # test various permutations of success to make sure everything returns okay name1 = '%i-url' % (component1.id) name2 = '%i-url' % (component2.id) submissions = [ ({}, False), ({ name1: '', name2: '' }, False), ({ name1: '', name2: 'do i look like a url to you?' }, False), ({ name1: 'http://www.sfu.ca/', name2: '' }, False), ({ name1: 'http://www.cs.sfu.ca/', name2: 'http://example.com/' }, True), ({ name1: 'http://www.sfu.ca/', name2: 'http://example.com/' }, True), ] for submitdata, redir in submissions: test_views( self, client, 'offering:submission:', ['show_components', 'show_components_submission_history'], { 'course_slug': offering.slug, 'activity_slug': activity.slug }) url = reverse('offering:submission:show_components', kwargs={ 'course_slug': offering.slug, 'activity_slug': activity.slug }) response = client.post(url, submitdata) if redir: # success: we expect a redirect self.assertEqual(response.status_code, 302) else: # some problems: expect a page reporting that self.assertEqual(response.status_code, 200) validate_content(self, response.content, url)
def test_pages(self): """ Render as many pages as possible, to make sure they work, are valid, etc. """ c = Client() # as department admin c.login_user('dzhao') test_views(self, c, 'faculty:', ['index', 'search_index', 'salary_index', 'status_index', 'manage_event_index', 'teaching_capacity', 'fallout_report', 'course_accreditation', 'manage_faculty_roles'], {}) test_views(self, c, 'faculty:', ['summary', 'teaching_summary', 'salary_summary', 'otherinfo', 'event_type_list', 'study_leave_credits', 'timeline', 'faculty_member_info', 'edit_faculty_member_info', 'faculty_wizard'], {'userid': 'ggbaker'}) test_views(self, c, 'faculty:', ['view_event', 'change_event', 'new_attachment', 'new_text_attachment', 'new_memo_no_template'], {'userid': 'ggbaker', 'event_slug': '2000-appointment-to-position'}) test_views(self, c, 'faculty:', ['manage_memo_template'], {'event_type': 'appoint', 'slug': 'cmpt-welcome'}) test_views(self, c, 'faculty:', ['new_memo'], {'userid': 'ggbaker', 'event_slug': '2000-appointment-to-position', 'memo_template_slug': 'cmpt-welcome'}) test_views(self, c, 'faculty:', ['manage_memo', 'view_memo'], {'userid': 'ggbaker', 'event_slug': '2000-appointment-to-position', 'memo_slug': '2000-appointment-to-position-welcome'}) test_views(self, c, 'faculty:', ['teaching_credit_override'], {'userid': 'ggbaker', 'course_slug': TEST_COURSE_SLUG}) test_views(self, c, 'faculty:', ['event_config_add'], {'event_type': 'fellow'}) # grant views test_views(self, c, 'faculty:', ['grant_index'], {}) test_views(self, c, 'faculty:', ['convert_grant'], {'gid': TempGrant.objects.all()[0].id}) test_views(self, c, 'faculty:', ['edit_grant', 'view_grant'], {'unit_slug': 'cmpt', 'grant_slug': 'baker-startup-grant'}) # TODO: CSV views, JSON view # per-handler views for Handler in HANDLERS: try: slug = Handler.EVENT_TYPE.lower() test_views(self, c, 'faculty:', ['create_event'], {'userid': 'ggbaker', 'event_type': slug}) test_views(self, c, 'faculty:', ['event_config', 'new_memo_template'], {'event_type': slug}) # the search form test_views(self, c, 'faculty:', ['search_events'], {'event_type': slug}) # search with some results test_views(self, c, 'faculty:', ['search_events'], {'event_type': slug}, qs='only_current=on') except: print("failure with Handler==%s" % (Handler)) raise
def test_pages(self): c = Client() # TUG/instructor views c.login_user('ggbaker') offering = CourseOffering.objects.get(slug=TEST_COURSE_SLUG) ta = Member.objects.filter(offering=offering, role="TA")[0] test_views(self, c, 'ta.views.', ['new_tug'], {'course_slug': offering.slug, 'userid': ta.person.userid}) # create TUG to view/edit tug = TUG(member=ta, base_units=5) for f in tug.config_meta.keys(): tug.config[f] = {'weekly': 1, 'total': 13, 'note': 'somenote'} tug.save() test_views(self, c, 'ta.views.', ['view_tug', 'edit_tug'], {'course_slug': offering.slug, 'userid': ta.person.userid}) # admin views c.login_user('ggbaker') test_views(self, c, 'ta.views.', ['all_tugs_admin', 'view_postings'], {}) post = TAPosting.objects.filter(unit__label='CMPT')[0] test_views(self, c, 'ta.views.', ['new_application', 'new_application_manual', 'view_all_applications', 'print_all_applications', 'print_all_applications_by_course', 'view_late_applications', 'assign_tas', 'all_contracts'], {'post_slug': post.slug}) test_views(self, c, 'ta.views.', ['assign_bus'], {'post_slug': post.slug, 'course_slug': offering.slug}) app = TAApplication.objects.filter(posting=post)[0] test_views(self, c, 'ta.views.', ['edit_application', 'view_application', 'preview_offer', 'view_contract', 'edit_contract'], {'post_slug': post.slug, 'userid': app.person.userid}) # applicant views c.login_user(app.person.userid) test_views(self, c, 'ta.views.', ['accept_contract'], {'post_slug': post.slug, 'userid': app.person.userid})
def test_pages(self): """ Test basic page rendering """ c = Client() c.login_user('dzhao') test_views(self, c, 'ra:', ['search', 'new', 'accounts_index', 'new_account', 'projects_index', 'new_project', 'semester_config', 'browse'], {}) test_views(self, c, 'ra:', ['found'], {}, qs='search=grad') ra = RAAppointment.objects.filter(unit__label='CMPT')[0] p = ra.person test_views(self, c, 'ra:', ['student_appointments', 'new_student'], {'userid': p.userid}) test_views(self, c, 'ra:', ['edit', 'reappoint', 'view',], {'ra_slug': ra.slug}) # No offer text yet, we should get a redirect when trying to edit the letter text: url = reverse('ra:edit_letter', kwargs={'ra_slug': ra.slug}) response = c.get(url) self.assertEqual(response.status_code, 302) # Let's add some offer text and try again. ra.offer_letter_text='Some test text here' ra.save() test_views(self, c, 'ra:', ['edit_letter'], {'ra_slug': ra.slug}) # Make sure we can add attachments test_views(self, c, 'ra:', ['new_attachment'], {'ra_slug': ra.slug}) acct = Account.objects.filter(unit__label='CMPT')[0] test_views(self, c, 'ra:', ['edit_account'], {'account_slug': acct.slug}) proj = Project.objects.filter(unit__label='CMPT')[0] test_views(self, c, 'ra:', ['edit_project'], {'project_slug': proj.slug})
def test_pages(self): """ Test basic page rendering """ c = Client() c.login_user('dzhao') test_views(self, c, 'ra:', ['dashboard', 'new_request', 'browse'], {}) ra = RAAppointment.objects.filter(unit__label='CMPT')[0] p = ra.person test_views(self, c, 'ra:', ['edit', 'view'], {'ra_slug': ra.slug}) # No offer text yet, we should get a redirect when trying to edit the letter text: url = reverse('ra:edit_letter', kwargs={'ra_slug': ra.slug}) response = c.get(url) self.assertEqual(response.status_code, 302) # Let's add some offer text and try again. ra.offer_letter_text = 'Some test text here' ra.save() test_views(self, c, 'ra:', ['edit_letter'], {'ra_slug': ra.slug}) # Make sure we can add attachments test_views(self, c, 'ra:', ['new_attachment'], {'ra_slug': ra.slug}) # NEW RA # test basic pages test_views(self, c, 'ra:', [ 'browse_appointments', 'new_request', 'dashboard', 'active_appointments', 'advanced_search' ], {}) # test search test_views(self, c, 'ra:', ['appointee_appointments', 'supervisor_appointments'], {'userid': p.userid}) # create test rarequest u = Unit.objects.get(slug='cmpt') s = Person.objects.get(userid='dzhao') req = RARequest(person=p, unit=u, author=s, supervisor=s, config={}, hiring_category='RA', start_date=date(2021, 6, 1), end_date=date(2021, 9, 1), total_pay=1000) req.save() # test pages associated with an rarequest test_views(self, c, 'ra:', [ 'view_request', 'edit_request', 'reappoint_request', 'edit_request_notes', 'request_paf', 'request_offer_letter_update', 'new_admin_attachment' ], {'ra_slug': req.slug})
def test_pages(self): """ Test basic page rendering """ c = Client() c.login_user('dzhao') test_views(self, c, 'ra:', [ 'search', 'new', 'accounts_index', 'new_account', 'projects_index', 'new_project', 'semester_config', 'browse' ], {}) test_views(self, c, 'ra:', ['found'], {}, qs='search=grad') ra = RAAppointment.objects.filter(unit__label='CMPT')[0] p = ra.person test_views(self, c, 'ra:', ['student_appointments', 'new_student'], {'userid': p.userid}) test_views(self, c, 'ra:', [ 'edit', 'reappoint', 'view', ], {'ra_slug': ra.slug}) # No offer text yet, we should get a redirect when trying to edit the letter text: url = reverse('ra:edit_letter', kwargs={'ra_slug': ra.slug}) response = c.get(url) self.assertEquals(response.status_code, 302) # Let's add some offer text and try again. ra.offer_letter_text = 'Some test text here' ra.save() test_views(self, c, 'ra:', ['edit_letter'], {'ra_slug': ra.slug}) acct = Account.objects.filter(unit__label='CMPT')[0] test_views(self, c, 'ra:', ['edit_account'], {'account_slug': acct.slug}) proj = Project.objects.filter(unit__label='CMPT')[0] test_views(self, c, 'ra:', ['edit_project'], {'project_slug': proj.slug})
def test_pages(self): """ Test basic page rendering """ c = Client() c.login_user('ggbaker') test_views(self, c, 'ra.views.', ['search', 'new', 'accounts_index', 'new_account', 'projects_index', 'new_project', 'semester_config', 'browse'], {}) test_views(self, c, 'ra.views.', ['found'], {}, qs='search=grad') ra = RAAppointment.objects.filter(unit__label='CMPT')[0] p = ra.person test_views(self, c, 'ra.views.', ['student_appointments', 'new_student'], {'userid': p.userid}) test_views(self, c, 'ra.views.', ['edit', 'reappoint', 'edit_letter', 'view',], {'ra_slug': ra.slug}) acct = Account.objects.filter(unit__label='CMPT')[0] test_views(self, c, 'ra.views.', ['edit_account'], {'account_slug': acct.slug}) proj = Project.objects.filter(unit__label='CMPT')[0] test_views(self, c, 'ra.views.', ['edit_project'], {'project_slug': proj.slug})