Beispiel #1
0
    def test_save_with_postponement_sets_inconsistents(self):
        # create postponed egy's
        self._create_postponed_egys()

        # update with inconsistant EducationGroupOrganization (organization present in the future not in present)
        self.education_group_year.refresh_from_db()
        unconsistent_egy = EducationGroupYear.objects.get(
            education_group=self.education_group_year.education_group,
            academic_year=self.list_acs[4])
        EducationGroupOrganizationFactory(
            organization=OrganizationFactory(),
            education_group_year=unconsistent_egy)
        EducationGroupOrganizationFactory(
            organization=OrganizationFactory(),
            education_group_year=self.education_group_year)

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

        self.assertGreater(len(form.warnings), 0)
        self.assertEqual(form.warnings, [
            _("Consistency error in %(academic_year)s : %(error)s") % {
                'academic_year': unconsistent_egy.academic_year,
                'error': EducationGroupOrganization._meta.verbose_name.title()
            }
        ])
 def test_unique(self):
     EducationGroupOrganizationFactory(
         education_group_year=self.education_group_year,
         organization=self.organization)
     with self.assertRaises(IntegrityError):
         EducationGroupOrganizationFactory(
             education_group_year=self.education_group_year,
             organization=self.organization)
Beispiel #3
0
    def setUpTestData(cls):
        cls.user = UserFactory()
        cls.person = CentralManagerFactory(user=cls.user)

        cls.academic_year = create_current_academic_year()
        cls.education_group_yr = EducationGroupYearFactory(
            acronym='ARKE2A',
            academic_year=cls.academic_year,
            education_group_type=EducationGroupTypeFactory(
                category=education_group_categories.TRAINING),
            management_entity=EntityFactory())

        cls.root_id = cls.education_group_yr.id
        cls.country_be = CountryFactory()

        cls.organization_address = OrganizationAddressFactory(
            country=cls.country_be)
        cls.organization = cls.organization_address.organization
        cls.education_group_organization = EducationGroupOrganizationFactory(
            organization=cls.organization,
            education_group_year=cls.education_group_yr,
            diploma=diploma_coorganization.UNIQUE,
            all_students=True,
        )
        cls.organization_bis = OrganizationFactory()
        cls.address = OrganizationAddressFactory(
            organization=cls.organization_bis, is_main=True)
Beispiel #4
0
    def test_init(self):
        # In case of creation
        form = TrainingForm({},
                            user=self.user,
                            education_group_type=self.education_group_type)
        self.assertFalse(form.dict_initial_egy)
        self.assertEqual(form.initial_dicts,
                         {'educationgrouporganization_set': {}})

        # In case of update
        coorg = EducationGroupOrganizationFactory(
            organization=OrganizationFactory(),
            education_group_year=self.education_group_year)
        form = TrainingForm({},
                            user=self.user,
                            instance=self.education_group_year)
        dict_initial_egy = model_to_dict_fk(self.education_group_year,
                                            exclude=form.field_to_exclude)

        self.assertEqual(str(form.dict_initial_egy), str(dict_initial_egy))
        initial_dict_coorg = model_to_dict_fk(
            self.education_group_year.coorganizations.first(),
            exclude=FIELD_TO_EXCLUDE_IN_SET)
        self.assertEqual(
            form.initial_dicts, {
                'educationgrouporganization_set': {
                    coorg.organization.id: initial_dict_coorg
                }
            })
Beispiel #5
0
    def test_versions(self):
        response = self.client.get(self.url)
        self.assertEqual(len(response.context["versions"]), 0)

        with reversion.create_revision():
            self.education_group_child_1.acronym = "Snape"
            self.education_group_child_1.save()

        response = self.client.get(self.url)
        self.assertEqual(len(response.context["versions"]), 1)

        with reversion.create_revision():
            EducationGroupOrganizationFactory(
                education_group_year=self.education_group_child_1)

        response = self.client.get(self.url)
        self.assertEqual(len(response.context["versions"]), 2)
