Пример #1
0
 def setUp(self):
     self.data = {
         'title': 'Métamorphose',
         'title_english': 'Transfiguration',
         'education_group_type': self.education_group_type.pk,
         'credits': 42,
         'acronym': 'CRSCHOIXDVLD',
         'partial_acronym': 'LDVLD101R',
         'management_entity': self.management_entity_version.pk,
         'administration_entity': MainEntityVersionFactory().pk,
         'main_teaching_campus': "",
         'academic_year': create_current_academic_year().pk,
         'active': ACTIVE,
         'schedule_type': DAILY,
         "internship": internship_presence.NO,
         "primary_language": LanguageFactory().pk,
         "start_year": 2010,
         "constraint_type": "",
         "diploma_printing_title": 'Diploma title'
     }
     self.administration_entity_version = MainEntityVersionFactory()
     self.education_group_year = TrainingFactory(
         academic_year=create_current_academic_year(),
         education_group_type__name=education_group_types.TrainingType.
         BACHELOR,
         management_entity=self.management_entity_version.entity,
         administration_entity=self.administration_entity_version.entity,
     )
     PersonEntityFactory(person=self.person,
                         entity=self.education_group_year.management_entity)
Пример #2
0
    def setUp(self):

        self.education_group_year = TrainingFactory(
            academic_year=create_current_academic_year())
        self.education_group_type = EducationGroupTypeFactory(
            category=education_group_categories.TRAINING)

        EntityVersionFactory(
            entity=self.education_group_year.administration_entity)
        EntityVersionFactory(
            entity=self.education_group_year.management_entity)
        self.list_acs = GenerateAcademicYear(get_current_year(),
                                             get_current_year() +
                                             40).academic_years

        self.data = {
            'title': 'Métamorphose',
            'title_english': 'Transfiguration',
            'education_group_type': self.education_group_type.pk,
            'credits': 42,
            'acronym': 'CRSCHOIXDVLD',
            'partial_acronym': 'LDVLD101R',
            'management_entity': MainEntityVersionFactory().pk,
            'administration_entity': MainEntityVersionFactory().pk,
            'main_teaching_campus': "",
            'academic_year': create_current_academic_year().pk,
            'active': ACTIVE,
            'schedule_type': DAILY,
            "internship": internship_presence.NO,
            "primary_language": LanguageFactory().pk,
            "start_year": 2010,
            "constraint_type": "",
        }
Пример #3
0
    def test_clean_certificate_aims(self):
        administration_entity_version = MainEntityVersionFactory(end_date=None)
        management_entity_version = MainEntityVersionFactory(end_date=None)
        person = PersonFactory()
        PersonEntityFactory(person=person,
                            entity=management_entity_version.entity)
        user = person.user
        user.groups.add(self.central_manager)

        parent_education_group_year = TrainingFactory(
            academic_year=self.academic_year,
            education_group_type=self.education_group_type,
            management_entity=management_entity_version.entity,
            administration_entity=administration_entity_version.entity,
        )
        AuthorizedRelationshipFactory(
            parent_type=parent_education_group_year.education_group_type,
            child_type=self.education_group_type,
        )

        cert = [
            CertificateAimFactory(code=code, section=2)
            for code in range(100, 102)
        ]
        for i in range(0, len(cert)):
            with self.subTest(i=i):
                cert_for_form = [str(cert[j].pk) for j in range(0, i + 1)]

                form = self.form_class(
                    data={
                        'acronym': "EEDY2020",
                        'partial_acronym': 'EEDY2020F',
                        'title': "Test",
                        'internship': 'OPTIONAL',
                        'primary_language': LanguageFactory().pk,
                        'active': 'ACTIVE',
                        'schedule_type': 'DAILY',
                        'administration_entity':
                        administration_entity_version.pk,
                        'management_entity': management_entity_version.pk,
                        'diploma_printing_title': 'Diplome en test',
                        'certificate_aims': cert_for_form,
                    },
                    parent=parent_education_group_year,
                    education_group_type=parent_education_group_year.
                    education_group_type,
                    user=user,
                )
                if i == 0:
                    self.assertTrue(form.is_valid())
                else:
                    self.assertFalse(form.is_valid())
