Beispiel #1
0
 def test_deactivate(self):
     self.dissertation = DissertationFactory(active=True)
     self.dissertation.deactivate()
     self.assertEqual(self.dissertation.active, False)
Beispiel #2
0
    def setUpTestData(cls):
        cls.maxDiff = None
        cls.manager = AdviserManagerFactory()
        a_person_teacher = PersonFactory.create(
            first_name='Pierre',
            last_name='Dupont',
            email='*****@*****.**')
        cls.teacher = AdviserTeacherFactory(person=a_person_teacher)
        a_person_teacher2 = PersonFactory.create(
            first_name='Marco',
            last_name='Millet',
            email='*****@*****.**')
        cls.teacher2 = AdviserTeacherFactory(person=a_person_teacher2)
        a_person_student = PersonWithoutUserFactory.create(
            last_name="Durant", email='*****@*****.**')
        cls.student = StudentFactory.create(person=a_person_student)
        cls.education_group = EducationGroupFactory()
        cls.education_group3 = EducationGroupFactory()
        cls.academic_year1 = create_current_academic_year()
        cls.academic_year2 = AcademicYearFactory(year=cls.academic_year1.year -
                                                 1)
        cls.education_group_year = EducationGroupYearFactory(
            academic_year=cls.academic_year1,
            education_group=cls.education_group,
            acronym="test_offer1")
        cls.faculty_manager = FacultyAdviserFactory(
            adviser=cls.manager, education_group=cls.education_group)
        cls.offer_proposition1 = OfferPropositionFactory(
            global_email_to_commission=True,
            evaluation_first_year=True,
            education_group=cls.education_group_year.education_group)
        cls.offer_proposition2 = OfferPropositionFactory(
            education_group=cls.education_group3,
            global_email_to_commission=False)
        cls.education_group_year2 = EducationGroupYearFactory(
            acronym="test_offer2",
            education_group=cls.offer_proposition2.education_group,
            academic_year=cls.academic_year1)
        cls.proposition_dissertation = PropositionDissertationFactory(
            author=cls.teacher,
            creator=a_person_teacher,
            title='Proposition 1212121')
        cls.dissertation_test_email = DissertationFactory(
            author=cls.student,
            title='Dissertation_test_email',
            proposition_dissertation=cls.proposition_dissertation,
            status='DRAFT',
            active=True,
            dissertation_role__adviser=cls.teacher,
            dissertation_role__status='PROMOTEUR',
            education_group_year=cls.education_group_year,
        )

        FacultyAdviserFactory(
            adviser=cls.manager,
            education_group=cls.education_group_year.education_group)
        cls.manager2 = AdviserManagerFactory()
        FacultyAdviserFactory(
            adviser=cls.manager,
            education_group=cls.education_group_year2.education_group)
        FacultyAdviserFactory(
            adviser=cls.manager,
            education_group=cls.education_group_year.education_group)
        roles = [
            'PROMOTEUR', 'CO_PROMOTEUR', 'READER', 'PROMOTEUR', 'ACCOMPANIST',
            'PRESIDENT'
        ]
        status = [
            'DRAFT', 'COM_SUBMIT', 'EVA_SUBMIT', 'TO_RECEIVE', 'DIR_SUBMIT',
            'DIR_SUBMIT'
        ]
        cls.dissertations_list = list()
        for x in range(0, 6):
            proposition_dissertation = PropositionDissertationFactory(
                author=cls.teacher,
                creator=a_person_teacher,
                title='Proposition {}'.format(x))
            PropositionOfferFactory(
                proposition_dissertation=proposition_dissertation,
                offer_proposition=cls.offer_proposition1)

            cls.dissertations_list.append(
                DissertationFactory(
                    author=cls.student,
                    title='Dissertation {}'.format(x),
                    education_group_year=cls.education_group_year,
                    proposition_dissertation=proposition_dissertation,
                    status=status[x],
                    active=True,
                    dissertation_role__adviser=cls.teacher,
                    dissertation_role__status=roles[x]))
        cls.dissertation_1 = DissertationFactory(
            author=cls.student,
            title='Dissertation 2017',
            education_group_year=cls.education_group_year,
            proposition_dissertation=cls.proposition_dissertation,
            status='COM_SUBMIT',
            active=True,
            dissertation_role__adviser=cls.teacher2,
            dissertation_role__status='PROMOTEUR')
        cls.url = reverse('manager_dissertations_search')