Beispiel #6
0
    def test_save_with_postponement_coorganization_inconsistant(self):
        # create postponed egy's
        self._create_postponed_egys()

        # update with a coorganization to postpone
        self.education_group_year.refresh_from_db()

        good_organization = EducationGroupOrganizationFactory(
            organization=OrganizationFactory(),
            education_group_year=self.education_group_year)
        self._postpone_coorganization_and_check()

        # update with unconsistant EducationGroupOrganization (field different from a year to another one)
        self.education_group_year.refresh_from_db()
        unconsistent_egy = EducationGroupYear.objects.get(
            education_group=self.education_group_year.education_group,
            academic_year=self.list_acs[4])
        unconsistent_orga = EducationGroupOrganization.objects.get(
            education_group_year=unconsistent_egy)
        unconsistent_orga.all_students = not good_organization.all_students
        unconsistent_orga.save()
        # have to invalidate cache
        del self.education_group_year.coorganizations
        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.warnings), 1)
        error_msg = _("%(col_name)s has been already modified.") % {
            "col_name":
            _(
                EducationGroupOrganization._meta.get_field(
                    'all_students').verbose_name).title(),
        }
        self.assertEqual(form.warnings, [
            _("Consistency error in %(academic_year)s with %(model)s: %(error)s"
              ) %
            {
                'academic_year': unconsistent_egy.academic_year,
                'model': EducationGroupOrganization._meta.verbose_name.title(),
                'error': error_msg
            }
        ])
Beispiel #7
0
    def setUp(self):
        self.academic_year = create_current_academic_year()
        self.person = CentralManagerFactory("can_access_education_group")

        # Create an organization with main address
        self.organization = OrganizationFactory()
        self.main_organization_address = OrganizationAddressFactory(
            organization=self.organization, is_main=True)

        # Create Training which is co-organized
        self.training_egy = TrainingFactory(academic_year=self.academic_year)
        self.education_group_organization = EducationGroupOrganizationFactory(
            organization=self.organization,
            education_group_year=self.training_egy,
            diploma=diploma_coorganization.UNIQUE,
            all_students=True,
        )
        self.client.force_login(self.person.user)
Beispiel #8
0
    def test_formset_with_organization_already_attached_to_egy(self):
        egy = EducationGroupYearFactory()
        egy_organization = EducationGroupOrganizationFactory(
            organization=self.organization_bis, education_group_year=egy)
        self.data['form-0-organization'] = egy_organization.organization.pk

        form = OrganizationFormset(
            data=self.data,
            form_kwargs={
                'education_group_year': egy,
                'user': self.user
            },
        )
        self.assertFalse(form.is_valid(), form.errors)
        self.assertEqual(form.errors, [{
            'organization':
            [_('There is already a coorganization with this organization')]
        }])
Beispiel #9
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)
Beispiel #10
0
    def test_save_with_postponement(self):
        # Create postponed egy
        self._create_postponed_egys()

        # Update egys
        self.education_group_year.refresh_from_db()

        self.assertEqual(
            self.education_group_year.educationgrouporganization_set.all().
            count(), 0)
        EducationGroupOrganizationFactory(
            organization=OrganizationFactory(),
            education_group_year=self.education_group_year)
        self.assertEqual(
            self.education_group_year.educationgrouporganization_set.all().
            count(), 1)

        self.data["title"] = "Defence Against the Dark Arts"
        self._postpone_coorganization_and_check()
Beispiel #11
0
    def test_education_group_read(self, mock_find_by_id, mock_program_manager,
                                  mock_render, mock_decorators):
        mock_decorators.login_required = lambda x: x
        mock_decorators.permission_required = lambda *args, **kwargs: lambda func: func
        education_group_year = EducationGroupYearFactory(
            academic_year=self.academic_year)
        organization = EducationGroupOrganizationFactory(
            education_group_year=education_group_year)
        request = mock.Mock(method='GET')

        from base.views.education_group import education_group_read

        mock_find_by_id.return_value = education_group_year
        education_group_read(request, education_group_year.id)
        self.assertTrue(mock_render.called)
        request, template, context = mock_render.call_args[0]
        self.assertEqual(template, 'education_group/tab_identification.html')
        self.assertEqual(
            context['education_group_year'].coorganizations.first(),
            organization)
        self.assertEqual(
            context['education_group_year'].coorganizations.first().address,
            organization.address)
Beispiel #12
0
    def setUp(self):
        self.user = UserFactory()
        self.client.force_login(self.user)
        self.person = PersonFactory(user=self.user)
        self.user.user_permissions.add(Permission.objects.get(codename="can_access_education_group"))

        self.academic_year = create_current_academic_year()
        self.education_group_yr = EducationGroupYearFactory(
            acronym='ARKE2A', academic_year=self.academic_year,
            education_group_type=EducationGroupTypeFactory(category=education_group_categories.TRAINING),
            management_entity=EntityFactory()
        )

        self.root_id = self.education_group_yr.id
        self.country_be = CountryFactory()

        self.organization_address = OrganizationAddressFactory(country=self.country_be)
        self.organization = self.organization_address.organization
        self.education_group_organization = EducationGroupOrganizationFactory(
            organization=self.organization,
            education_group_year=self.education_group_yr,
            diploma=diploma_coorganization.UNIQUE,
            all_students=True,
        )