Пример #4
0
    def setUpTestData(cls):
        super().setUpTestData()

        cls.current_academic_year = AcademicYearFactory(current=True)
        cls.generated_ac_years = AcademicYearFactory.produce(
            base_year=cls.current_academic_year.year,
            number_past=0,
            number_future=7)
        cls.entity_version = MainEntityVersionFactory(
            entity_type=entity_type.SECTOR)
        cls.central_manager = CentralManagerFactory()
        PersonEntityFactory(person=cls.central_manager,
                            entity=cls.entity_version.entity)
        cls.training = TrainingFactory(
            management_entity=cls.entity_version.entity,
            administration_entity=cls.entity_version.entity,
            academic_year=cls.current_academic_year)
        cls.form_data = model_to_dict_fk(cls.training,
                                         exclude=('secondary_domains', ))
        cls.form_data.update({
            'primary_language':
            cls.form_data['primary_language_id'],
            'administration_entity':
            cls.entity_version.pk,
            'management_entity':
            cls.entity_version.pk
        })
Пример #5
0
    def setUpTestData(cls, **kwargs):
        cls.education_group_type = kwargs.pop('education_group_type')

        cls.campus = CampusFactory(organization__type=organization_type.MAIN)
        cls.academic_year = AcademicYearFactory()
        new_entity_version = MainEntityVersionFactory()

        cls.form_data = {
            "acronym": "ACRO4569",
            "partial_acronym": "PACR8974",
            "education_group_type": cls.education_group_type.id,
            "title": "Test data",
            "main_teaching_campus": cls.campus.id,
            "academic_year": cls.academic_year.id,
            "management_entity": new_entity_version.pk,
            "remark": "This is a test!!"
        }

        cls.parent_education_group_year = EducationGroupYearFactory(
            academic_year=cls.academic_year)
        # Append version to management/administration entity
        cls.entity_version = EntityVersionFactory(
            entity=cls.parent_education_group_year.management_entity)
        if cls.education_group_type.category == TRAINING:
            EntityVersionFactory(
                entity=cls.parent_education_group_year.administration_entity)

        # Create user and attached it to management entity
        person = PersonFactory()
        PersonEntityFactory(
            person=person,
            entity=cls.parent_education_group_year.management_entity)
        cls.user = person.user
Пример #6
0
def _get_valid_post_data(category):
    entity_version = MainEntityVersionFactory()
    education_group_type = EducationGroupTypeFactory(category=category)
    campus = CampusFactory(organization__type=organization_type.MAIN)
    current_academic_year = create_current_academic_year()
    fake_education_group_year = EducationGroupYearFactory.build(
        academic_year=current_academic_year,
        management_entity=entity_version.entity,
        main_teaching_campus=campus,
        education_group_type=education_group_type,
        education_group__start_year=current_academic_year.year,
        constraint_type=CREDITS,
    )
    AuthorizedRelationshipFactory(child_type=fake_education_group_year.education_group_type)
    post_data = {
        'main_teaching_campus': str(fake_education_group_year.main_teaching_campus.id),
        'management_entity': str(entity_version.id),
        'remark_english': str(fake_education_group_year.remark_english),
        'title_english': str(fake_education_group_year.title_english),
        'partial_acronym': str(fake_education_group_year.partial_acronym),
        'end_year': str(fake_education_group_year.education_group.end_year),
        'start_year': str(fake_education_group_year.education_group.start_year),
        'title': str(fake_education_group_year.title),
        'credits': str(fake_education_group_year.credits),
        'academic_year': str(fake_education_group_year.academic_year.id),
        'constraint_type': CREDITS,
        'max_constraint': str(fake_education_group_year.max_constraint),
        'min_constraint': str(fake_education_group_year.min_constraint),
        'remark': str(fake_education_group_year.remark),
        'acronym': str(fake_education_group_year.acronym),
        'active': str(fake_education_group_year.active),
        'schedule_type': str(fake_education_group_year.schedule_type),
    }
    return fake_education_group_year, post_data
Пример #7
0
    def test_update_with_parent_when_existing_group_element_year(
            self, mock_find_authorized_types):
        parent = EducationGroupYearFactory(
            academic_year=self.expected_educ_group_year.academic_year,
            education_group__end_year=None)

        entity_version = MainEntityVersionFactory()
        initial_educ_group_year = MiniTrainingFactory(
            management_entity=entity_version.entity,
            academic_year=self.expected_educ_group_year.academic_year,
            education_group__start_year=starting_academic_year())

        GroupElementYearFactory(parent=parent,
                                child_branch=initial_educ_group_year)
        initial_count = GroupElementYear.objects.all().count()

        form = self.form_class(data=self.post_data,
                               instance=initial_educ_group_year,
                               parent=parent,
                               user=self.user)
        self.assertTrue(form.is_valid(), form.errors)
        updated_education_group_year = form.save()

        # Assert existing GroupElementYear is reused.
        self.assertEqual(initial_count, GroupElementYear.objects.all().count())
        self._assert_all_fields_correctly_saved(updated_education_group_year)
        self.assertTrue(form.forms[ModelForm].fields["academic_year"].disabled)