Beispiel #3
0
 def test_find_by_id(self):
     self.dissertation_a = DissertationFactory(id=666)
     result = dissertation.find_by_id(666)
     self.assertEqual(self.dissertation_a, result)
     result = dissertation.find_by_id(999)
     self.assertEqual(None, result)
Beispiel #4
0
class DissertationModelTestCase(TestCase):
    fixtures = ['dissertation/fixtures/message_template.json', ]

    @classmethod
    def setUpTestData(cls):
        a_person_teacher = PersonFactory(
            first_name='Pierre',
            last_name='Dupont'
        )
        cls.teacher = AdviserTeacherFactory(person=a_person_teacher)
        a_person_student = PersonWithoutUserFactory(
            last_name="Durant",
            first_name='jean'
        )
        cls.student = StudentFactory(person=a_person_student)
        cls.education_group = EducationGroupFactory()
        cls.education_group2 = EducationGroupFactory()
        cls.offer_prop = OfferPropositionFactory(education_group=cls.education_group,
                                                 acronym="test_offer1",
                                                 validation_commission_exists=True)
        cls.proposition_dissertation = PropositionDissertationFactory(author=cls.teacher,
                                                                      title='proposition_x',
                                                                      creator=a_person_teacher)

        cls.academic_year1 = AcademicYearFactory()
        cls.education_group_year = EducationGroupYearFactory(acronym="test_offer1",
                                                             education_group=cls.education_group,
                                                             academic_year=cls.academic_year1)
        cls.education_group_year2 = EducationGroupYearFactory(acronym="test_offer11",
                                                              education_group=cls.education_group2,
                                                              academic_year=cls.academic_year1)
        cls.dissertation_test_email = DissertationFactory(author=cls.student,
                                                          title='Dissertation_test_email',
                                                          education_group_year=cls.education_group_year,
                                                          proposition_dissertation=cls.proposition_dissertation,
                                                          status=dissertation_status.DRAFT,
                                                          active=True,
                                                          dissertation_role__adviser=cls.teacher,
                                                          dissertation_role__status='PROMOTEUR')
        cls.dissertation = DissertationFactory(author=cls.student,
                                               title='Dissertation_1',
                                               education_group_year=cls.education_group_year,
                                               proposition_dissertation=cls.proposition_dissertation,
                                               status=dissertation_status.DIR_SUBMIT,
                                               active=True,
                                               description='les phobies',
                                               dissertation_role__adviser=cls.teacher,
                                               dissertation_role__status='PROMOTEUR')

    def test_deactivate(self):
        self.dissertation = DissertationFactory(active=True)
        self.dissertation.deactivate()
        self.assertEqual(self.dissertation.active, False)

    def test_str(self):
        self.dissertation = DissertationFactory(title="dissert1")
        self.assertEqual(self.dissertation.title, str(self.dissertation))

    def test_set_status(self):
        self.dissertation = DissertationFactory(status=dissertation_status.DRAFT)
        self.dissertation.set_status(dissertation_status.DIR_SUBMIT)
        self.assertEqual(self.dissertation.status, dissertation_status.DIR_SUBMIT)

    def test_go_forward_status(self):
        self.dissertation = DissertationFactory(status=dissertation_status.DRAFT, active=True)
        self.dissertation.go_forward()
        self.assertEqual(dissertation_status.DIR_SUBMIT, self.dissertation.status)
        self.dissertation = DissertationFactory(status=dissertation_status.DIR_KO)
        self.dissertation.go_forward()
        self.assertEqual(dissertation_status.DIR_SUBMIT, self.dissertation.status)
        self.dissertation = DissertationFactory(status=dissertation_status.TO_RECEIVE)
        self.dissertation.go_forward()
        self.assertEqual(dissertation_status.TO_DEFEND, self.dissertation.status)

    def test_go_forward_emails_acknowledge(self):
        self.dissertation_test_email.status = dissertation_status.TO_RECEIVE
        count_message_history_author = message_history.find_my_messages(
            self.dissertation_test_email.author.person.id
        ).count()
        self.dissertation_test_email.go_forward()
        message_history_result_author_after_change = message_history.find_my_messages(
            self.dissertation_test_email.author.person.id
        )
        count_message_history_result_author = len(message_history_result_author_after_change)
        self.assertEqual(count_message_history_author + 1, count_message_history_result_author)
        self.assertIn('bien été réceptionné', message_history_result_author_after_change.last().subject)

    def test_go_forward_emails_new_dissert_1(self):
        self.dissertation_test_email.status = dissertation_status.DRAFT
        count_messages_before_status_change = message_history.find_my_messages(self.teacher.person.id).count()
        self.dissertation_test_email.go_forward()
        message_history_result = message_history.find_my_messages(self.teacher.person.id)
        self.assertEqual(count_messages_before_status_change + 1, len(message_history_result))
        self.assertIsNotNone(message_template.find_by_reference('dissertation_adviser_new_project_dissertation_txt'))
        self.assertIsNotNone(message_template.find_by_reference('dissertation_adviser_new_project_dissertation_html'))
        self.assertIn('Vous avez reçu une demande d\'encadrement de mémoire', message_history_result.last().subject)

    def test_go_forward_emails_new_dissert_2(self):
        count_messages_before_status_change = message_history.find_my_messages(self.teacher.person.id).count()
        self.dissertation_test_email.status = dissertation_status.DIR_KO
        self.dissertation_test_email.go_forward()
        message_history_result = message_history.find_my_messages(self.teacher.person.id)
        self.assertEqual(count_messages_before_status_change + 1, len(message_history_result))
        self.assertIsNotNone(message_template.find_by_reference('dissertation_adviser_new_project_dissertation_txt'))
        self.assertIsNotNone(message_template.find_by_reference('dissertation_adviser_new_project_dissertation_html'))
        self.assertIn('Vous avez reçu une demande d\'encadrement de mémoire', message_history_result.last().subject)

    def test_manager_accept_commission_exist(self):
        self.offer_prop2 = OfferPropositionFactory(
            education_group=self.education_group2,
            validation_commission_exists=True
        )
        self.dissertation1 = DissertationFactory(
            status=dissertation_status.DIR_SUBMIT,
            education_group_year=self.education_group_year2
        )
        self.dissertation1.manager_accept()
        self.assertEqual(self.dissertation1.status, dissertation_status.COM_SUBMIT)

    def test_manager_accept_commission_exist_2(self):
        self.offer_prop2 = OfferPropositionFactory(
            education_group=self.education_group2,
            validation_commission_exists=True,
            evaluation_first_year=True
        )
        self.dissertation1 = DissertationFactory(
            status=dissertation_status.COM_KO,
            education_group_year=self.education_group_year2
        )
        self.dissertation1.manager_accept()
        self.assertEqual(self.dissertation1.status, dissertation_status.EVA_SUBMIT)

    def test_manager_accept_not_commission_exist(self):
        self.offer_prop2 = OfferPropositionFactory(education_group=self.education_group2,
                                                   validation_commission_exists=False,
                                                   evaluation_first_year=False)
        self.dissertation1 = DissertationFactory(status=dissertation_status.DIR_SUBMIT,
                                                 education_group_year=self.education_group_year2)
        self.dissertation1.manager_accept()
        self.assertEqual(self.dissertation1.status, dissertation_status.TO_RECEIVE)

    def test_manager_accept_not_commission_yes_eval(self):
        self.offer_prop2 = OfferPropositionFactory(education_group=self.education_group2,
                                                   validation_commission_exists=False,
                                                   evaluation_first_year=True)
        self.dissertation1 = DissertationFactory(status=dissertation_status.DIR_SUBMIT,
                                                 education_group_year=self.education_group_year2)
        self.dissertation1.manager_accept()
        self.assertEqual(self.dissertation1.status, dissertation_status.EVA_SUBMIT)

    def test_manager_accept_eval_submit(self):
        self.offer_prop2 = OfferPropositionFactory(education_group=self.education_group2,
                                                   validation_commission_exists=False,
                                                   evaluation_first_year=True)
        self.dissertation1 = DissertationFactory(status=dissertation_status.EVA_SUBMIT,
                                                 education_group_year=self.education_group_year2)
        self.dissertation1.manager_accept()
        self.assertEqual(self.dissertation1.status, dissertation_status.TO_RECEIVE)

    def test_manager_accept_eval_KO(self):
        self.offer_prop2 = OfferPropositionFactory(education_group=self.education_group2,
                                                   validation_commission_exists=False,
                                                   evaluation_first_year=True)
        self.dissertation1 = DissertationFactory(status=dissertation_status.EVA_KO,
                                                 education_group_year=self.education_group_year2, )
        self.dissertation1.manager_accept()
        self.assertEqual(self.dissertation1.status, dissertation_status.TO_RECEIVE)

    def test_teacher_accept_1(self):
        count_messages_before_status_change = message_history.find_my_messages(self.student.person.id).count()
        self.offer_prop2 = OfferPropositionFactory(education_group=self.education_group2,
                                                   validation_commission_exists=True,
                                                   evaluation_first_year=True)
        self.dissertation1 = DissertationFactory(status=dissertation_status.DIR_SUBMIT,
                                                 education_group_year=self.education_group_year2,
                                                 author=self.student)
        self.dissertation1.teacher_accept()
        message_history_result = message_history.find_my_messages(self.student.person.id)
        self.assertEqual(count_messages_before_status_change + 1, len(message_history_result))
        self.assertEqual(self.dissertation1.status, dissertation_status.COM_SUBMIT)
        self.assertIn('Votre projet de mémoire est validé par votre promoteur', message_history_result.last().subject)

    def test_teacher_accept_2(self):
        self.dissertation1 = DissertationFactory(status=dissertation_status.DRAFT)
        self.assertEqual(self.dissertation1.teacher_accept(), None)

    def test_refuse_DIR_SUBMIT(self):
        count_messages_before_status_change = message_history.find_my_messages(self.student.person.id).count()
        self.offer_prop2 = OfferPropositionFactory(education_group=self.education_group2, )
        self.dissertation1 = DissertationFactory(status=dissertation_status.DIR_SUBMIT,
                                                 education_group_year=self.education_group_year2,
                                                 author=self.student)
        self.dissertation1.refuse()
        message_history_result = message_history.find_my_messages(self.student.person.id)
        self.assertEqual(count_messages_before_status_change + 1, len(message_history_result))
        self.assertEqual(self.dissertation1.status, dissertation_status.DIR_KO)
        self.assertIn('Votre projet de mémoire n\'a pas été validé par votre promoteur',
                      message_history_result.last().subject)

    def test_refuse_COM_SUBMIT(self):
        count_messages_before_status_change = message_history.find_my_messages(self.student.person.id).count()
        self.offer_prop2 = OfferPropositionFactory(education_group=self.education_group2,
                                                   validation_commission_exists=True,
                                                   evaluation_first_year=True)
        self.dissertation1 = DissertationFactory(status=dissertation_status.COM_SUBMIT,
                                                 education_group_year=self.education_group_year2,
                                                 author=self.student)
        self.dissertation1.refuse()
        message_history_result = message_history.find_my_messages(self.student.person.id)
        self.assertEqual(count_messages_before_status_change + 1, len(message_history_result))
        self.assertEqual(self.dissertation1.status, dissertation_status.COM_KO)
        self.assertIn('n\'a pas validé',
                      message_history_result.last().subject)

    def test_refuse_COM_SUBMIT_2(self):
        count_messages_before_status_change = message_history.find_my_messages(self.teacher.person.id).count()
        self.offer_prop2 = OfferPropositionFactory(education_group=self.education_group2,
                                                   validation_commission_exists=True,
                                                   evaluation_first_year=True)
        self.dissertation1 = DissertationFactory(status=dissertation_status.COM_SUBMIT,
                                                 education_group_year=self.education_group_year2,
                                                 author=self.student,
                                                 dissertation_role__adviser=self.teacher,
                                                 dissertation_role__status='PROMOTEUR'
                                                 )
        self.dissertation1.refuse()
        message_history_result = message_history.find_my_messages(self.teacher.person.id)
        self.assertEqual(count_messages_before_status_change + 1, len(message_history_result))
        self.assertEqual(self.dissertation1.status, dissertation_status.COM_KO)
        self.assertIn('n\'a pas validé le projet de mémoire',
                      message_history_result.last().subject)

    def test_search_with_title_name_first_name(self):
        self.assertCountEqual(dissertation.search('Dissertation_1'), [self.dissertation])
        self.assertCountEqual(
            dissertation.search(dissertation_status.DIR_SUBMIT),
            [self.dissertation]
        )
        self.assertCountEqual(
            dissertation.search('jean'),
            [self.dissertation, self.dissertation_test_email]
        )
        self.assertCountEqual(
            dissertation.search('durant'),
            [self.dissertation, self.dissertation_test_email]
        )
        self.assertCountEqual(
            dissertation.search('Pierre'),
            [self.dissertation, self.dissertation_test_email]
        )

    def test_search_with_subject_offer(self):
        self.assertCountEqual(
            dissertation.search('les phobies'),
            [self.dissertation]
        )
        self.assertCountEqual(
            dissertation.search('proposition_x'),
            [self.dissertation, self.dissertation_test_email]
        )
        self.assertCountEqual(
            dissertation.search('test_offer1'),
            [self.dissertation, self.dissertation_test_email]
        )

    def test_search_by_proposition_author(self):
        self.assertCountEqual(
            dissertation.search_by_proposition_author(None, True, self.teacher),
            [self.dissertation, self.dissertation_test_email]
        )

    def test_search_by_offer(self):
        self.assertCountEqual(dissertation.search_by_education_group([self.education_group]),
                              [self.dissertation, self.dissertation_test_email]
                              )

    def test_search_by_offer_and_status(self):
        self.assertCountEqual(
            dissertation.search_by_education_group_and_status([self.education_group], dissertation_status.DIR_SUBMIT),
            [self.dissertation]
        )

    def test_get_next_status_goforward(self):
        self.dissertation_x = DissertationFactory(status=dissertation_status.DRAFT, active=True)
        self.assertEqual(dissertation.get_next_status(self.dissertation_x, "go_forward"),
                         dissertation_status.DIR_SUBMIT)
        self.dissertation_x.status = dissertation_status.DIR_KO
        self.assertEqual(dissertation.get_next_status(self.dissertation_x, "go_forward"),
                         dissertation_status.DIR_SUBMIT)
        self.dissertation_x.status = dissertation_status.TO_RECEIVE
        self.assertEqual(dissertation.get_next_status(self.dissertation_x, "go_forward"),
                         dissertation_status.TO_DEFEND)
        self.dissertation_x.status = dissertation_status.TO_DEFEND
        self.assertEqual(dissertation.get_next_status(self.dissertation_x, "go_forward"),
                         dissertation_status.DEFENDED)
        self.dissertation_x.status = dissertation_status.DIR_SUBMIT
        self.assertEqual(dissertation.get_next_status(self.dissertation_x, "go_forward"),
                         dissertation_status.DIR_SUBMIT)

    def test_get_next_status_accept_1(self):
        self.offer_prop2 = OfferPropositionFactory(
            education_group=self.education_group2,
            validation_commission_exists=True,
            evaluation_first_year=True
        )
        self.dissertation_x = DissertationFactory(status=dissertation_status.DIR_SUBMIT,
                                                  education_group_year=self.education_group_year2)
        self.assertEqual(dissertation.get_next_status(self.dissertation_x, "accept"),
                         dissertation_status.COM_SUBMIT)

    def test_get_next_status_accept_2(self):
        self.offer_prop2 = OfferPropositionFactory(education_group=self.education_group2,
                                                   validation_commission_exists=False,
                                                   evaluation_first_year=True)
        self.dissertation_x = DissertationFactory(status=dissertation_status.DIR_SUBMIT,
                                                  education_group_year=self.education_group_year2)
        self.assertEqual(dissertation.get_next_status(self.dissertation_x, "accept"),
                         dissertation_status.EVA_SUBMIT)
        self.dissertation_x.status = dissertation_status.COM_SUBMIT
        self.assertEqual(dissertation.get_next_status(self.dissertation_x, "accept"),
                         dissertation_status.EVA_SUBMIT)
        self.dissertation_x.status = dissertation_status.COM_KO
        self.assertEqual(dissertation.get_next_status(self.dissertation_x, "accept"),
                         dissertation_status.EVA_SUBMIT)

    def test_get_next_status_accept_3(self):
        self.offer_prop2 = OfferPropositionFactory(education_group=self.education_group2,
                                                   validation_commission_exists=False,
                                                   evaluation_first_year=True)
        self.dissertation_x = DissertationFactory(status=dissertation_status.EVA_SUBMIT,
                                                  education_group_year=self.education_group_year2)
        self.assertEqual(dissertation.get_next_status(self.dissertation_x, "accept"),
                         dissertation_status.TO_RECEIVE)
        self.dissertation_x.status = dissertation_status.DEFENDED
        self.assertEqual(dissertation.get_next_status(self.dissertation_x, "accept"), dissertation_status.ENDED_WIN)

        self.dissertation_x.status = dissertation_status.DIR_SUBMIT
        self.assertEqual(dissertation.get_next_status(self.dissertation_x, "accept"), dissertation_status.EVA_SUBMIT)

    def test_get_next_status_accept_4(self):
        self.offer_prop2 = OfferPropositionFactory(education_group=self.education_group2,
                                                   validation_commission_exists=False,
                                                   evaluation_first_year=False)
        self.dissertation_x = DissertationFactory(status=dissertation_status.DIR_SUBMIT,
                                                  education_group_year=self.education_group_year2)
        self.dissertation_x.status = dissertation_status.DIR_SUBMIT
        self.assertEqual(dissertation.get_next_status(self.dissertation_x, "accept"),
                         dissertation_status.TO_RECEIVE)
        self.dissertation_x.status = dissertation_status.DIR_SUBMIT
        self.assertEqual(dissertation.get_next_status(self.dissertation_x, "go"), dissertation_status.DIR_SUBMIT)

    def test_get_next_status_refuse(self):
        self.dissertation_a = DissertationFactory(status=dissertation_status.DIR_SUBMIT)
        self.assertEqual(dissertation.get_next_status(self.dissertation_a, "refuse"), dissertation_status.DIR_KO)
        self.dissertation_a.status = dissertation_status.COM_SUBMIT
        self.assertEqual(dissertation.get_next_status(self.dissertation_a, "refuse"), dissertation_status.COM_KO)
        self.dissertation_a.status = dissertation_status.EVA_SUBMIT
        self.assertEqual(dissertation.get_next_status(self.dissertation_a, "refuse"), dissertation_status.EVA_KO)
        self.dissertation_a.status = dissertation_status.DEFENDED
        self.assertEqual(dissertation.get_next_status(self.dissertation_a, "refuse"), dissertation_status.ENDED_LOS)
        self.dissertation_a.status = dissertation_status.DRAFT
        self.assertEqual(dissertation.get_next_status(self.dissertation_a, "refuse"), dissertation_status.DRAFT)
        self.dissertation_a.status = dissertation_status.TO_DEFEND
        self.assertEqual(dissertation.get_next_status(self.dissertation_a, "refuse"), dissertation_status.TO_DEFEND)

    def test_find_by_id(self):
        self.dissertation_a = DissertationFactory(id=666)
        result = dissertation.find_by_id(666)
        self.assertEqual(self.dissertation_a, result)
        result = dissertation.find_by_id(999)
        self.assertEqual(None, result)

    def test_count_by_proposition(self):
        self.prop_dissert = PropositionDissertationFactory()
        self.starting_academic_year = create_current_academic_year()
        self.dissertation_active = DissertationFactory(
            active=True,
            status=dissertation_status.COM_SUBMIT,
            proposition_dissertation=self.prop_dissert,
            education_group_year__academic_year=self.starting_academic_year
        )
        DissertationFactory(active=False, proposition_dissertation=self.prop_dissert)
        DissertationFactory(active=True, status=dissertation_status.DRAFT, proposition_dissertation=self.prop_dissert)
        DissertationFactory(active=True, status=dissertation_status.DIR_KO, proposition_dissertation=self.prop_dissert)

        self.assertEqual(dissertation.count_by_proposition(self.prop_dissert), 1)

    def test_search_by_education_group(self):
        dissert = dissertation.search_by_education_group([self.education_group_year.education_group])
        self.assertEqual(dissert[0], self.dissertation)
