def test_edit_session(self): print('- Test: edit a session') self.login() session_id = '6' session = adminApi.get_session(session_id) courses = adminApi.get_courses_by_term('6') data1 = { 'session': session_id, 'year': '2019', 'term': '6', 'title': 'Edited TA Application', 'description': 'Edited description', 'note': 'Edited note', 'is_visible': 'True', 'courses': [str(courses[0].id), str(courses[1].id)], 'next': '/administrators/sessions/currentt/?page=2' } response = self.client.post( reverse('administrators:edit_session', args=[session.slug]) + CURRENT_SESSION, data=urlencode(data1, True), content_type=ContentType) self.assertEqual(response.status_code, 404) data2 = { 'session': session_id, 'year': '2019', 'term': '6', 'title': 'Edited TA Application', 'description': 'Edited description', 'note': 'Edited note', 'is_visible': 'True', 'courses': [str(courses[0].id), str(courses[1].id)], 'next': CURRENT_NEXT } response = self.client.post( reverse('administrators:edit_session', args=[session.slug]) + CURRENT_SESSION, data=urlencode(data2, True), content_type=ContentType) messages = self.messages(response) self.assertTrue('Success' in messages[0]) self.assertEqual(response.status_code, 302) self.assertEqual( response.url, reverse('administrators:current_sessions') + '?page=2') self.assertRedirects(response, response.url) updated_session = adminApi.get_session(session_id) self.assertEqual(updated_session.id, int(data2['session'])) self.assertEqual(updated_session.year, data2['year']) self.assertEqual(updated_session.title, data2['title']) self.assertEqual(updated_session.description, data2['description']) self.assertEqual(updated_session.note, data2['note']) self.assertEqual(updated_session.is_visible, eval(data2['is_visible'])) self.assertEqual(updated_session.job_set.count(), len(data2['courses']))
def test_add_empty_courses_in_session(self): print('- Test: add empty courses in a session') self.login() session_id = '5' term_id = '3' session = adminApi.get_session(session_id) data = { 'session': session_id, 'year': session.year, 'term': term_id, 'title': 'Edited TA Application', 'description': 'Edited description', 'note': 'Edited note', 'is_visible': 'True', 'courses': [], 'next': CURRENT_NEXT } response = self.client.post( reverse('administrators:edit_session', args=[session.slug]) + CURRENT_SESSION, data=urlencode(data, True), content_type=ContentType) messages = self.messages(response) self.assertTrue('An error occurred' in messages[0]) self.assertEqual(response.status_code, 302) self.assertRedirects(response, response.url)
def test_view_session_report_applicants(self): print('- Test: view a session report - applicants') self.login() client_session = self.client.session client_session['next_session'] = reverse( 'administrators:current_sessions') + '?page=1' client_session.save() session = adminApi.get_session(SESSION, 'slug') response = self.client.get( reverse('administrators:show_report_applicants', args=[session.slug])) self.assertEqual(response.status_code, 200) self.assertEqual(response.context['loggedin_user'].username, USERS[0]) self.assertEqual(response.context['session'].id, session.id) self.assertEqual(response.context['session'].slug, SESSION) self.assertEqual(response.context['total_applicants'], 5) self.assertEqual( response.context['next_session'], reverse('administrators:current_sessions') + '?page=1') self.assertEqual(response.context['back_to_word'], 'Current Sessions') applicants = [{ 'username': '******', 'accepted_apps': ['APBI 200 001 (30.0 hours)'] }, { 'username': '******', 'accepted_apps': [] }, { 'username': '******', 'accepted_apps': ['APBI 260 001 (45.0 hours)'] }, { 'username': '******', 'accepted_apps': ['APBI 200 002 (65.0 hours)'] }, { 'username': '******', 'accepted_apps': [] }] c = 0 for applicant in response.context['applicants']: self.assertEqual(applicant.username, applicants[c]['username']) if len(applicant.accepted_apps) > 0: d = 0 for accepted_app in applicant.accepted_apps: self.assertEqual( accepted_app.job.course.code.name + ' ' + accepted_app.job.course.number.name + ' ' + accepted_app.job.course.section.name + ' (' + str(accepted_app.accepted.assigned_hours) + ' hours)', applicants[c]['accepted_apps'][d]) d += 1 c += 1
def test_delete_session(self): print('- Test: delete a session') self.login() session_id = '6' session = adminApi.get_session(session_id) data = {'session': session_id, 'next': CURRENT_NEXT} response = self.client.post( reverse('administrators:delete_session_confirmation', args=[session.slug]) + CURRENT_SESSION, data=urlencode(data), content_type=ContentType) messages = self.messages(response) self.assertTrue('Success' in messages[0]) self.assertEqual(response.status_code, 302) self.assertRedirects(response, response.url) self.assertFalse(adminApi.session_exists(session_id))
def test_show_session(self): print('- Test: show a session') self.login() session = adminApi.get_session(SESSION, 'slug') response = self.client.get( reverse('administrators:show_session', args=[session.slug])) self.assertEqual(response.status_code, 404) response = self.client.get( reverse('administrators:show_session', args=[session.slug]) + '?nex=/administrators/sessions/current/?page=2&p=Current%20Session' ) self.assertEqual(response.status_code, 404) response = self.client.get( reverse('administrators:show_session', args=[session.slug]) + '?next=/administrator/sessions/current/?page=2&p=Current%20Session' ) self.assertEqual(response.status_code, 404) response = self.client.get( reverse('administrators:show_session', args=[session.slug]) + '?next=/administrators/sessions/current/&a=Current%20Sessions') self.assertEqual(response.status_code, 404) response = self.client.get( reverse('administrators:show_session', args=[session.slug]) + '?next=/administrators/sessions/current/&p=Current%20Session') self.assertEqual(response.status_code, 404) response = self.client.get( reverse('administrators:show_session', args=[session.slug]) + CURRENT_SESSION) self.assertEqual(response.status_code, 200) self.assertEqual(response.context['loggedin_user'].username, USERS[0]) self.assertEqual(response.context['session'].id, session.id) self.assertEqual(response.context['session'].slug, SESSION) self.assertEqual(response.context['next'], CURRENT_NEXT)
def test_remove_courses_in_session(self): print('- Test: remove courses in a session') self.login() session_id = '5' term_id = '3' session = adminApi.get_session(session_id) courses = adminApi.get_courses_by_term(term_id) num_courses = len(courses) course_ids = [] for course in courses: if course.id != 3 and course.id != 27: course_ids.append(str(course.id)) data = { 'session': session_id, 'year': session.year, 'term': term_id, 'title': 'Edited TA Application', 'description': 'Edited description', 'note': 'Edited note', 'is_visible': 'True', 'courses': course_ids, 'next': CURRENT_NEXT } response = self.client.post( reverse('administrators:edit_session', args=[session.slug]) + CURRENT_SESSION, data=urlencode(data, True), content_type=ContentType) messages = self.messages(response) self.assertTrue('Success' in messages[0]) self.assertEqual(response.status_code, 302) self.assertRedirects(response, response.url) updated_session = adminApi.get_session(session_id) self.assertEqual(updated_session.id, int(data['session'])) self.assertEqual(updated_session.year, data['year']) self.assertEqual(updated_session.title, data['title']) self.assertEqual(updated_session.description, data['description']) self.assertEqual(updated_session.note, data['note']) self.assertEqual(updated_session.is_visible, eval(data['is_visible'])) self.assertEqual(updated_session.job_set.count(), len(data['courses'])) self.assertEqual(updated_session.job_set.count(), num_courses - 2) # re-enter courses data = { 'session': session_id, 'year': session.year, 'term': term_id, 'title': 'Edited TA Application', 'description': 'Edited description', 'note': 'Edited note', 'is_visible': 'True', 'courses': [str(course.id) for course in courses], 'next': CURRENT_NEXT } response = self.client.post( reverse('administrators:edit_session', args=[session.slug]) + CURRENT_SESSION, data=urlencode(data, True), content_type=ContentType) messages = self.messages(response) self.assertTrue('Success' in messages[0]) self.assertEqual(response.status_code, 302) self.assertRedirects(response, response.url) updated_session = adminApi.get_session(session_id) self.assertEqual(updated_session.id, int(data['session'])) self.assertEqual(updated_session.year, data['year']) self.assertEqual(updated_session.title, data['title']) self.assertEqual(updated_session.description, data['description']) self.assertEqual(updated_session.note, data['note']) self.assertEqual(updated_session.is_visible, eval(data['is_visible'])) self.assertEqual(updated_session.job_set.count(), len(data['courses'])) self.assertEqual(updated_session.job_set.count(), num_courses)
def test_view_session_report_summary(self): print('- Test: view a session report - summary') self.login(USERS[2], PASSWORD) self.submit_confiential_information_international_complete(USERS[2]) self.login() client_session = self.client.session client_session['next_session'] = reverse( 'administrators:current_sessions') + '?page=1' client_session.save() session = adminApi.get_session(SESSION, 'slug') response = self.client.get( reverse('administrators:show_report_summary', args=[session.slug])) self.assertEqual(response.status_code, 200) self.assertEqual(response.context['loggedin_user'].username, USERS[0]) self.assertEqual(response.context['session'].id, session.id) self.assertEqual(response.context['session'].slug, SESSION) self.assertEqual(len(response.context['jobs']), 104) self.assertEqual( response.context['next_session'], reverse('administrators:current_sessions') + '?page=1') self.assertEqual(response.context['back_to_word'], 'Current Sessions') jobs = response.context['jobs'] accepted_apps = [{ 'course': 'APBI 200 001', 'instructors': 'User10 Ins,User56 Ins', 'tas': 'User100 Test, 30.0, GTA I, $33.1, $248.25, International, Other Program - Master of Science in Statistics' }, { 'course': 'APBI 200 002', 'instructors': 'User42 Ins', 'tas': 'User70 Test, 65.0, GTA I, $33.1, $537.88, International, Doctor of Philosophy in Soil Science (PhD)' }] for i in range(2): job = jobs[i] course = '{0} {1} {2}'.format(job.course.code.name, job.course.number.name, job.course.section.name) self.assertEqual(course, accepted_apps[i]['course']) instructors = [ ins.first_name + ' ' + ins.last_name for ins in job.instructors.all() ] self.assertEqual(','.join(instructors), accepted_apps[i]['instructors']) tas = '' for app in job.accepted_apps: str = app.applicant.first_name + ' ' + app.applicant.last_name + ', ' str += '{}, '.format(app.accepted.assigned_hours) str += app.classification.name + ', ' str += '${}, '.format(app.classification.wage) str += '${}, '.format(app.salary) str += 'Domestic, ' if app.applicant.confidentiality.nationality == '0' else 'International, ' str += 'Other Program - ' + app.applicant.profile.program_others if app.applicant.profile.program.slug == 'other' else app.applicant.profile.program.name tas += str self.assertEqual(tas, accepted_apps[i]['tas']) self.delete_document(USERS[2], ['sin', 'study_permit'], 'international')
def summary_applicants(request, session_slug): ''' Display the summary of applicants in each session term ''' request = userApi.has_user_access(request, Role.INSTRUCTOR) session = adminApi.get_session(session_slug, 'slug') applicants = adminApi.get_applicants_in_session(session) total_applicants = applicants.count() if bool(request.GET.get('first_name')): applicants = applicants.filter( first_name__icontains=request.GET.get('first_name')) if bool(request.GET.get('last_name')): applicants = applicants.filter( last_name__icontains=request.GET.get('last_name')) if bool(request.GET.get('cwl')): applicants = applicants.filter( username__icontains=request.GET.get('cwl')) if bool(request.GET.get('student_number')): applicants = applicants.filter( profile__student_number__icontains=request.GET.get( 'student_number')) no_offers_applicants = [] for applicant in applicants: appls = applicant.application_set.filter( Q(job__session__year=session.year) & Q(job__session__term__code=session.term.code)) count_offered_apps = Count( 'applicationstatus', filter=Q(applicationstatus__assigned=ApplicationStatus.OFFERED)) offered_apps = appls.annotate( count_offered_apps=count_offered_apps).filter( count_offered_apps__gt=0) applicant.no_offers = False if len(offered_apps) == 0: no_offers_applicants.append(applicant) applicant.no_offers = True if bool(request.GET.get('no_offers')): applicants = no_offers_applicants page = request.GET.get('page', 1) paginator = Paginator(applicants, settings.PAGE_SIZE) try: applicants = paginator.page(page) except PageNotAnInteger: applicants = paginator.page(1) except EmptyPage: applicants = paginator.page(paginator.num_pages) for applicant in applicants: applicant = userApi.add_resume(applicant) apps = applicant.application_set.filter( Q(job__session__year=session.year) & Q(job__session__term__code=session.term.code)) applicant.apps = [] for app in apps: app = adminApi.add_app_info_into_application( app, ['applied', 'accepted', 'declined', 'cancelled']) app_obj = { 'course': app.job.course.code.name + ' ' + app.job.course.number.name + ' ' + app.job.course.section.name, 'applied': app.applied, 'accepted': None } if adminApi.check_valid_accepted_app_or_not(app): app_obj['accepted'] = app.accepted applicant.apps.append(app_obj) return render( request, 'instructors/jobs/summary_applicants.html', { 'loggedin_user': request.user, 'session': session, 'total_applicants': total_applicants, 'total_no_offers_applicants': len(no_offers_applicants), 'applicants': applicants, 'searched_total': len(applicants), 'next_second': request.session.get('next_second', None) })