class PhdSupervisorReviewViewTestCase(TestCase): def setUp(self): self.factory = RequestFactory() today = datetime.date.today() self.current_academic_year = AcademicYearFactory( start_date=today, end_date=today.replace(year=today.year + 1), year=today.year) self.phd_supervisor = PersonFactory() self.assistant = AcademicAssistantFactory( supervisor=self.phd_supervisor) self.assistant_mandate = AssistantMandateFactory( academic_year=self.current_academic_year, assistant=self.assistant) self.assistant_mandate.state = assistant_mandate_state.PHD_SUPERVISOR self.assistant_mandate.save() self.review = ReviewFactory(reviewer=None, mandate=self.assistant_mandate, status=review_status.IN_PROGRESS) def test_generate_phd_supervisor_menu_tabs(self): self.client.force_login(self.phd_supervisor) # Review has not been completed -> supervisor can edit self.assertEqual( generate_phd_supervisor_menu_tabs(self.assistant_mandate, None), [{ 'item': assistant_mandate_state.PHD_SUPERVISOR, 'class': '', 'action': 'edit' }]) self.assertEqual( generate_phd_supervisor_menu_tabs( self.assistant_mandate, assistant_mandate_state.PHD_SUPERVISOR), [{ 'item': assistant_mandate_state.PHD_SUPERVISOR, 'class': 'active', 'action': 'edit' }]) # Review has been completed -> supervisor can only view his review self.review.status = review_status.DONE self.review.save() self.assistant_mandate.state = assistant_mandate_state.RESEARCH self.assistant_mandate.save() self.assertEqual( generate_phd_supervisor_menu_tabs(self.assistant_mandate, None), [{ 'item': assistant_mandate_state.PHD_SUPERVISOR, 'class': '', 'action': 'view' }]) self.assertEqual( generate_phd_supervisor_menu_tabs( self.assistant_mandate, assistant_mandate_state.PHD_SUPERVISOR), [{ 'item': assistant_mandate_state.PHD_SUPERVISOR, 'class': 'active', 'action': 'view' }])
class AssistantsListViewTestCase(TestCase): def setUp(self): self.factory = RequestFactory() self.client = Client() self.settings = SettingsFactory() today = datetime.date.today() self.current_academic_year = AcademicYearFactory( start_date=today, end_date=today.replace(year=today.year + 1), year=today.year) self.phd_supervisor = PersonFactory() self.assistant = AcademicAssistantFactory( supervisor=self.phd_supervisor) self.assistant_mandate = AssistantMandateFactory( academic_year=self.current_academic_year, assistant=self.assistant) self.assistant_mandate.state = assistant_mandate_state.PHD_SUPERVISOR self.assistant_mandate.save() self.review = ReviewFactory(reviewer=None, mandate=self.assistant_mandate, status=review_status.IN_PROGRESS) self.entity_version = EntityVersionFactory( entity_type=entity_type.INSTITUTE) self.mandate_entity = MandateEntityFactory( assistant_mandate=self.assistant_mandate, entity=self.entity_version.entity) def test_with_unlogged_user(self): response = self.client.get('/assistants/phd_supervisor/assistants/') self.assertEqual(response.status_code, HTTP_FOUND) def test_context_data_phd_supervisor_is_not_reviewer(self): self.client.force_login(self.phd_supervisor.user) response = self.client.get('/assistants/phd_supervisor/assistants/') self.assertEqual(response.status_code, HTTP_OK) self.assertEqual(response.context['current_reviewer'], find_by_person(self.phd_supervisor)) self.assertFalse(response.context['can_delegate']) entities_id = self.assistant_mandate.mandateentity_set.all().order_by( 'id').values_list('entity', flat=True) self.assistant_mandate.entities = find_versions_from_entites( entities_id, None) self.assistant_mandate.save() self.assertQuerysetEqual(response.context['object_list'], find_for_supervisor_for_academic_year( self.phd_supervisor, self.current_academic_year), transform=lambda x: x) def test_context_data_phd_supervisor_is_reviewer(self): self.reviewer = ReviewerFactory(role=reviewer_role.RESEARCH, entity=self.entity_version.entity, person=self.phd_supervisor) self.client.force_login(self.phd_supervisor.user) response = self.client.get('/assistants/phd_supervisor/assistants/') self.assertEqual(response.context['current_reviewer'], find_by_person(self.phd_supervisor)) self.assertTrue(response.context['can_delegate'])
class AssistantsListViewTestCase(TestCase): def setUp(self): self.factory = RequestFactory() self.client = Client() self.settings = SettingsFactory() today = datetime.date.today() self.current_academic_year = AcademicYearFactory(start_date=today, end_date=today.replace(year=today.year + 1), year=today.year) self.phd_supervisor = PersonFactory() self.assistant = AcademicAssistantFactory(supervisor=self.phd_supervisor) self.assistant_mandate = AssistantMandateFactory(academic_year=self.current_academic_year, assistant=self.assistant) self.assistant_mandate.state = assistant_mandate_state.PHD_SUPERVISOR self.assistant_mandate.save() self.review = ReviewFactory(reviewer=None, mandate=self.assistant_mandate, status=review_status.IN_PROGRESS) self.entity_version = EntityVersionFactory(entity_type=entity_type.INSTITUTE) self.mandate_entity = MandateEntityFactory(assistant_mandate=self.assistant_mandate, entity=self.entity_version.entity) def test_with_unlogged_user(self): response = self.client.get('/assistants/phd_supervisor/assistants/') self.assertEqual(response.status_code, HTTP_FOUND) def test_context_data_phd_supervisor_is_not_reviewer(self): self.client.force_login(self.phd_supervisor.user) response = self.client.get('/assistants/phd_supervisor/assistants/') self.assertEqual(response.status_code, HTTP_OK) self.assertEqual(response.context['current_reviewer'], find_by_person(self.phd_supervisor)) self.assertFalse(response.context['can_delegate']) entities_id = self.assistant_mandate.mandateentity_set.all().order_by('id').values_list('entity', flat=True) self.assistant_mandate.entities = find_versions_from_entites(entities_id, None) self.assistant_mandate.save() self.assertQuerysetEqual(response.context['object_list'], find_for_supervisor_for_academic_year(self.phd_supervisor, self.current_academic_year), transform = lambda x: x ) def test_context_data_phd_supervisor_is_reviewer(self): self.reviewer = ReviewerFactory(role=reviewer_role.RESEARCH, entity=self.entity_version.entity, person=self.phd_supervisor) self.client.force_login(self.phd_supervisor.user) response = self.client.get('/assistants/phd_supervisor/assistants/') self.assertEqual(response.context['current_reviewer'], find_by_person(self.phd_supervisor)) self.assertTrue(response.context['can_delegate'])
class TestUsersAccess(TestCase): def setUp(self): self.factory = RequestFactory() self.client = Client() self.settings = SettingsFactory() today = datetime.date.today() self.current_academic_year = AcademicYearFactory(start_date=today, end_date=today.replace(year=today.year + 1), year=today.year) self.phd_supervisor = PersonFactory() self.assistant = AcademicAssistantFactory(supervisor=self.phd_supervisor) self.assistant_mandate = AssistantMandateFactory(academic_year=self.current_academic_year, assistant=self.assistant) self.assistant_mandate.state = assistant_mandate_state.PHD_SUPERVISOR self.assistant_mandate.save() self.review = ReviewFactory(reviewer=None, mandate=self.assistant_mandate, status=review_status.IN_PROGRESS) self.entity = EntityFactory() self.entity_version = EntityVersionFactory(entity=self.entity, entity_type=entity_type.INSTITUTE) self.mandate_entity = MandateEntityFactory(assistant_mandate=self.assistant_mandate, entity=self.entity) self.reviewer = ReviewerFactory(role=reviewer_role.RESEARCH, entity=self.entity_version.entity) def test_user_is_reviewer_and_procedure_is_open(self): auth.signals.user_logged_in.disconnect(auth.models.update_last_login) self.client.force_login(self.reviewer) self.assertTrue(user_is_reviewer_and_procedure_is_open(self.reviewer.person.user)) def test_user_is_not_reviewer_and_procedure_is_open(self): auth.signals.user_logged_in.disconnect(auth.models.update_last_login) self.client.force_login(self.assistant) self.assertFalse(user_is_reviewer_and_procedure_is_open(self.assistant.person.user)) def test_user_is_phd_supervisor_and_procedure_is_open(self): auth.signals.user_logged_in.disconnect(auth.models.update_last_login) self.client.force_login(self.phd_supervisor) self.assertTrue(user_is_phd_supervisor_and_procedure_is_open(self.phd_supervisor.user)) def test_user_is_not_phd_supervisor_and_procedure_is_open(self): auth.signals.user_logged_in.disconnect(auth.models.update_last_login) self.client.force_login(self.assistant) self.assertFalse(user_is_phd_supervisor_and_procedure_is_open(self.assistant.person.user))
class TestUsersAccess(TestCase): def setUp(self): self.factory = RequestFactory() self.client = Client() self.settings = SettingsFactory() today = datetime.date.today() self.current_academic_year = AcademicYearFactory(start_date=today, end_date=today.replace(year=today.year + 1), year=today.year) self.phd_supervisor = PersonFactory() self.assistant = AcademicAssistantFactory(supervisor=self.phd_supervisor) self.assistant_mandate = AssistantMandateFactory(academic_year=self.current_academic_year, assistant=self.assistant) self.assistant_mandate.state = assistant_mandate_state.PHD_SUPERVISOR self.assistant_mandate.save() self.review = ReviewFactory(reviewer=None, mandate=self.assistant_mandate, status=review_status.IN_PROGRESS) self.entity = EntityFactory() self.entity_version = EntityVersionFactory(entity=self.entity, entity_type=entity_type.INSTITUTE) self.mandate_entity = MandateEntityFactory(assistant_mandate=self.assistant_mandate, entity=self.entity) self.reviewer = ReviewerFactory(role=reviewer_role.RESEARCH, entity=self.entity_version.entity) def test_user_is_reviewer_and_procedure_is_open(self): auth.signals.user_logged_in.disconnect(auth.models.update_last_login) self.client.force_login(self.reviewer) self.assertTrue(user_is_reviewer_and_procedure_is_open(self.reviewer.person.user)) def test_user_is_not_reviewer_and_procedure_is_open(self): auth.signals.user_logged_in.disconnect(auth.models.update_last_login) self.client.force_login(self.assistant) self.assertFalse(user_is_reviewer_and_procedure_is_open(self.assistant.person.user)) def test_user_is_phd_supervisor_and_procedure_is_open(self): auth.signals.user_logged_in.disconnect(auth.models.update_last_login) self.client.force_login(self.phd_supervisor) self.assertTrue(user_is_phd_supervisor_and_procedure_is_open(self.phd_supervisor.user)) def test_user_is_not_phd_supervisor_and_procedure_is_open(self): auth.signals.user_logged_in.disconnect(auth.models.update_last_login) self.client.force_login(self.assistant) self.assertFalse(user_is_phd_supervisor_and_procedure_is_open(self.assistant.person.user))
class AssistantFormViewTestCase(TestCase): def setUp(self): self.factory = RequestFactory() self.settings = SettingsFactory() today = datetime.date.today() self.current_academic_year = AcademicYearFactory( start_date=today, end_date=today.replace(year=today.year + 1), year=today.year) self.assistant_mandate = AssistantMandateFactory( academic_year=self.current_academic_year) self.assistant_mandate.state = assistant_mandate_state.TRTS self.assistant_mandate.save() LearningUnitYearFactory(academic_year=self.current_academic_year, acronym="LBIR1210") LearningUnitYearFactory(academic_year=self.current_academic_year, acronym="LBIR1211") def test_assistant_form_part4_edit_view_basic(self): self.client.force_login(self.assistant_mandate.assistant.person.user) request = self.factory.get(reverse('form_part4_edit')) request.user = self.assistant_mandate.assistant.person.user with self.assertTemplateUsed('assistant_form_part4.html'): response = form_part4_edit(request) self.assertEqual(response.status_code, 200) def test_get_learning_units_year(self): self.client.force_login(self.assistant_mandate.assistant.person.user) response = self.client.generic( method='get', path= '/assistants/assistant/form/part2/get_learning_units_year/?term=LBIR1211', HTTP_X_REQUESTED_WITH='XMLHttpRequest') data = json.loads(response.content.decode('utf-8')) self.assertEqual(data[0]['value'], 'LBIR1211') self.assertEqual(len(data), 1) response = self.client.generic( method='get', path= '/assistants/assistant/form/part2/get_learning_units_year/?term=LBIR12', HTTP_X_REQUESTED_WITH='XMLHttpRequest') data = json.loads(response.content.decode('utf-8')) self.assertEqual(len(data), 2)
class AssistantFormViewTestCase(TestCase): def setUp(self): self.factory = RequestFactory() self.client = Client() self.settings = SettingsFactory() today = datetime.date.today() self.current_academic_year = AcademicYearFactory( start_date=today.replace(year=today.year-1), end_date=today.replace(year=today.year+1), year=today.year-1, ) self.assistant_mandate = AssistantMandateFactory(academic_year=self.current_academic_year) self.assistant_mandate.state = assistant_mandate_state.TRTS self.assistant_mandate.save() LearningUnitYearFactory(academic_year=self.current_academic_year, acronym="LBIR1210") LearningUnitYearFactory(academic_year=self.current_academic_year, acronym="LBIR1211") def test_assistant_form_part4_edit_view_basic(self): self.client.force_login(self.assistant_mandate.assistant.person.user) response = self.client.get('/assistants/assistant/form/part4/edit/') self.assertEqual(response.status_code, HTTP_OK) def test_get_learning_units_year(self): self.client.force_login(self.assistant_mandate.assistant.person.user) response = self.client.generic(method='get', path='/assistants/assistant/form/part2/get_learning_units_year/?term=LBIR1211', HTTP_X_REQUESTED_WITH='XMLHttpRequest') data = json.loads(response.content.decode('utf-8')) self.assertEqual(data[0]['value'], 'LBIR1211') self.assertEqual(len(data), 1) response = self.client.generic(method='get', path='/assistants/assistant/form/part2/get_learning_units_year/?term=LBIR12', HTTP_X_REQUESTED_WITH='XMLHttpRequest') data = json.loads(response.content.decode('utf-8')) self.assertEqual(len(data), 2)
class TestMandateEntity(TestCase): def setUp(self): self.factory = RequestFactory() self.client = Client() self.manager = ManagerFactory() self.settings = SettingsFactory() self.client.force_login(self.manager.person.user) self.assistant = AcademicAssistantFactory() self.assistant_mandate = AssistantMandateFactory( state=assistant_mandate_state.TRTS, assistant=self.assistant, assistant_type=assistant_type.ASSISTANT) self.assistant2 = AcademicAssistantFactory() self.assistant_mandate2 = AssistantMandateFactory( state=assistant_mandate_state.SUPERVISION, assistant=self.assistant2, assistant_type=assistant_type.TEACHING_ASSISTANT) self.entity1 = EntityFactory() self.entity_version1 = EntityVersionFactory( entity=self.entity1, entity_type=entity_type.SECTOR) self.entity2 = EntityFactory() self.entity_version2 = EntityVersionFactory( entity=self.entity2, entity_type=entity_type.FACULTY) self.entity3 = EntityFactory() self.entity_version3 = EntityVersionFactory( entity=self.entity3, entity_type=entity_type.INSTITUTE) self.entity4 = EntityFactory() self.entity_version4 = EntityVersionFactory( entity=self.entity4, parent=self.entity2, entity_type=entity_type.SCHOOL) self.mandate_entity1 = MandateEntityFactory( assistant_mandate=self.assistant_mandate, entity=self.entity1) self.mandate_entity2 = MandateEntityFactory( assistant_mandate=self.assistant_mandate, entity=self.entity2) self.mandate_entity3 = MandateEntityFactory( assistant_mandate=self.assistant_mandate, entity=self.entity3) self.mandate_entity4 = MandateEntityFactory( assistant_mandate=self.assistant_mandate2, entity=self.entity1) self.mandate_entity5 = MandateEntityFactory( assistant_mandate=self.assistant_mandate2, entity=self.entity2) self.reviewer1 = ReviewerFactory(entity=self.entity3, role=reviewer_role.RESEARCH) self.reviewer2 = ReviewerFactory(entity=self.entity2, role=reviewer_role.SUPERVISION) self.reviewer3 = ReviewerFactory(entity=self.entity1, role=reviewer_role.VICE_RECTOR) self.reviewer4 = ReviewerFactory(entity=None, role=reviewer_role.PHD_SUPERVISOR) def test_mandate_can_go_backward(self): self.assertTrue(mandate_can_go_backward(self.assistant_mandate)) self.assistant_mandate.state = assistant_mandate_state.RESEARCH self.assistant_mandate.save() self.review1 = ReviewFactory(reviewer=self.reviewer1, mandate=self.assistant_mandate, status=review_status.IN_PROGRESS) self.assertFalse(mandate_can_go_backward(self.assistant_mandate)) self.review1.delete() self.assistant_mandate.state = assistant_mandate_state.TO_DO self.assistant_mandate.save() self.assertFalse(mandate_can_go_backward(self.assistant_mandate)) def test_assistant_mandate_step_back_from_assistant_to_beginning(self): self.assistant_mandate.state = assistant_mandate_state.TRTS self.assistant_mandate.save() self.client.post(reverse('assistant_mandate_step_back'), {'mandate_id': self.assistant_mandate.id}) self.assistant_mandate.refresh_from_db() self.assertEqual(self.assistant_mandate.state, assistant_mandate_state.TO_DO) def test_assistant_mandate_step_back_from_phd_supervisor_to_assistant( self): self.assistant_mandate.state = assistant_mandate_state.PHD_SUPERVISOR self.assistant_mandate.save() self.client.post(reverse('assistant_mandate_step_back'), {'mandate_id': self.assistant_mandate.id}) self.assistant_mandate.refresh_from_db() self.assertEqual(self.assistant_mandate.state, assistant_mandate_state.TRTS) def test_assistant_mandate_step_back_from_institute_president_to_php_supervisor( self): self.assistant.supervisor = PersonFactory() self.assistant.save() self.review1 = ReviewFactory(reviewer=self.reviewer1, mandate=self.assistant_mandate, status=review_status.DONE) self.review2 = ReviewFactory(reviewer=None, mandate=self.assistant_mandate, status=review_status.DONE) self.assistant_mandate.state = assistant_mandate_state.RESEARCH self.assistant_mandate.save() self.client.post(reverse('assistant_mandate_step_back'), {'mandate_id': self.assistant_mandate.id}) self.assistant_mandate.refresh_from_db() self.assertEqual(self.assistant_mandate.state, assistant_mandate_state.PHD_SUPERVISOR) def test_assistant_mandate_step_back_from_institute_president_to_assistant( self): # Test if assistant does not have a phd supervisor self.assistant_mandate.state = assistant_mandate_state.RESEARCH self.assistant_mandate.save() self.assistant.supervisor = None self.assistant.save() self.client.post(reverse('assistant_mandate_step_back'), {'mandate_id': self.assistant_mandate.id}) self.assistant_mandate.refresh_from_db() self.assertEqual(self.assistant_mandate.state, assistant_mandate_state.TRTS) def test_assistant_mandate_step_back_from_dean_of_faculty_to_institute_president( self): self.research_review = ReviewFactory(mandate=self.assistant_mandate, reviewer=self.reviewer1) self.assistant_mandate.state = assistant_mandate_state.SUPERVISION self.assistant_mandate.save() self.client.post(reverse('assistant_mandate_step_back'), {'mandate_id': self.assistant_mandate.id}) self.assistant_mandate.refresh_from_db() self.assertEqual(self.assistant_mandate.state, assistant_mandate_state.RESEARCH) def test_assistant_mandate_step_back_from_vice_rector_to_dean_of_faculty( self): self.supervision_review = ReviewFactory(mandate=self.assistant_mandate, reviewer=self.reviewer2) self.assistant_mandate.state = assistant_mandate_state.VICE_RECTOR self.assistant_mandate.save() self.client.post(reverse('assistant_mandate_step_back'), {'mandate_id': self.assistant_mandate.id}) self.assistant_mandate.refresh_from_db() self.assertEqual(self.assistant_mandate.state, assistant_mandate_state.SUPERVISION) def test_assistant_mandate_step_back_from_dean_of_faculty_to_assistant( self): # Test if assistant is teaching assistant self.research_review = ReviewFactory(mandate=self.assistant_mandate, reviewer=self.reviewer1) self.assistant_mandate.state = assistant_mandate_state.SUPERVISION self.assistant_mandate.save() self.client.post(reverse('assistant_mandate_step_back'), {'mandate_id': self.assistant_mandate2.id}) self.assistant_mandate2.refresh_from_db() self.assertEqual(self.assistant_mandate2.state, assistant_mandate_state.TRTS) def test_assistant_mandate_step_back_from_done_to_vice_rector(self): self.review4 = ReviewFactory(reviewer=self.reviewer3, mandate=self.assistant_mandate2, status=review_status.DONE) self.review5 = ReviewFactory(reviewer=self.reviewer2, mandate=self.assistant_mandate2, status=review_status.DONE) self.assistant_mandate2.state = assistant_mandate_state.DONE self.assistant_mandate2.save() self.client.post(reverse('assistant_mandate_step_back'), {'mandate_id': self.assistant_mandate2.id}) self.assistant_mandate2.refresh_from_db() self.assertEqual(self.assistant_mandate2.state, assistant_mandate_state.VICE_RECTOR) def test_add_actions_to_mandates_list(self): self.client.force_login(self.reviewer1.person.user) response = self.client.get('/assistants/reviewer/') context = add_actions_to_mandates_list(response.context, self.reviewer1) for mandate in context['object_list']: if mandate.id == self.assistant_mandate.id: self.assertFalse(mandate.view) self.assertFalse(mandate.edit) self.client.force_login(self.reviewer2.person.user) response = self.client.get('/assistants/reviewer/') context = add_actions_to_mandates_list(response.context, self.reviewer2) for mandate in context['object_list']: if mandate.id == self.assistant_mandate2.id: self.assertTrue(mandate.view) self.assertTrue(mandate.edit)
class PhdSupervisorReviewViewTestCase(TestCase): def setUp(self): self.factory = RequestFactory() self.client = Client() self.settings = SettingsFactory() today = datetime.date.today() self.current_academic_year = AcademicYearFactory( start_date=today, end_date=today.replace(year=today.year + 1), year=today.year) self.phd_supervisor = PersonFactory() self.assistant = AcademicAssistantFactory( supervisor=self.phd_supervisor) self.assistant_mandate = AssistantMandateFactory( academic_year=self.current_academic_year, assistant=self.assistant) self.assistant_mandate.state = assistant_mandate_state.PHD_SUPERVISOR self.assistant_mandate.save() self.review = ReviewFactory(reviewer=None, mandate=self.assistant_mandate, status=review_status.IN_PROGRESS) self.entity1 = EntityFactory() self.entity_version1 = EntityVersionFactory( entity=self.entity1, entity_type=entity_type.INSTITUTE) self.mandate_entity = MandateEntityFactory( assistant_mandate=self.assistant_mandate, entity=self.entity1) def test_generate_phd_supervisor_menu_tabs(self): self.client.force_login(self.phd_supervisor) # Review has not been completed -> supervisor can edit self.assertEqual( generate_phd_supervisor_menu_tabs(self.assistant_mandate, None), [{ 'item': assistant_mandate_state.PHD_SUPERVISOR, 'class': '', 'action': 'edit' }]) self.assertEqual( generate_phd_supervisor_menu_tabs( self.assistant_mandate, assistant_mandate_state.PHD_SUPERVISOR), [{ 'item': assistant_mandate_state.PHD_SUPERVISOR, 'class': 'active', 'action': 'edit' }]) # Review has been completed -> supervisor can only view his review self.review.status = review_status.DONE self.review.save() self.assistant_mandate.state = assistant_mandate_state.RESEARCH self.assistant_mandate.save() self.assertEqual( generate_phd_supervisor_menu_tabs(self.assistant_mandate, None), [{ 'item': assistant_mandate_state.PHD_SUPERVISOR, 'class': '', 'action': 'view' }]) self.assertEqual( generate_phd_supervisor_menu_tabs( self.assistant_mandate, assistant_mandate_state.PHD_SUPERVISOR), [{ 'item': assistant_mandate_state.PHD_SUPERVISOR, 'class': 'active', 'action': 'view' }]) def test_pst_form_view(self): self.client.force_login(self.phd_supervisor.user) response = self.client.post('/assistants/phd_supervisor/pst_form/', {'mandate_id': self.assistant_mandate.id}) self.assertEqual(response.status_code, HTTP_OK) def test_review_view(self): self.client.force_login(self.phd_supervisor.user) response = self.client.post('/assistants/phd_supervisor/review/view/', {'mandate_id': self.assistant_mandate.id}) self.assertEqual(response.status_code, HTTP_OK) def test_review_edit(self): self.client.force_login(self.phd_supervisor.user) response = self.client.post('/assistants/phd_supervisor/review/edit/', {'mandate_id': self.assistant_mandate.id}) self.assertEqual(response.status_code, HTTP_OK) self.review.status = review_status.DONE self.review.save() response = self.client.post('/assistants/phd_supervisor/review/edit/', {'mandate_id': self.assistant_mandate.id}) self.assertEqual(response.status_code, 302) def test_review_save(self): self.client.force_login(self.phd_supervisor.user) response = self.client.post( '/assistants/phd_supervisor/review/save/', { 'mandate_id': self.assistant_mandate.id, 'review_id': self.review.id }) self.assertEqual(response.status_code, HTTP_OK) def test_validate_review_and_update_mandate(self): validate_review_and_update_mandate(self.review, self.assistant_mandate) self.assertEqual(self.review.status, review_status.DONE) self.assertEqual(self.assistant_mandate.state, assistant_mandate_state.RESEARCH) self.entity_version1.entity_type = entity_type.POLE self.entity_version1.save() validate_review_and_update_mandate(self.review, self.assistant_mandate) self.assertEqual(self.assistant_mandate.state, assistant_mandate_state.RESEARCH) self.entity_version1.entity_type = entity_type.FACULTY self.entity_version1.save() validate_review_and_update_mandate(self.review, self.assistant_mandate) self.assertEqual(self.assistant_mandate.state, assistant_mandate_state.SUPERVISION)
class PhdSupervisorReviewViewTestCase(TestCase): def setUp(self): self.factory = RequestFactory() self.client = Client() self.settings = SettingsFactory() today = datetime.date.today() self.current_academic_year = AcademicYearFactory(start_date=today, end_date=today.replace(year=today.year + 1), year=today.year) self.phd_supervisor = PersonFactory() self.assistant = AcademicAssistantFactory(supervisor=self.phd_supervisor) self.assistant_mandate = AssistantMandateFactory(academic_year=self.current_academic_year, assistant=self.assistant) self.assistant_mandate.state = assistant_mandate_state.PHD_SUPERVISOR self.assistant_mandate.save() self.review = ReviewFactory(reviewer=None, mandate=self.assistant_mandate, status=review_status.IN_PROGRESS) self.entity1 = EntityFactory() self.entity_version1 = EntityVersionFactory(entity=self.entity1, entity_type=entity_type.INSTITUTE) self.mandate_entity = MandateEntityFactory(assistant_mandate=self.assistant_mandate, entity=self.entity1) def test_generate_phd_supervisor_menu_tabs(self): self.client.force_login(self.phd_supervisor) # Review has not been completed -> supervisor can edit self.assertEqual(generate_phd_supervisor_menu_tabs(self.assistant_mandate, None), [{'item': assistant_mandate_state.PHD_SUPERVISOR, 'class': '', 'action': 'edit'}]) self.assertEqual(generate_phd_supervisor_menu_tabs(self.assistant_mandate, assistant_mandate_state.PHD_SUPERVISOR), [{'item': assistant_mandate_state.PHD_SUPERVISOR, 'class': 'active', 'action': 'edit'}]) # Review has been completed -> supervisor can only view his review self.review.status = review_status.DONE self.review.save() self.assistant_mandate.state = assistant_mandate_state.RESEARCH self.assistant_mandate.save() self.assertEqual(generate_phd_supervisor_menu_tabs(self.assistant_mandate, None), [{'item': assistant_mandate_state.PHD_SUPERVISOR, 'class': '', 'action': 'view'}]) self.assertEqual(generate_phd_supervisor_menu_tabs(self.assistant_mandate, assistant_mandate_state.PHD_SUPERVISOR), [{'item': assistant_mandate_state.PHD_SUPERVISOR, 'class': 'active', 'action': 'view'}]) def test_pst_form_view(self): self.client.force_login(self.phd_supervisor.user) response = self.client.post('/assistants/phd_supervisor/pst_form/', {'mandate_id': self.assistant_mandate.id}) self.assertEqual(response.status_code, HTTP_OK) def test_review_view(self): self.client.force_login(self.phd_supervisor.user) response = self.client.post('/assistants/phd_supervisor/review/view/', {'mandate_id': self.assistant_mandate.id}) self.assertEqual(response.status_code, HTTP_OK) def test_review_edit(self): self.client.force_login(self.phd_supervisor.user) response = self.client.post('/assistants/phd_supervisor/review/edit/', {'mandate_id': self.assistant_mandate.id}) self.assertEqual(response.status_code, HTTP_OK) self.review.status = review_status.DONE self.review.save() response = self.client.post('/assistants/phd_supervisor/review/edit/',{'mandate_id': self.assistant_mandate.id}) self.assertEqual(response.status_code, HTTP_FOUND) def test_review_save(self): self.client.force_login(self.phd_supervisor.user) response = self.client.post('/assistants/phd_supervisor/review/save/', {'mandate_id': self.assistant_mandate.id, 'review_id': self.review.id }) self.assertEqual(response.status_code, HTTP_OK) def test_validate_review_and_update_mandate(self): validate_review_and_update_mandate(self.review, self.assistant_mandate) self.assertEqual(self.review.status, review_status.DONE) self.assertEqual(self.assistant_mandate.state, assistant_mandate_state.RESEARCH) self.entity_version1.entity_type = entity_type.POLE self.entity_version1.save() validate_review_and_update_mandate(self.review, self.assistant_mandate) self.assertEqual(self.assistant_mandate.state, assistant_mandate_state.RESEARCH) self.entity_version1.entity_type = entity_type.FACULTY self.entity_version1.save() validate_review_and_update_mandate(self.review, self.assistant_mandate) self.assertEqual(self.assistant_mandate.state, assistant_mandate_state.SUPERVISION)
class ReviewerReviewViewTestCase(TestCase): def setUp(self): self.factory = RequestFactory() self.client = Client() self.settings = SettingsFactory() today = datetime.date.today() self.current_academic_year = AcademicYearFactory( start_date=today, end_date=today.replace(year=today.year + 1), year=today.year) self.current_academic_year.save() self.phd_supervisor = PersonFactory() self.assistant = AcademicAssistantFactory( supervisor=self.phd_supervisor) self.assistant_mandate = AssistantMandateFactory( academic_year=self.current_academic_year, assistant=self.assistant, state=assistant_mandate_state.RESEARCH) self.assistant_mandate2 = AssistantMandateFactory( academic_year=self.current_academic_year, assistant=self.assistant, state=assistant_mandate_state.RESEARCH) self.phd_supervisor_review = ReviewFactory( reviewer=None, mandate=self.assistant_mandate, status=review_status.DONE) self.entity_version = EntityVersionFactory( entity_type=entity_type.INSTITUTE) self.entity_mandate = MandateEntityFactory( assistant_mandate=self.assistant_mandate, entity=self.entity_version.entity) self.entity_mandate2 = MandateEntityFactory( assistant_mandate=self.assistant_mandate2, entity=self.entity_version.entity) self.reviewer = ReviewerFactory(role=reviewer_role.RESEARCH, entity=self.entity_version.entity) self.review = ReviewFactory(reviewer=self.reviewer, mandate=self.assistant_mandate, status=review_status.IN_PROGRESS) self.entity_version2 = EntityVersionFactory( entity_type=entity_type.FACULTY) self.entity_mandate2 = MandateEntityFactory( assistant_mandate=self.assistant_mandate, entity=self.entity_version2.entity) self.reviewer2 = ReviewerFactory(role=reviewer_role.SUPERVISION, entity=self.entity_version2.entity) self.entity_version3 = EntityVersionFactory( entity_type=entity_type.SECTOR) self.entity_mandate3 = MandateEntityFactory( assistant_mandate=self.assistant_mandate, entity=self.entity_version3.entity) self.reviewer3 = ReviewerFactory(role=reviewer_role.VICE_RECTOR, entity=self.entity_version3.entity) def test_pst_form_view(self): self.client.force_login(self.reviewer.person.user) response = self.client.post('/assistants/reviewer/pst_form/', {'mandate_id': self.assistant_mandate.id}) self.assertEqual(response.status_code, HTTP_OK) def test_review_edit(self): self.client.force_login(self.reviewer.person.user) response = self.client.post('/assistants/reviewer/review/edit/', {'mandate_id': self.assistant_mandate2.id}) self.assertEqual(response.status_code, HTTP_OK) def test_review_save(self): self.client.force_login(self.reviewer.person.user) response = self.client.post('/assistants/reviewer/review/save/', { 'mandate_id': self.assistant_mandate.id, 'review_id': self.review.id }) self.assertEqual(response.status_code, HTTP_OK) def test_validate_review_and_update_mandate(self): validate_review_and_update_mandate(self.review, self.assistant_mandate) self.assertEqual(self.review.status, review_status.DONE) self.assertEqual(self.assistant_mandate.state, assistant_mandate_state.SUPERVISION) self.review2 = ReviewFactory(reviewer=self.reviewer2, mandate=self.assistant_mandate, status=review_status.IN_PROGRESS) validate_review_and_update_mandate(self.review2, self.assistant_mandate) self.assertEqual(self.review2.status, review_status.DONE) self.assertEqual(self.assistant_mandate.state, assistant_mandate_state.VICE_RECTOR) self.review3 = ReviewFactory(reviewer=self.reviewer3, mandate=self.assistant_mandate, status=review_status.IN_PROGRESS) validate_review_and_update_mandate(self.review3, self.assistant_mandate) self.assertEqual(self.review3.status, review_status.DONE) self.assertEqual(self.assistant_mandate.state, assistant_mandate_state.DONE) def test_review_view(self): self.client.force_login(self.reviewer.person.user) response = self.client.post( '/assistants/reviewer/review/view/', { 'mandate_id': self.assistant_mandate.id, 'role': reviewer_role.PHD_SUPERVISOR }) self.assertEqual(response.status_code, HTTP_OK) response = self.client.post( '/assistants/reviewer/review/view/', { 'mandate_id': self.assistant_mandate.id, 'role': reviewer_role.RESEARCH }) self.assertEqual(response.status_code, HTTP_OK) def test_generate_phd_supervisor_menu_tabs(self): self.client.force_login(self.reviewer.person.user) self.assertEqual([{ 'action': 'view', 'class': '', 'item': 'PHD_SUPERVISOR' }, { 'item': 'RESEARCH', 'class': '', 'action': 'edit' }], generate_reviewer_menu_tabs(reviewer_role.RESEARCH, self.assistant_mandate, None)) self.review.status = review_status.DONE self.review.save() self.assistant_mandate.state = assistant_mandate_state.SUPERVISION self.assistant_mandate.save() self.review2 = ReviewFactory(reviewer=self.reviewer2, mandate=self.assistant_mandate, status=review_status.IN_PROGRESS) self.assertEqual([{ 'action': 'view', 'class': '', 'item': 'PHD_SUPERVISOR' }, { 'item': 'RESEARCH', 'class': 'active', 'action': 'view' }], generate_reviewer_menu_tabs( reviewer_role.RESEARCH, self.assistant_mandate, assistant_mandate_state.RESEARCH)) self.assertEqual([{ 'action': 'view', 'class': '', 'item': 'PHD_SUPERVISOR' }, { 'item': 'RESEARCH', 'class': '', 'action': 'view' }, { 'item': 'SUPERVISION', 'class': '', 'action': 'edit' }], generate_reviewer_menu_tabs(reviewer_role.SUPERVISION, self.assistant_mandate, None))
class TestMandateEntity(TestCase): def setUp(self): self.factory = RequestFactory() self.client = Client() self.manager = ManagerFactory() self.settings = SettingsFactory() self.client.force_login(self.manager.person.user) self.assistant = AcademicAssistantFactory() self.assistant_mandate = AssistantMandateFactory( state=assistant_mandate_state.TRTS, assistant=self.assistant, assistant_type=assistant_type.ASSISTANT ) self.assistant2 = AcademicAssistantFactory() self.assistant_mandate2 = AssistantMandateFactory( state=assistant_mandate_state.SUPERVISION, assistant=self.assistant2, assistant_type=assistant_type.TEACHING_ASSISTANT ) self.entity1 = EntityFactory() self.entity_version1 = EntityVersionFactory(entity=self.entity1, entity_type=entity_type.SECTOR) self.entity2 = EntityFactory() self.entity_version2 = EntityVersionFactory(entity=self.entity2, entity_type=entity_type.FACULTY) self.entity3 = EntityFactory() self.entity_version3 = EntityVersionFactory(entity=self.entity3, entity_type=entity_type.INSTITUTE) self.entity4 = EntityFactory() self.entity_version4 = EntityVersionFactory( entity=self.entity4, parent=self.entity2, entity_type=entity_type.SCHOOL) self.mandate_entity1 = MandateEntityFactory(assistant_mandate=self.assistant_mandate, entity=self.entity1) self.mandate_entity2 = MandateEntityFactory(assistant_mandate=self.assistant_mandate, entity=self.entity2) self.mandate_entity3 = MandateEntityFactory(assistant_mandate=self.assistant_mandate, entity=self.entity3) self.mandate_entity4 = MandateEntityFactory(assistant_mandate=self.assistant_mandate2, entity=self.entity1) self.mandate_entity5 = MandateEntityFactory(assistant_mandate=self.assistant_mandate2, entity=self.entity2) self.reviewer1 = ReviewerFactory(entity=self.entity3, role=reviewer_role.RESEARCH) self.reviewer2 = ReviewerFactory(entity=self.entity2, role=reviewer_role.SUPERVISION) self.reviewer3 = ReviewerFactory(entity=self.entity1, role=reviewer_role.VICE_RECTOR) self.reviewer4 = ReviewerFactory(entity=None, role=reviewer_role.PHD_SUPERVISOR) def test_mandate_can_go_backward(self): self.assertTrue(mandate_can_go_backward(self.assistant_mandate)) self.assistant_mandate.state = assistant_mandate_state.RESEARCH self.assistant_mandate.save() self.review1 = ReviewFactory( reviewer=self.reviewer1, mandate=self.assistant_mandate, status=review_status.IN_PROGRESS ) self.assertFalse(mandate_can_go_backward(self.assistant_mandate)) self.review1.delete() self.assistant_mandate.state = assistant_mandate_state.TO_DO self.assistant_mandate.save() self.assertFalse(mandate_can_go_backward(self.assistant_mandate)) def test_assistant_mandate_step_back_from_assistant_to_beginning(self): self.assistant_mandate.state = assistant_mandate_state.TRTS self.assistant_mandate.save() self.client.post(reverse('assistant_mandate_step_back'), {'mandate_id': self.assistant_mandate.id}) self.assistant_mandate.refresh_from_db() self.assertEqual(self.assistant_mandate.state, assistant_mandate_state.TO_DO) def test_assistant_mandate_step_back_from_phd_supervisor_to_assistant(self): self.assistant_mandate.state = assistant_mandate_state.PHD_SUPERVISOR self.assistant_mandate.save() self.client.post(reverse('assistant_mandate_step_back'), {'mandate_id': self.assistant_mandate.id}) self.assistant_mandate.refresh_from_db() self.assertEqual(self.assistant_mandate.state, assistant_mandate_state.TRTS) def test_assistant_mandate_step_back_from_institute_president_to_php_supervisor(self): self.assistant.supervisor = PersonFactory() self.assistant.save() self.review1 = ReviewFactory( reviewer=self.reviewer1, mandate=self.assistant_mandate, status=review_status.DONE ) self.review2 = ReviewFactory( reviewer=None, mandate=self.assistant_mandate, status=review_status.DONE ) self.assistant_mandate.state = assistant_mandate_state.RESEARCH self.assistant_mandate.save() self.client.post(reverse('assistant_mandate_step_back'), {'mandate_id': self.assistant_mandate.id}) self.assistant_mandate.refresh_from_db() self.assertEqual(self.assistant_mandate.state, assistant_mandate_state.PHD_SUPERVISOR) def test_assistant_mandate_step_back_from_institute_president_to_assistant(self): # Test if assistant does not have a phd supervisor self.assistant_mandate.state = assistant_mandate_state.RESEARCH self.assistant_mandate.save() self.assistant.supervisor = None self.assistant.save() self.client.post(reverse('assistant_mandate_step_back'), {'mandate_id': self.assistant_mandate.id}) self.assistant_mandate.refresh_from_db() self.assertEqual(self.assistant_mandate.state, assistant_mandate_state.TRTS) def test_assistant_mandate_step_back_from_dean_of_faculty_to_institute_president(self): self.research_review = ReviewFactory(mandate=self.assistant_mandate, reviewer=self.reviewer1) self.assistant_mandate.state = assistant_mandate_state.SUPERVISION self.assistant_mandate.save() self.client.post(reverse('assistant_mandate_step_back'), {'mandate_id': self.assistant_mandate.id}) self.assistant_mandate.refresh_from_db() self.assertEqual(self.assistant_mandate.state, assistant_mandate_state.RESEARCH) def test_assistant_mandate_step_back_from_vice_rector_to_dean_of_faculty(self): self.supervision_review = ReviewFactory(mandate=self.assistant_mandate, reviewer=self.reviewer2) self.assistant_mandate.state = assistant_mandate_state.VICE_RECTOR self.assistant_mandate.save() self.client.post(reverse('assistant_mandate_step_back'), {'mandate_id': self.assistant_mandate.id}) self.assistant_mandate.refresh_from_db() self.assertEqual(self.assistant_mandate.state, assistant_mandate_state.SUPERVISION) def test_assistant_mandate_step_back_from_dean_of_faculty_to_assistant(self): # Test if assistant is teaching assistant self.research_review = ReviewFactory(mandate=self.assistant_mandate, reviewer=self.reviewer1) self.assistant_mandate.state = assistant_mandate_state.SUPERVISION self.assistant_mandate.save() self.client.post(reverse('assistant_mandate_step_back'), {'mandate_id': self.assistant_mandate2.id}) self.assistant_mandate2.refresh_from_db() self.assertEqual(self.assistant_mandate2.state, assistant_mandate_state.TRTS) def test_assistant_mandate_step_back_from_done_to_vice_rector(self): self.review4 = ReviewFactory( reviewer=self.reviewer3, mandate=self.assistant_mandate2, status=review_status.DONE ) self.review5 = ReviewFactory( reviewer=self.reviewer2, mandate=self.assistant_mandate2, status=review_status.DONE ) self.assistant_mandate2.state = assistant_mandate_state.DONE self.assistant_mandate2.save() self.client.post(reverse('assistant_mandate_step_back'), {'mandate_id': self.assistant_mandate2.id}) self.assistant_mandate2.refresh_from_db() self.assertEqual(self.assistant_mandate2.state, assistant_mandate_state.VICE_RECTOR) def test_add_actions_to_mandates_list(self): self.client.force_login(self.reviewer1.person.user) response = self.client.get('/assistants/reviewer/') context = add_actions_to_mandates_list(response.context, self.reviewer1) for mandate in context['object_list']: if mandate.id == self.assistant_mandate.id: self.assertFalse(mandate.view) self.assertFalse(mandate.edit) self.client.force_login(self.reviewer2.person.user) response = self.client.get('/assistants/reviewer/') context = add_actions_to_mandates_list(response.context, self.reviewer2) for mandate in context['object_list']: if mandate.id == self.assistant_mandate2.id: self.assertTrue(mandate.view) self.assertTrue(mandate.edit)
class StructuresListView(TestCase): def setUp(self): self.factory = RequestFactory() self.client = Client() self.settings = SettingsFactory() today = datetime.date.today() self.current_academic_year = AcademicYearFactory(start_date=today, end_date=today.replace(year=today.year + 1), year=today.year) self.phd_supervisor = PersonFactory() self.assistant = AcademicAssistantFactory(supervisor=self.phd_supervisor) self.assistant_mandate = AssistantMandateFactory(academic_year=self.current_academic_year, assistant=self.assistant) self.assistant_mandate.state = assistant_mandate_state.PHD_SUPERVISOR self.assistant_mandate.save() self.review = ReviewFactory(reviewer=None, mandate=self.assistant_mandate, status=review_status.IN_PROGRESS) self.entity_factory = EntityFactory() self.entity_version = EntityVersionFactory( entity_type=entity_type.INSTITUTE, end_date=None, entity=self.entity_factory ) self.entity_factory2 = EntityFactory() self.entity_version2 = EntityVersionFactory( entity_type=entity_type.SCHOOL, end_date=None, entity=self.entity_factory2 ) self.entity_version2 = EntityVersionFactory(entity_type=entity_type.SECTOR) self.mandate_entity = MandateEntityFactory(assistant_mandate=self.assistant_mandate, entity=self.entity_version.entity) self.reviewer = ReviewerFactory(role=reviewer_role.RESEARCH, entity=self.entity_version.entity) self.reviewer2 = ReviewerFactory(role=reviewer_role.VICE_RECTOR, entity=self.entity_version2.entity) self.entity_version3 = EntityVersionFactory(entity_type=entity_type.FACULTY) self.reviewer3 = ReviewerFactory(role=reviewer_role.SUPERVISION, entity=self.entity_version3.entity) self.delegate = PersonFactory() self.delegate2 = PersonFactory() def test_with_unlogged_user(self): response = self.client.get('/assistants/reviewer/delegation/') self.assertEqual(response.status_code, HTTP_FOUND) def test_context_data(self): self.client.force_login(self.reviewer.person.user) response = self.client.get('/assistants/reviewer/delegation/') entities_version = entity_version.get_last_version(self.reviewer.entity).children entities = [this_entity_version.entity for this_entity_version in entities_version] entities.insert(0, entity_version.get_last_version(self.reviewer.entity).entity) queryset = [{ 'id': entity.id, 'title': entity_version.get_last_version(entity, None).title, 'acronym': entity.most_recent_acronym, 'has_already_delegate': get_delegate_for_entity(self.reviewer, entity) } for entity in entities] self.assertQuerysetEqual(response.context['object_list'], queryset, transform=lambda x: x ) self.assertEqual(response.context['entity'], entity_version.get_last_version(self.reviewer.entity)) self.assertEqual(response.context['year'], self.current_academic_year.year) self.assertEqual(response.status_code, HTTP_OK) self.assertEqual(response.context['current_reviewer'], find_by_person(self.reviewer.person)) self.assertEqual(response.context['is_supervisor'], is_supervisor(self.reviewer.person)) def test_add_reviewer_for_structure_with_invalid_data(self): self.client.force_login(self.reviewer.person.user) this_entity = find_versions_from_entites([self.entity_factory.id], date=None)[0] response = self.client.post('/assistants/reviewer/delegate/add/', { #'person_id': self.delegate.id, 'entity': this_entity.id, 'role': self.reviewer.role } ) self.assertEqual(response.status_code, HTTP_OK) def test_add_reviewer_for_structure_with_person_already_reviewer(self): self.client.force_login(self.reviewer.person.user) this_entity = find_versions_from_entites([self.entity_factory.id], date=None)[0] response = self.client.post('/assistants/reviewer/delegate/add/', { 'person_id': self.reviewer2.person.id, 'entity': this_entity.id, 'role': self.reviewer.role } ) self.assertEqual(response.status_code, HTTP_OK) def test_add_reviewer_for_structure_with_valid_data(self): self.client.force_login(self.reviewer.person.user) this_entity = find_versions_from_entites([self.entity_factory.id], date=None)[0] response = self.client.post('/assistants/reviewer/delegate/add/', { 'person_id': self.delegate.id, 'entity': this_entity.id, 'role': self.reviewer.role } ) self.assertEqual(response.status_code, HTTP_FOUND) self.assertTrue(find_by_person(self.delegate)) def test_add_reviewer_for_structure_if_logged_reviewer_cannot_delegate(self): self.client.force_login(self.reviewer2.person.user) response = self.client.post('/assistants/reviewer/delegate/add/', {'entity': self.reviewer.entity.id}) self.assertEqual(response.status_code, HTTP_FOUND)
class StructuresListView(TestCase): def setUp(self): self.factory = RequestFactory() self.client = Client() self.settings = SettingsFactory() today = datetime.date.today() self.current_academic_year = AcademicYearFactory( start_date=today, end_date=today.replace(year=today.year + 1), year=today.year) self.phd_supervisor = PersonFactory() self.assistant = AcademicAssistantFactory( supervisor=self.phd_supervisor) self.assistant_mandate = AssistantMandateFactory( academic_year=self.current_academic_year, assistant=self.assistant) self.assistant_mandate.state = assistant_mandate_state.PHD_SUPERVISOR self.assistant_mandate.save() self.review = ReviewFactory(reviewer=None, mandate=self.assistant_mandate, status=review_status.IN_PROGRESS) self.entity_factory = EntityFactory() self.entity_version = EntityVersionFactory( entity_type=entity_type.INSTITUTE, end_date=None, entity=self.entity_factory) self.entity_factory2 = EntityFactory() self.entity_version2 = EntityVersionFactory( entity_type=entity_type.SCHOOL, end_date=None, entity=self.entity_factory2) self.entity_version2 = EntityVersionFactory( entity_type=entity_type.SECTOR) self.mandate_entity = MandateEntityFactory( assistant_mandate=self.assistant_mandate, entity=self.entity_version.entity) self.reviewer = ReviewerFactory(role=reviewer_role.RESEARCH, entity=self.entity_version.entity) self.reviewer2 = ReviewerFactory(role=reviewer_role.VICE_RECTOR, entity=self.entity_version2.entity) self.entity_version3 = EntityVersionFactory( entity_type=entity_type.FACULTY) self.reviewer3 = ReviewerFactory(role=reviewer_role.SUPERVISION, entity=self.entity_version3.entity) self.delegate = PersonFactory() self.delegate2 = PersonFactory() def test_with_unlogged_user(self): response = self.client.get('/assistants/reviewer/delegation/') self.assertEqual(response.status_code, HTTP_FOUND) def test_context_data(self): self.client.force_login(self.reviewer.person.user) response = self.client.get('/assistants/reviewer/delegation/') entities_version = entity_version.get_last_version( self.reviewer.entity).children entities = [ this_entity_version.entity for this_entity_version in entities_version ] entities.insert( 0, entity_version.get_last_version(self.reviewer.entity).entity) queryset = [{ 'id': entity.id, 'title': entity_version.get_last_version(entity, None).title, 'acronym': entity.most_recent_acronym, 'has_already_delegate': get_delegate_for_entity(self.reviewer, entity) } for entity in entities] self.assertQuerysetEqual(response.context['object_list'], queryset, transform=lambda x: x) self.assertEqual(response.context['entity'], entity_version.get_last_version(self.reviewer.entity)) self.assertEqual(response.context['year'], self.current_academic_year.year) self.assertEqual(response.status_code, HTTP_OK) self.assertEqual(response.context['current_reviewer'], find_by_person(self.reviewer.person)) self.assertEqual(response.context['is_supervisor'], is_supervisor(self.reviewer.person)) def test_add_reviewer_for_structure_with_invalid_data(self): self.client.force_login(self.reviewer.person.user) this_entity = find_versions_from_entites([self.entity_factory.id], date=None)[0] response = self.client.post( '/assistants/reviewer/delegate/add/', { #'person_id': self.delegate.id, 'entity': this_entity.id, 'role': self.reviewer.role }) self.assertEqual(response.status_code, HTTP_OK) def test_add_reviewer_for_structure_with_person_already_reviewer(self): self.client.force_login(self.reviewer.person.user) this_entity = find_versions_from_entites([self.entity_factory.id], date=None)[0] response = self.client.post( '/assistants/reviewer/delegate/add/', { 'person_id': self.reviewer2.person.id, 'entity': this_entity.id, 'role': self.reviewer.role }) self.assertEqual(response.status_code, HTTP_OK) def test_add_reviewer_for_structure_with_valid_data(self): self.client.force_login(self.reviewer.person.user) this_entity = find_versions_from_entites([self.entity_factory.id], date=None)[0] response = self.client.post( '/assistants/reviewer/delegate/add/', { 'person_id': self.delegate.id, 'entity': this_entity.id, 'role': self.reviewer.role }) self.assertEqual(response.status_code, HTTP_FOUND) self.assertTrue(find_by_person(self.delegate)) def test_add_reviewer_for_structure_if_logged_reviewer_cannot_delegate( self): self.client.force_login(self.reviewer2.person.user) response = self.client.post('/assistants/reviewer/delegate/add/', {'entity': self.reviewer.entity.id}) self.assertEqual(response.status_code, HTTP_FOUND)
class ReviewerReviewViewTestCase(TestCase): def setUp(self): self.factory = RequestFactory() self.client = Client() self.settings = SettingsFactory() today = datetime.date.today() self.current_academic_year = AcademicYearFactory(start_date=today, end_date=today.replace(year=today.year + 1), year=today.year) self.current_academic_year.save() self.phd_supervisor = PersonFactory() self.assistant = AcademicAssistantFactory(supervisor=self.phd_supervisor) self.assistant_mandate = AssistantMandateFactory( academic_year=self.current_academic_year, assistant=self.assistant, state=assistant_mandate_state.RESEARCH ) self.assistant_mandate2 = AssistantMandateFactory( academic_year=self.current_academic_year, assistant=self.assistant, state=assistant_mandate_state.RESEARCH ) self.phd_supervisor_review = ReviewFactory( reviewer=None, mandate=self.assistant_mandate, status=review_status.DONE ) self.entity_version = EntityVersionFactory(entity_type=entity_type.INSTITUTE) self.entity_mandate = MandateEntityFactory(assistant_mandate=self.assistant_mandate, entity=self.entity_version.entity) self.entity_mandate2 = MandateEntityFactory( assistant_mandate=self.assistant_mandate2, entity=self.entity_version.entity ) self.reviewer = ReviewerFactory(role=reviewer_role.RESEARCH, entity=self.entity_version.entity) self.review = ReviewFactory(reviewer=self.reviewer, mandate=self.assistant_mandate, status=review_status.IN_PROGRESS) self.entity_version2 = EntityVersionFactory(entity_type=entity_type.FACULTY) self.entity_mandate2 = MandateEntityFactory( assistant_mandate=self.assistant_mandate, entity=self.entity_version2.entity ) self.reviewer2 = ReviewerFactory( role=reviewer_role.SUPERVISION, entity=self.entity_version2.entity ) self.entity_version3 = EntityVersionFactory(entity_type=entity_type.SECTOR) self.entity_mandate3 = MandateEntityFactory( assistant_mandate=self.assistant_mandate, entity=self.entity_version3.entity ) self.reviewer3 = ReviewerFactory( role=reviewer_role.VICE_RECTOR, entity=self.entity_version3.entity ) def test_pst_form_view(self): self.client.force_login(self.reviewer.person.user) response = self.client.post('/assistants/reviewer/pst_form/', {'mandate_id': self.assistant_mandate.id}) self.assertEqual(response.status_code, HTTP_OK) def test_review_edit(self): self.client.force_login(self.reviewer.person.user) response = self.client.post('/assistants/reviewer/review/edit/', {'mandate_id': self.assistant_mandate2.id}) self.assertEqual(response.status_code, HTTP_OK) def test_review_save(self): self.client.force_login(self.reviewer.person.user) response = self.client.post('/assistants/reviewer/review/save/', {'mandate_id': self.assistant_mandate.id, 'review_id': self.review.id }) self.assertEqual(response.status_code, HTTP_OK) def test_validate_review_and_update_mandate(self): validate_review_and_update_mandate(self.review, self.assistant_mandate) self.assertEqual(self.review.status, review_status.DONE) self.assertEqual(self.assistant_mandate.state, assistant_mandate_state.SUPERVISION) self.review2 = ReviewFactory( reviewer=self.reviewer2, mandate=self.assistant_mandate, status=review_status.IN_PROGRESS ) validate_review_and_update_mandate(self.review2, self.assistant_mandate) self.assertEqual(self.review2.status, review_status.DONE) self.assertEqual(self.assistant_mandate.state, assistant_mandate_state.VICE_RECTOR) self.review3 = ReviewFactory(reviewer=self.reviewer3, mandate=self.assistant_mandate, status=review_status.IN_PROGRESS) validate_review_and_update_mandate(self.review3, self.assistant_mandate) self.assertEqual(self.review3.status, review_status.DONE) self.assertEqual(self.assistant_mandate.state, assistant_mandate_state.DONE) def test_review_view(self): self.client.force_login(self.reviewer.person.user) response = self.client.post('/assistants/reviewer/review/view/', {'mandate_id': self.assistant_mandate.id, 'role': reviewer_role.PHD_SUPERVISOR}) self.assertEqual(response.status_code, HTTP_OK) response = self.client.post('/assistants/reviewer/review/view/', {'mandate_id': self.assistant_mandate.id, 'role': reviewer_role.RESEARCH}) self.assertEqual(response.status_code, HTTP_OK) def test_generate_reviewer_menu_tabs(self): self.client.force_login(self.reviewer.person.user) self.assertEqual([{'action': 'view', 'class': '', 'item': 'PHD_SUPERVISOR'}, {'item': 'RESEARCH', 'class': '', 'action': 'edit'}], generate_reviewer_menu_tabs(reviewer_role.RESEARCH, self.assistant_mandate, None)) self.review.status = review_status.DONE self.review.save() self.assistant_mandate.state = assistant_mandate_state.SUPERVISION self.assistant_mandate.save() self.review2 = ReviewFactory( reviewer=self.reviewer2, mandate=self.assistant_mandate, status=review_status.IN_PROGRESS ) self.assertEqual([{'action': 'view', 'class': '', 'item': 'PHD_SUPERVISOR'}, {'item': 'RESEARCH', 'class': 'active', 'action': 'view'}], generate_reviewer_menu_tabs(reviewer_role.RESEARCH, self.assistant_mandate, assistant_mandate_state.RESEARCH)) self.assertEqual([{'action': 'view', 'class': '', 'item': 'PHD_SUPERVISOR'}, {'item': 'RESEARCH', 'class': '', 'action': 'view'}, {'item': 'SUPERVISION', 'class': '', 'action': 'edit'}], generate_reviewer_menu_tabs(reviewer_role.SUPERVISION, self.assistant_mandate, None))