Ejemplo n.º 1
0
    def test_save_with_postponement_m2m(self):
        domains = [
            DomainFactory(name="Alchemy"),
            DomainFactory(name="Muggle Studies")
        ]
        self.data["secondary_domains"] = '|'.join(
            [str(domain.pk) for domain in domains])

        certificate_aims = [
            CertificateAimFactory(code=100, section=1),
            CertificateAimFactory(code=101, section=2)
        ]
        self.data["certificate_aims"] = [
            str(aim.pk) for aim in certificate_aims
        ]

        self._create_postponed_egys()

        last = EducationGroupYear.objects.filter(
            education_group=self.education_group_year.education_group
        ).order_by('academic_year').last()

        self.education_group_year.refresh_from_db()
        self.assertEqual(self.education_group_year.secondary_domains.count(),
                         2)
        self.assertEqual(last.secondary_domains.count(), 2)
        self.assertEqual(last.certificate_aims.count(), len(certificate_aims))

        # update with a conflict
        dom3 = DomainFactory(name="Divination")
        EducationGroupYearDomainFactory(domain=dom3, education_group_year=last)

        domains = [
            DomainFactory(name="Care of Magical Creatures"),
            DomainFactory(name="Muggle Studies")
        ]

        self.data["secondary_domains"] = '|'.join(
            [str(domain.pk) for domain in domains])

        form = TrainingForm(self.data,
                            instance=self.education_group_year,
                            user=self.user)
        self.assertTrue(form.is_valid(), form.errors)
        form.save()

        self.assertEqual(len(form.education_group_year_postponed), 5)

        self.assertEqual(
            EducationGroupYear.objects.filter(
                education_group=self.education_group_year.education_group).
            count(), 7)
        last.refresh_from_db()
        self.education_group_year.refresh_from_db()

        self.assertEqual(self.education_group_year.secondary_domains.count(),
                         2)
        self.assertEqual(last.secondary_domains.count(), 3)
        self.assertEqual(len(form.warnings), 1)
Ejemplo n.º 2
0
    def test_with_subdomains(self):
        children_1 = DomainFactory(parent=self.parent_domain)
        children_2 = DomainFactory(parent=self.parent_domain)

        subdomains = list(domain.find_subdomains(self.parent_domain))
        self.assertEqual(len(subdomains), 2)
        self.assertIn(children_1, subdomains)
        self.assertIn(children_2, subdomains)
Ejemplo n.º 3
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)
Ejemplo n.º 4
0
    def setUp(self):
        self.current_academic_year = create_current_academic_year()

        self.education_group_year = GroupFactory()

        EntityVersionFactory(
            entity=self.education_group_year.management_entity,
            start_date=self.education_group_year.academic_year.start_date)

        EntityVersionFactory(
            entity=self.education_group_year.administration_entity,
            start_date=self.education_group_year.academic_year.start_date)

        AuthorizedRelationshipFactory(
            parent_type=self.education_group_year.education_group_type,
            child_type=self.education_group_year.education_group_type)

        self.url = reverse(
            update_education_group,
            args=[self.education_group_year.pk, self.education_group_year.pk])
        self.person = PersonFactory()

        self.client.force_login(self.person.user)
        permission = Permission.objects.get(codename='change_educationgroup')
        self.person.user.user_permissions.add(permission)
        self.perm_patcher = mock.patch(
            "base.business.education_groups.perms.is_eligible_to_change_education_group",
            return_value=True)
        self.mocked_perm = self.perm_patcher.start()

        self.an_training_education_group_type = EducationGroupTypeFactory(
            category=education_group_categories.TRAINING)

        self.training_education_group_year = TrainingFactory(
            academic_year=self.current_academic_year,
            education_group_type=self.an_training_education_group_type)

        AuthorizedRelationshipFactory(
            parent_type=self.an_training_education_group_type,
            child_type=self.an_training_education_group_type,
        )

        EntityVersionFactory(
            entity=self.training_education_group_year.management_entity,
            start_date=self.education_group_year.academic_year.start_date)

        EntityVersionFactory(
            entity=self.training_education_group_year.administration_entity,
            start_date=self.education_group_year.academic_year.start_date)

        self.training_url = reverse(update_education_group,
                                    args=[
                                        self.training_education_group_year.pk,
                                        self.training_education_group_year.pk
                                    ])

        self.domains = [DomainFactory() for x in range(10)]
Ejemplo n.º 5
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())
Ejemplo n.º 6
0
 def setUp(self):
     self.parent_domain = DomainFactory()