Пример #8
0
    def test_post(self):
        new_entity_version = MainEntityVersionFactory()
        PersonEntityFactory(person=self.person, entity=new_entity_version.entity)

        data = {
            'title': 'Cours au choix',
            'title_english': 'deaze',
            'education_group_type': self.education_group_year.education_group_type.id,
            'credits': 42,
            'acronym': 'CRSCHOIXDVLD',
            'partial_acronym': 'LDVLD101R',
            'management_entity': new_entity_version.pk,
            'main_teaching_campus': "",
            'academic_year': self.education_group_year.academic_year.pk,
            "constraint_type": "",
        }
        response = self.client.post(self.url, data=data)

        self.assertEqual(response.status_code, 302)
        self.education_group_year.refresh_from_db()
        self.assertEqual(self.education_group_year.title, 'Cours au choix')
        self.assertEqual(self.education_group_year.title_english, 'deaze')
        self.assertEqual(self.education_group_year.credits, 42)
        self.assertEqual(self.education_group_year.acronym, 'CRSCHOIXDVLD')
        self.assertEqual(self.education_group_year.partial_acronym, 'LDVLD101R')
        self.assertEqual(self.education_group_year.management_entity, new_entity_version.entity)
Пример #9
0
    def test_update_without_parent(self):
        entity_version = MainEntityVersionFactory()
        education_group_type = MiniTrainingEducationGroupTypeFactory()
        initial_educ_group_year = EducationGroupYearFactory(
            academic_year=current_academic_year(),
            management_entity=entity_version.entity,
            education_group__start_year=current_academic_year(),
            education_group_type=education_group_type)

        initial_educ_group = initial_educ_group_year.education_group

        form = self.form_class(data=self.post_data,
                               instance=initial_educ_group_year,
                               parent=None,
                               user=self.user)
        self.assertTrue(form.is_valid(), form.errors)
        updated_educ_group_year = form.save()

        self.assertEqual(updated_educ_group_year.pk,
                         initial_educ_group_year.pk)
        # Assert keep the same EducationGroup when update
        self.assertEqual(updated_educ_group_year.education_group,
                         initial_educ_group)
        self._assert_all_fields_correctly_saved(updated_educ_group_year)
        self.assertTrue(form.forms[ModelForm].fields["academic_year"].disabled)
Пример #10
0
    def test_post_mini_training(self):
        old_domain = DomainFactory()
        EducationGroupYearDomainFactory(
            education_group_year=self.mini_training_education_group_year,
            domain=old_domain)

        new_entity_version = MainEntityVersionFactory()
        PersonEntityFactory(person=self.person,
                            entity=new_entity_version.entity)
        data = {
            'title':
            'Cours au choix',
            'title_english':
            'deaze',
            'education_group_type':
            self.a_mini_training_education_group_type.pk,
            'credits':
            42,
            'acronym':
            'CRSCHOIXDVLD',
            'partial_acronym':
            'LDVLD101R',
            'management_entity':
            new_entity_version.pk,
            'main_teaching_campus':
            "",
            'academic_year':
            self.mini_training_education_group_year.academic_year.pk,
            'active':
            ACTIVE,
            'schedule_type':
            DAILY,
            "primary_language":
            LanguageFactory().pk,
            "start_year":
            2010,
            "constraint_type":
            "",
            "diploma_printing_title":
            "Diploma Title",
        }
        response = self.client.post(self.mini_training_url, data=data)
        self.assertEqual(response.status_code,
                         HttpResponseRedirect.status_code)

        self.mini_training_education_group_year.refresh_from_db()
        self.assertEqual(self.mini_training_education_group_year.title,
                         'Cours au choix')
        self.assertEqual(self.mini_training_education_group_year.title_english,
                         'deaze')
        self.assertEqual(self.mini_training_education_group_year.credits, 42)
        self.assertEqual(self.mini_training_education_group_year.acronym,
                         'CRSCHOIXDVLD')
        self.assertEqual(
            self.mini_training_education_group_year.partial_acronym,
            'LDVLD101R')
        self.assertEqual(
            self.mini_training_education_group_year.management_entity,
            new_entity_version.entity)
Пример #11
0
 def setUpTestData(cls):
     start_year = AcademicYearFactory(year=get_current_year())
     end_year = AcademicYearFactory(year=get_current_year() + 40)
     cls.list_acs = GenerateAcademicYear(start_year,
                                         end_year).academic_years
     # Create user and attached it to management entity
     cls.person = PersonFactory()
     cls.user = cls.person.user
     cls.management_entity_version = MainEntityVersionFactory()
     cls.education_group_type = EducationGroupTypeFactory(
         category=education_group_categories.TRAINING,
         name=education_group_types.TrainingType.BACHELOR)
