class VisualizeStudentResult(TestCase): def setUp(self): self.person = PersonFactory() self.person.user.user_permissions.add( Permission.objects.get(codename="is_faculty_administrator")) self.student_performance = StudentPerformanceFactory() self.url = reverse('performance_student_result_admin', args=[self.student_performance.pk]) self.client.force_login(self.person.user) def test_user_not_logged(self): self.client.logout() response = self.client.get(self.url) self.assertRedirects(response, "/login/?next={}".format(self.url)) def test_user_has_not_permission(self): a_person = PersonFactory() self.client.force_login(a_person.user) response = self.client.get(self.url) self.assertEqual(response.status_code, ACCESS_DENIED) self.assertTemplateUsed(response, 'access_denied.html') def test_no_corresponding_student_performance(self): self.student_performance.delete() response = self.client.get(self.url) self.assertEqual(response.status_code, OK) self.assertTemplateUsed(response, 'admin/performance_result_admin.html') self.assertEqual(response.context['results'], None) self.assertEqual(response.context['creation_date'], None) self.assertEqual(response.context['update_date'], None) self.assertEqual(response.context['fetch_timed_out'], None) self.assertEqual(response.context['not_authorized_message'], None) def test_when_found_student_performance(self): response = self.client.get(self.url) self.assertEqual(response.status_code, OK) self.assertTemplateUsed(response, 'admin/performance_result_admin.html') self.assertJSONEqual(response.context['results'], json.dumps(self.student_performance.data)) self.assertEqual(response.context['creation_date'], self.student_performance.creation_date) self.assertEqual(response.context['update_date'], self.student_performance.update_date) self.assertEqual(response.context['fetch_timed_out'], False) self.assertEqual(response.context['not_authorized_message'], None) def test_with_not_authorized_message(self): self.student_performance.authorized = False self.student_performance.save() response = self.client.get(self.url) self.assertTemplateUsed(response, 'admin/performance_result_admin.html') self.assertEqual(response.status_code, OK) self.assertJSONEqual(response.context['results'], json.dumps(self.student_performance.data)) self.assertEqual(response.context['creation_date'], self.student_performance.creation_date) self.assertEqual(response.context['update_date'], self.student_performance.update_date) self.assertEqual(response.context['fetch_timed_out'], False) self.assertEqual( response.context['not_authorized_message'], _('performance_result_note_not_autorized').format( _(self.student_performance.session_locked)))
class VisualizeStudentPrograms(TestCase): def setUp(self): self.person = PersonFactory() self.person.user.user_permissions.add( Permission.objects.get(codename="is_faculty_administrator")) Group.objects.create(name="students") self.student = StudentFactory() self.student_performance = StudentPerformanceFactory( registration_id=self.student.registration_id, academic_year=2017) self.url = reverse('performance_student_programs_admin', args=[self.student.registration_id]) self.client.force_login(self.person.user) def test_user_not_logged(self): self.client.logout() response = self.client.get(self.url) self.assertRedirects(response, "/login/?next={}".format(self.url)) def test_user_has_not_permission(self): a_person = PersonFactory() self.client.force_login(a_person.user) response = self.client.get(self.url) self.assertEqual(response.status_code, ACCESS_DENIED) self.assertTemplateUsed(response, 'access_denied.html') def test_with_no_corresponding_student(self): self.student.delete() response = self.client.get(self.url) self.assertEqual(response.status_code, OK) self.assertTemplateUsed(response, 'admin/performance_home_admin.html') self.assertEqual(response.context['student'], None) self.assertEqual(response.context['programs'], None) self.assertEqual(response.context['registration_states_to_show'], offer_registration_state.STATES_TO_SHOW_ON_PAGE) def test_when_empty_programs_list(self): self.student_performance.delete() response = self.client.get(self.url) self.assertEqual(response.status_code, OK) self.assertTemplateUsed(response, 'admin/performance_home_admin.html') self.assertEqual(response.context['student'], self.student) self.assertEqual(response.context['programs'], []) self.assertEqual(response.context['registration_states_to_show'], offer_registration_state.STATES_TO_SHOW_ON_PAGE) def test_when_program(self): response = self.client.get(self.url) self.assertEqual(response.status_code, OK) self.assertTemplateUsed(response, 'admin/performance_home_admin.html') self.assertEqual(response.context['student'], self.student) self.assertEqual(response.context['programs'], [{ 'academic_year': '2017 - 2018', 'acronym': self.student_performance.acronym, 'offer_registration_state': 'CESSATION', 'pk': self.student_performance.pk, 'title': ' Master [120] en sciences informatiques, à finalité spécialisée ' }]) self.assertEqual(response.context['registration_states_to_show'], offer_registration_state.STATES_TO_SHOW_ON_PAGE)
class VisualizeStudentResult(TestCase): def setUp(self): self.person = PersonFactory() self.person.user.user_permissions.add( Permission.objects.get(codename="is_faculty_administrator")) self.student_performance = StudentPerformanceFactory(acronym='CHIM1BA') self.url = reverse('performance_student_result_admin', args=[self.student_performance.pk]) def tearDown(self): self.client.logout() def test_user_not_logged(self): response = self.client.get(self.url) self.assertRedirects(response, "/login/?next={}".format(self.url)) def test_user_has_not_permission(self): a_person = PersonFactory() self.client.force_login(a_person.user) response = self.client.get(self.url) self.assertEqual(response.status_code, ACCESS_DENIED) self.assertTemplateUsed(response, 'access_denied.html') def test_user_is_manager_wrong_program(self): a_person = PersonFactory() self.client.force_login(a_person.user) session = self.client.session session['is_faculty_manager'] = True session['managed_programs'] = json.dumps( { '2017': ['PHYS1BA', 'BIOL1BA'], '2018': ['PHYS1BA', 'BIOL1BA'] }, cls=DjangoJSONEncoder) session.save() response = self.client.get(self.url) self.assertEqual(response.status_code, ACCESS_DENIED) self.assertTemplateUsed(response, 'access_denied.html') def test_user_is_manager_program_ok(self): a_person = PersonFactory() a_student_performance = StudentPerformanceFactory(academic_year=2017, acronym='PHYS1BA') url = reverse('performance_student_result_admin', args=[a_student_performance.pk]) self.client.force_login(a_person.user) session = self.client.session session['is_faculty_manager'] = True session['managed_programs'] = json.dumps( { '2017': ['PHYS1BA', 'BIOL1BA'], '2018': ['PHYS1BA', 'BIOL1BA'] }, cls=DjangoJSONEncoder) session.save() response = self.client.get(url) self.assertEqual(response.status_code, OK) self.assertTemplateUsed(response, 'admin/performance_result_admin.html') def test_no_corresponding_student_performance(self): self.student_performance.delete() self.client.force_login(self.person.user) response = self.client.get(self.url) self.assertEqual(response.status_code, OK) self.assertTemplateUsed(response, 'admin/performance_result_admin.html') self.assertEqual(response.context['results'], None) self.assertEqual(response.context['creation_date'], None) self.assertEqual(response.context['update_date'], None) self.assertEqual(response.context['fetch_timed_out'], None) self.assertEqual(response.context['not_authorized_message'], None) def test_when_found_student_performance(self): self.client.force_login(self.person.user) response = self.client.get(self.url) self.assertEqual(response.status_code, OK) self.assertTemplateUsed(response, 'admin/performance_result_admin.html') self.assertJSONEqual(response.context['results'], json.dumps(self.student_performance.data)) self.assertEqual(response.context['creation_date'], self.student_performance.creation_date) self.assertEqual(response.context['update_date'], self.student_performance.update_date) self.assertEqual(response.context['fetch_timed_out'], False) self.assertEqual(response.context['not_authorized_message'], None) def test_with_not_authorized_message(self): self.student_performance.authorized = False self.student_performance.save() self.client.force_login(self.person.user) response = self.client.get(self.url) self.assertTemplateUsed(response, 'admin/performance_result_admin.html') self.assertEqual(response.status_code, OK) self.assertJSONEqual(response.context['results'], json.dumps(self.student_performance.data)) self.assertEqual(response.context['creation_date'], self.student_performance.creation_date) self.assertEqual(response.context['update_date'], self.student_performance.update_date) self.assertEqual(response.context['fetch_timed_out'], False) response_message = _( 'The publication of the notes from the %(session_month)s session was not authorized by our faculty.') \ % {"session_month": self.student_performance.get_session_locked_display()} self.assertEqual(response.context['not_authorized_message'], response_message)
class DisplayResultForSpecificStudentPerformanceTest(TestCase): def setUp(self): students_group = Group.objects.create(name="students") permission = Permission.objects.get(codename="is_student") students_group.permissions.add(permission) self.student = StudentFactory() self.student_performance = StudentPerformanceFactory( registration_id=self.student.registration_id) self.url = reverse('performance_student_result', args=[self.student_performance.pk]) self.client.force_login(self.student.person.user) def test_user_not_logged(self): self.client.logout() response = self.client.get(self.url, follow=True) self.assertRedirects(response, "/login/?next={}".format(self.url)) def test_user_not_a_student(self): a_person = PersonFactory() self.client.logout() self.client.force_login(a_person.user) response = self.client.get(self.url, follow=True) self.assertEqual(response.status_code, ACCESS_DENIED) self.assertTemplateUsed(response, 'access_denied.html') def test_multiple_students_objects_for_one_user(self): StudentFactory(person=self.student.person) response = self.client.get(self.url) self.assertTemplateUsed(response, 'dashboard.html') messages = list(response.context['messages']) self.assertEqual(len(messages), 1) self.assertEqual(messages[0].tags, 'error') self.assertEqual(messages[0].message, _('error_multiple_registration_id')) def test_when_none_student_performance(self): self.student_performance.delete() response = self.client.get(self.url) self.assertTemplateUsed(response, 'access_denied.html') self.assertEqual(response.status_code, ACCESS_DENIED) def test_when_trying_to_access_other_student_performance(self): an_other_student = StudentFactory() self.client.force_login(an_other_student.person.user) response = self.client.get(self.url) self.assertTemplateUsed(response, 'access_denied.html') self.assertEqual(response.status_code, ACCESS_DENIED) def test_with_performance_present(self): response = self.client.get(self.url) self.assertTemplateUsed(response, 'performance_result_student.html') self.assertEqual(response.status_code, OK) self.assertJSONEqual(response.context['results'], json.dumps(self.student_performance.data)) self.assertEqual(response.context['creation_date'], self.student_performance.creation_date) self.assertEqual(response.context['update_date'], self.student_performance.update_date) self.assertEqual(response.context['fetch_timed_out'], False) self.assertEqual(response.context['not_authorized_message'], None) def test_with_not_authorized_message(self): self.student_performance.authorized = False self.student_performance.save() response = self.client.get(self.url) self.assertTemplateUsed(response, 'performance_result_student.html') self.assertEqual(response.status_code, OK) self.assertJSONEqual(response.context['results'], json.dumps(self.student_performance.data)) self.assertEqual(response.context['creation_date'], self.student_performance.creation_date) self.assertEqual(response.context['update_date'], self.student_performance.update_date) self.assertEqual(response.context['fetch_timed_out'], False) self.assertEqual( response.context['not_authorized_message'], _('performance_result_note_not_autorized').format( _(self.student_performance.session_locked)))
class DisplayResultForSpecificStudentPerformanceTest(TestCase): def setUp(self): students_group = Group.objects.create(name="students") permission = Permission.objects.get(codename="is_student") students_group.permissions.add(permission) self.student = StudentFactory() self.student_performance = StudentPerformanceFactory( registration_id=self.student.registration_id) self.url = reverse('performance_student_result', args=[self.student_performance.pk]) self.client.force_login(self.student.person.user) def test_user_not_logged(self): self.client.logout() response = self.client.get(self.url, follow=True) self.assertRedirects(response, "/login/?next={}".format(self.url)) def test_user_not_a_student(self): a_person = PersonFactory() self.client.logout() self.client.force_login(a_person.user) response = self.client.get(self.url, follow=True) self.assertEqual(response.status_code, ACCESS_DENIED) self.assertTemplateUsed(response, 'access_denied.html') def test_multiple_students_objects_for_one_user(self): StudentFactory(person=self.student.person) msg = _( "A problem was detected with your registration : 2 registration id's are linked to your user. Please " "contact the registration departement (SIC). Thank you.") response = self.client.get(self.url) self.assertTemplateUsed(response, 'dashboard.html') messages = list(response.context['messages']) self.assertEqual(len(messages), 1) self.assertEqual(messages[0].tags, 'error') self.assertEqual(messages[0].message, msg) def test_when_none_student_performance(self): self.student_performance.delete() response = self.client.get(self.url) self.assertTemplateUsed(response, 'access_denied.html') self.assertEqual(response.status_code, ACCESS_DENIED) def test_when_trying_to_access_other_student_performance(self): an_other_student = StudentFactory() self.client.force_login(an_other_student.person.user) response = self.client.get(self.url) self.assertTemplateUsed(response, 'access_denied.html') self.assertEqual(response.status_code, ACCESS_DENIED) def test_with_performance_present(self): response = self.client.get(self.url) self.assertTemplateUsed(response, 'performance_result_student.html') self.assertEqual(response.status_code, OK) self.assertJSONEqual(response.context['results'], json.dumps(self.student_performance.data)) self.assertEqual(response.context['creation_date'], self.student_performance.creation_date) self.assertEqual(response.context['update_date'], self.student_performance.update_date) self.assertEqual(response.context['fetch_timed_out'], False) self.assertEqual(response.context['not_authorized_message'], None) def test_with_not_authorized_message(self): self.student_performance.authorized = False self.student_performance.save() response = self.client.get(self.url) self.assertTemplateUsed(response, 'performance_result_student.html') self.assertEqual(response.status_code, OK) self.assertJSONEqual(response.context['results'], json.dumps(self.student_performance.data)) self.assertEqual(response.context['creation_date'], self.student_performance.creation_date) self.assertEqual(response.context['update_date'], self.student_performance.update_date) self.assertEqual(response.context['fetch_timed_out'], False) response_message = _( 'The publication of the notes from the %(session_month)s session was not authorized by our faculty.') \ % {"session_month": self.student_performance.get_session_locked_display()} self.assertEqual(response.context['not_authorized_message'], response_message)