Beispiel #5
0
 def test_teacher_accept_2(self):
     self.dissertation1 = DissertationFactory(status=dissertation_status.DRAFT)
     self.assertEqual(self.dissertation1.teacher_accept(), None)
Beispiel #6
0
 def test_set_status(self):
     self.dissertation = DissertationFactory(status=dissertation_status.DRAFT)
     self.dissertation.set_status(dissertation_status.DIR_SUBMIT)
     self.assertEqual(self.dissertation.status, dissertation_status.DIR_SUBMIT)
Beispiel #7
0
 def test_str(self):
     self.dissertation = DissertationFactory(title="dissert1")
     self.assertEqual(self.dissertation.title, str(self.dissertation))
Beispiel #8
0
 def setUpTestData(cls):
     cls.user = UserFactory()
     cls.person = PersonFactory(user=cls.user)
     cls.student = StudentFactory(person=cls.person)
     cls.dissertation = DissertationFactory(author=cls.student)
class DissertationViewTestCase(TestCase):
    fixtures = [
        'dissertation/fixtures/message_templates_dissertation.json',
    ]

    @classmethod
    def setUpTestData(cls):
        cls.maxDiff = None
        cls.manager = AdviserManagerFactory()
        a_person_teacher = PersonFactory(first_name='Pierre',
                                         last_name='Dupont')
        cls.teacher = AdviserTeacherFactory(person=a_person_teacher)
        a_person_student = PersonFactory(last_name="Durant")
        another_person_student = PersonFactory(last_name="Paul")
        cls.student = StudentFactory.create(person=a_person_student)
        cls.student_with_1_dissertation = StudentFactory(
            person=another_person_student)
        cls.education_group1 = EducationGroupFactory()
        cls.academic_year1 = AcademicYearFactory()
        cls.education_group_year1 = EducationGroupYearFactory(
            acronym="test_offer1",
            education_group=cls.education_group1,
            academic_year=cls.academic_year1)
        cls.offer_proposition1 = OfferPropositionFactory(
            education_group=cls.education_group1)
        cls.proposition_dissertation = PropositionDissertationFactory(
            author=cls.teacher,
            creator=a_person_teacher,
            title='Proposition 1212121')
        cls.proposition_dissertation2 = PropositionDissertationFactory(
            author=cls.teacher,
            creator=a_person_teacher,
            title='Proposition 1212121')

    def setUp(self):
        self.client.force_login(self.student.person.user)
        self.dissertation = DissertationFactory(
            author=self.student,
            title='Dissertation test',
            education_group_year=self.education_group_year1,
            proposition_dissertation=self.proposition_dissertation2,
            status='DIR_SUBMIT',
            active=True,
            dissertation_role__adviser=self.teacher,
            dissertation_role__status=dissertation_role_status.PROMOTEUR)
        self.dissertation_to_dir_submit = DissertationFactory(
            author=self.student_with_1_dissertation,
            status='DRAFT',
            active=True,
            dissertation_role__adviser=self.teacher,
            dissertation_role__status=dissertation_role_status.PROMOTEUR)

    def test_email_new_dissert(self):
        self.dissertation_test_email = DissertationFactory(
            author=self.student,
            title='Dissertation_test_email',
            education_group_year=self.education_group_year1,
            proposition_dissertation=self.proposition_dissertation,
            status='DRAFT',
            active=True,
            dissertation_role__adviser=self.teacher,
            dissertation_role__status=dissertation_role_status.PROMOTEUR)
        self.client.force_login(self.manager.person.user)
        count_messages_before_status_change = len(
            message_history.find_my_messages(self.teacher.person.id))
        self.dissertation_test_email.go_forward()
        message_history_result = message_history.find_my_messages(
            self.teacher.person.id)
        self.assertEqual(count_messages_before_status_change + 1,
                         len(message_history_result))
        self.assertNotEqual(
            message_template.find_by_reference(
                'dissertation_adviser_new_project_dissertation_txt'), None)
        self.assertNotEqual(
            message_template.find_by_reference(
                'dissertation_adviser_new_project_dissertation_html'), None)
        self.assertIn('Vous avez reçu une demande d\'encadrement de mémoire',
                      message_history_result.last().subject)

    def test_dissertation_to_dir_submit(self):
        self.client.force_login(self.student_with_1_dissertation.person.user)
        form = DissertationUpdateForm(
            dissertation=self.dissertation_to_dir_submit,
            person=self.student_with_1_dissertation.person,
            action="go_forward",
        )
        response = self.client.post(
            reverse('dissertation_to_dir_submit',
                    args=[self.dissertation_to_dir_submit.pk]), {
                        "form": form,
                    })
        self.assertEqual(response.status_code,
                         HttpResponseRedirect.status_code)

    def test_dissertation_to_dir_submit_with_another_student(self):
        form = DissertationUpdateForm(
            dissertation=self.dissertation_to_dir_submit,
            person=self.student_with_1_dissertation.person,
            action="go_forward",
        )
        response = self.client.post(
            reverse('dissertation_to_dir_submit',
                    args=[self.dissertation_to_dir_submit.pk]), {
                        "form": form,
                    })
        self.assertEqual(response.status_code,
                         HttpResponseRedirect.status_code)

    @patch("dissertation.forms.DissertationUpdateForm.is_valid",
           return_value=False)
    def test_dissertation_to_dir_submit_with_invalid_form(self, *args):
        self.client.force_login(self.student_with_1_dissertation.person.user)
        form = DissertationUpdateForm(
            dissertation=self.dissertation_to_dir_submit,
            person=self.student_with_1_dissertation.person,
            action="go_forward",
        )
        response = self.client.post(
            reverse('dissertation_to_dir_submit',
                    args=[self.dissertation_to_dir_submit.pk]), {
                        "form": form,
                    })
        self.assertEqual(response.status_code, HttpResponse.status_code)

    def test_dissertation_back_to_draft(self):
        form = DissertationUpdateForm(
            dissertation=self.dissertation,
            person=self.student.person,
            action="go_back",
        )
        response = self.client.post(
            reverse('dissertation_back_to_draft', args=[self.dissertation.pk]),
            {
                "form": form,
            })
        self.assertEqual(response.status_code,
                         HttpResponseRedirect.status_code)
        self.dissertation.refresh_from_db()
        self.assertEqual(self.dissertation.status, 'DRAFT')

    @patch("dissertation.forms.DissertationUpdateForm.is_valid",
           return_value=False)
    def test_dissertation_back_to_draft_with_invalid_form(self, mock_form):
        form = DissertationUpdateForm(
            dissertation=self.dissertation,
            person=self.student.person,
            action="go_back",
        )
        response = self.client.post(
            reverse('dissertation_back_to_draft', args=[self.dissertation.pk]),
            {"form": form})
        self.assertEqual(response.status_code, HttpResponse.status_code)

    def test_dissertation_jury_new_view(self):
        response = self.client.post(
            reverse('add_reader', args=[self.dissertation.pk]), {
                "status": "READER",
                'adviser': self.teacher.pk,
                "dissertation": self.dissertation.pk
            })
        self.assertEqual(response.status_code,
                         HttpResponseRedirect.status_code)

    def test_dissertation_jury_new_view_without_student_logged(self):
        self.client.force_login(self.manager.person.user)
        response = self.client.post(
            reverse('add_reader', args=[self.dissertation.pk]), {
                "status": "READER",
                'adviser': self.teacher.pk,
                "dissertation": self.dissertation.pk
            })
        self.assertEqual(response.status_code,
                         HttpResponseRedirect.status_code)