Пример #12
0
    def test_post_training(self):
        old_domain = DomainFactory()
        EducationGroupYearDomainFactory(
            education_group_year=self.training_education_group_year,
            domain=old_domain
        )

        new_entity_version = MainEntityVersionFactory()
        PersonEntityFactory(person=self.person, entity=new_entity_version.entity)
        list_domains = [domain.pk for domain in self.domains]
        data = {
            'title': 'Cours au choix',
            'title_english': 'deaze',
            'education_group_type': self.an_training_education_group_type.pk,
            'credits': 42,
            'acronym': 'CRSCHOIXDVLD',
            'partial_acronym': 'LDVLD101R',
            'management_entity': new_entity_version.pk,
            'administration_entity': new_entity_version.pk,
            'main_teaching_campus': "",
            'academic_year': self.training_education_group_year.academic_year.pk,
            'secondary_domains': ['|' + ('|'.join([str(domain.pk) for domain in self.domains])) + '|'],
            'active': ACTIVE,
            'schedule_type': DAILY,
            "internship": internship_presence.NO,
            "primary_language": LanguageFactory().pk,
            "start_year": 2010,
            "constraint_type": "",
        }
        response = self.client.post(self.training_url, data=data)
        self.assertEqual(response.status_code, 302)

        self.training_education_group_year.refresh_from_db()
        self.assertEqual(self.training_education_group_year.title, 'Cours au choix')
        self.assertEqual(self.training_education_group_year.title_english, 'deaze')
        self.assertEqual(self.training_education_group_year.credits, 42)
        self.assertEqual(self.training_education_group_year.acronym, 'CRSCHOIXDVLD')
        self.assertEqual(self.training_education_group_year.partial_acronym, 'LDVLD101R')
        self.assertEqual(self.training_education_group_year.management_entity, new_entity_version.entity)
        self.assertEqual(self.training_education_group_year.administration_entity, new_entity_version.entity)
        self.assertListEqual(
            list(self.training_education_group_year.secondary_domains.values_list('id', flat=True)),
            list_domains
        )
        self.assertNotIn(old_domain, self.education_group_year.secondary_domains.all())
Пример #13
0
    def test_post_training_removing_coorganization(self):
        new_entity_version = MainEntityVersionFactory()
        egy = TrainingFactory(
            education_group_type__name=TrainingType.AGGREGATION.name,
            management_entity=new_entity_version.entity,
            administration_entity=new_entity_version.entity)
        PersonEntityFactory(person=self.person,
                            entity=new_entity_version.entity)
        address = OrganizationAddressFactory(
            organization=OrganizationFactory(), is_main=True)
        egy_organization = EducationGroupOrganizationFactory(
            organization=OrganizationFactory(), education_group_year=egy)
        diploma_choice = random.choice(DiplomaCoorganizationTypes.get_names())

        data = {
            'title': 'Cours au choix',
            'education_group_type': egy.education_group_type.pk,
            'acronym': 'CRSCHOIXDVLD',
            'partial_acronym': 'LDVLD101R',
            'management_entity': new_entity_version.pk,
            'administration_entity': new_entity_version.pk,
            'academic_year': egy.academic_year.pk,
            'active': ACTIVE,
            'schedule_type': DAILY,
            "internship": internship_presence.NO,
            "primary_language": LanguageFactory().pk,
            "constraint_type": "",
            "diploma_printing_title": "Diploma Title",
            'form-TOTAL_FORMS': 1,
            'form-INITIAL_FORMS': 1,
            'form-0-country': address.country.pk,
            'form-0-organization': egy_organization.organization.pk,
            'form-0-diploma': diploma_choice,
            'form-0-DELETE': 'on',
            'form-0-id': egy_organization.pk
        }

        url = reverse(update_education_group, args=[egy.pk, egy.pk])
        response = self.client.post(url, data=data)
        self.assertEqual(response.status_code, 302)

        egy.refresh_from_db()
        coorganizations = egy.coorganizations
        self.assertEqual(coorganizations.count(), 0)