Ejemplo n.º 7
0
    def setUp(self):
        self.current_academic_year = create_current_academic_year()
        self.start_date_ay_1 = self.current_academic_year.start_date.replace(
            year=self.current_academic_year.year + 1)
        self.end_date_ay_1 = self.current_academic_year.end_date.replace(
            year=self.current_academic_year.year + 2)
        self.previous_academic_year = AcademicYearFactory(
            year=self.current_academic_year.year - 1)
        academic_year_1 = AcademicYearFactory.build(
            start_date=self.start_date_ay_1,
            end_date=self.end_date_ay_1,
            year=self.current_academic_year.year + 1)
        academic_year_1.save()

        self.start_date_ay_2 = self.current_academic_year.start_date.replace(
            year=self.current_academic_year.year + 2)
        self.end_date_ay_2 = self.current_academic_year.end_date.replace(
            year=self.current_academic_year.year + 3)
        academic_year_2 = AcademicYearFactory.build(
            start_date=self.start_date_ay_2,
            end_date=self.end_date_ay_2,
            year=self.current_academic_year.year + 2)
        academic_year_2.save()

        self.education_group_year = GroupFactory()

        EntityVersionFactory(
            entity=self.education_group_year.management_entity,
            start_date=self.education_group_year.academic_year.start_date)

        EntityVersionFactory(
            entity=self.education_group_year.administration_entity,
            start_date=self.education_group_year.academic_year.start_date)

        AuthorizedRelationshipFactory(
            parent_type=self.education_group_year.education_group_type,
            child_type=self.education_group_year.education_group_type)

        self.url = reverse(update_education_group,
                           kwargs={
                               "root_id":
                               self.education_group_year.pk,
                               "education_group_year_id":
                               self.education_group_year.pk
                           })
        self.person = CentralManagerFactory()
        PersonEntityFactory(person=self.person,
                            entity=self.education_group_year.management_entity)
        self.client.force_login(self.person.user)
        permission = Permission.objects.get(codename='change_educationgroup')
        self.person.user.user_permissions.add(permission)
        self.perm_patcher = mock.patch(
            "base.business.education_groups.perms._is_eligible_certificate_aims",
            return_value=True)
        self.mocked_perm = self.perm_patcher.start()

        self.an_training_education_group_type = EducationGroupTypeFactory(
            category=education_group_categories.TRAINING)

        self.previous_training_education_group_year = TrainingFactory(
            academic_year=self.previous_academic_year,
            education_group_type=self.an_training_education_group_type,
            education_group__start_year=1968)

        EntityVersionFactory(
            entity=self.previous_training_education_group_year.
            management_entity,
            start_date=self.previous_training_education_group_year.
            academic_year.start_date)

        EntityVersionFactory(
            entity=self.previous_training_education_group_year.
            administration_entity,
            start_date=self.previous_training_education_group_year.
            academic_year.start_date)

        self.training_education_group_year = TrainingFactory(
            academic_year=self.current_academic_year,
            education_group_type=self.an_training_education_group_type,
            education_group__start_year=1968)

        self.training_education_group_year_1 = TrainingFactory(
            academic_year=academic_year_1,
            education_group_type=self.an_training_education_group_type,
            education_group=self.training_education_group_year.education_group)

        self.training_education_group_year_2 = TrainingFactory(
            academic_year=academic_year_2,
            education_group_type=self.an_training_education_group_type,
            education_group=self.training_education_group_year.education_group)

        AuthorizedRelationshipFactory(
            parent_type=self.an_training_education_group_type,
            child_type=self.an_training_education_group_type,
        )

        EntityVersionFactory(
            entity=self.training_education_group_year.management_entity,
            start_date=self.education_group_year.academic_year.start_date)

        EntityVersionFactory(
            entity=self.training_education_group_year.administration_entity,
            start_date=self.education_group_year.academic_year.start_date)

        self.training_url = reverse(update_education_group,
                                    args=[
                                        self.training_education_group_year.pk,
                                        self.training_education_group_year.pk
                                    ])
        PersonEntityFactory(
            person=self.person,
            entity=self.training_education_group_year.management_entity)

        self.domains = [DomainFactory() for x in range(10)]

        self.a_mini_training_education_group_type = EducationGroupTypeFactory(
            category=education_group_categories.MINI_TRAINING)

        self.mini_training_education_group_year = MiniTrainingFactory(
            academic_year=self.current_academic_year,
            education_group_type=self.a_mini_training_education_group_type)

        self.mini_training_url = reverse(
            update_education_group,
            args=[
                self.mini_training_education_group_year.pk,
                self.mini_training_education_group_year.pk
            ])
        PersonEntityFactory(
            person=self.person,
            entity=self.mini_training_education_group_year.management_entity)

        EntityVersionFactory(
            entity=self.mini_training_education_group_year.management_entity,
            start_date=self.education_group_year.academic_year.start_date)
Ejemplo n.º 8
0
 def test_sorting_domain(self):
     expected_value = ('-decree__name', 'code', 'name')
     domain = DomainFactory(decree=self.decree, code='11', name='Test1')
     self.assertEqual(domain._meta.ordering, expected_value)
Ejemplo n.º 9
0
 def test_str_without_code(self):
     dom = DomainFactory(decree=self.decree, code='', name='Test Domain')
     expected_value = "{decree}: {name}".format(decree=dom.decree.name,
                                                name=dom.name)
     self.assertEqual(str(dom), expected_value)
Ejemplo n.º 10
0
 def test_str_without_decree(self):
     dom = DomainFactory(decree=None, code='10H', name='Test Domain')
     expected_value = "{code} {name}".format(code=dom.code, name=dom.name)
     self.assertEqual(str(dom), expected_value)