Пример #14
0
    def setUp(cls, **kwargs):
        cls.education_group_type = kwargs.pop('education_group_type')

        cls.campus = CampusFactory(organization__type=organization_type.MAIN)
        cls.academic_year = AcademicYearFactory()
        new_entity_version = MainEntityVersionFactory()

        cls.form_data = {
            "acronym": "ACRO4569",
            "partial_acronym": "PACR8974",
            "education_group_type": cls.education_group_type.id,
            "title": "Test data",
            "main_teaching_campus": cls.campus.id,
            "academic_year": cls.academic_year.id,
            "management_entity": new_entity_version.pk,
            "remark": "This is a test!!"
        }

        cls.parent_education_group_year = EducationGroupYearFactory(
            academic_year=cls.academic_year)
        cls.entity_version = EntityVersionFactory(
            entity=cls.parent_education_group_year.management_entity)
Пример #15
0
    def setUp(self, **kwargs):
        self.education_group_type = kwargs.pop('education_group_type')

        self.campus = CampusFactory(organization__type=organization_type.MAIN)
        self.academic_year = AcademicYearFactory()
        new_entity_version = MainEntityVersionFactory()

        self.form_data = {
            "acronym": "ACRO4569",
            "partial_acronym": "PACR8974",
            "education_group_type": self.education_group_type.id,
            "title": "Test data",
            "main_teaching_campus": self.campus.id,
            "academic_year": self.academic_year.id,
            "management_entity": new_entity_version.pk,
            "remark": "This is a test!!"
        }

        self.parent_education_group_year = EducationGroupYearFactory(academic_year=self.academic_year)
        # Append version to management/administration entity
        self.entity_version = EntityVersionFactory(entity=self.parent_education_group_year.management_entity)
        if self.education_group_type.category == TRAINING:
            EntityVersionFactory(entity=self.parent_education_group_year.administration_entity)
Пример #16
0
 def test_post_training_with_end_year(self):
     new_entity_version = MainEntityVersionFactory()
     PersonEntityFactory(person=self.person, entity=new_entity_version.entity)
     data = {
         'title': 'Cours au choix',
         'title_english': 'deaze',
         'education_group_type': self.an_training_education_group_type.pk,
         'credits': 42,
         'acronym': 'CRSCHOIXDVLD',
         'partial_acronym': 'LDVLD101R',
         'management_entity': new_entity_version.pk,
         'administration_entity': new_entity_version.pk,
         'main_teaching_campus': "",
         'academic_year': self.training_education_group_year.academic_year.pk,
         'secondary_domains': ['|' + ('|'.join([str(domain.pk) for domain in self.domains])) + '|'],
         'active': ACTIVE,
         'schedule_type': DAILY,
         "internship": internship_presence.NO,
         "primary_language": LanguageFactory().pk,
         "start_year": 2010,
         "end_year": 2018,
         "constraint_type": "",
     }
     response = self.client.post(self.training_url, data=data)
     messages = [m.message for m in get_messages(response.wsgi_request)]
     self.assertEqual(
         messages[1], _("Education group year %(acronym)s (%(academic_year)s) successfuly deleted.") % {
             "acronym": self.training_education_group_year_1.acronym,
             "academic_year": self.training_education_group_year_1.academic_year,
         }
     )
     self.assertEqual(
         messages[2], _("Education group year %(acronym)s (%(academic_year)s) successfuly deleted.") % {
             "acronym": self.training_education_group_year_2.acronym,
             "academic_year": self.training_education_group_year_2.academic_year,
         }
     )
Пример #17
0
    def setUpTestData(cls):
        super().setUpTestData()

        cls.current_academic_year = AcademicYearFactory(current=True)
        cls.generated_ac_years = AcademicYearFactory.produce(
            base_year=cls.current_academic_year.year,
            number_past=0,
            number_future=7)
        cls.entity_version = MainEntityVersionFactory(
            entity_type=entity_type.SECTOR)
        cls.central_manager = CentralManagerFactory()
        PersonEntityFactory(person=cls.central_manager,
                            entity=cls.entity_version.entity)
        cls.training = TrainingFactory(
            management_entity=cls.entity_version.entity,
            administration_entity=cls.entity_version.entity,
            academic_year=cls.current_academic_year)
        # Save the training instance will create N+6 data...
        form_data = model_to_dict_fk(cls.training,
                                     exclude=('secondary_domains', ))
        form_data.update({
            'primary_language': form_data['primary_language_id'],
            'administration_entity': cls.entity_version.pk,
            'management_entity': cls.entity_version.pk
        })
        training_form = TrainingForm(form_data,
                                     instance=cls.training,
                                     user=cls.central_manager.user)
        training_form.is_valid()
        training_form.save()

        cls.certificate_aim_type_2 = CertificateAimFactory(section=2, code=200)
        cls.certificate_aim_type_4 = CertificateAimFactory(section=4, code=400)
        cls.form_data = {
            'certificate_aims':
            [cls.certificate_aim_type_2.pk, cls.certificate_aim_type_4.pk]
        }