Beispiel #1
0
 def setUp(self):
     self.organization_address = OrganizationAddressFactory(
         organization=self.organization,
         country__iso_code='BE',
         is_main=True
     )
     self.client.force_login(user=self.super_user)
Beispiel #2
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 #3
0
    def setUp(self):
        self.super_user = SuperUserFactory()
        self.url = reverse("organization_autocomplete")

        self.organization = OrganizationFactory(name="Université de Louvain")
        self.organization_address = OrganizationAddressFactory(
            organization=self.organization,
            country__iso_code='BE',
            is_main=True)
 def test_organization_address_save(self):
     address = OrganizationAddressFactory(organization=self.organization)
     country = address.country
     url = reverse('organization_address_save', args=[address.id])
     response = self.client.post(url,
                                 data=get_form_organization_address_save())
     address.refresh_from_db()
     self.assertEqual(response.status_code, 200)
     self.assertEqual(address.location, "476 5th Ave")
     self.assertEqual(address.postal_code, "10018")
     self.assertEqual(address.city, "New York")
     self.assertEqual(address.country, country)
Beispiel #5
0
    def test_organization_address_delete(self):
        address = OrganizationAddressFactory(organization=self.organization)

        response = self.client.post(reverse(organization_address_delete, args=[address.id]))
        self.assertRedirects(response, reverse("organization_read", args=[self.organization.pk]))
        with self.assertRaises(ObjectDoesNotExist):
            organization_address.OrganizationAddress.objects.get(id=address.id)
Beispiel #6
0
    def test_organization_address_edit(self):
        from base.views.organization import organization_address_edit
        address = OrganizationAddressFactory(organization=self.organization)
        response = self.client.get(reverse(organization_address_edit, args=[address.id]))

        self.assertTemplateUsed(response, "organization/organization_address_form.html")
        self.assertEqual(response.context.get("organization_address"), address)
Beispiel #7
0
    def setUp(self):
        self.academic_year = create_current_academic_year()

        self.be_organization_adr_city1 = OrganizationAddressFactory(country__iso_code="BE", city=NAMEN)
        self.external_lu_1 = ExternalLearningUnitYearFactory(
            co_graduation=True,
            learning_unit_year__academic_year=self.academic_year,
            learning_unit_year__acronym='EDROI1001',
            learning_unit_year__campus__organization=self.be_organization_adr_city1.organization,
        )

        self.be_organization_adr_city2 = OrganizationAddressFactory(country__iso_code="BE", city='Bruxelles')
        self.external_lu_2 = ExternalLearningUnitYearFactory(
            co_graduation=True,
            learning_unit_year__academic_year=self.academic_year,
            learning_unit_year__acronym='EDROI1002',
            learning_unit_year__campus__organization=self.be_organization_adr_city2.organization,
        )
Beispiel #8
0
    def test_init(self):
        campus = CampusFactory()
        address = OrganizationAddressFactory(is_main=True, organization=campus.organization)

        luy = LearningUnitYearFullFactory(campus=campus)

        form = LearningUnitYearForExternalModelForm(
            person=self.person, data=None,
            subtype=FULL, instance=luy, initial={})
        self.assertEqual(form.fields["country_external_institution"].initial, address.country.pk)
Beispiel #9
0
    def setUpTestData(cls):
        cls.super_user = SuperUserFactory()
        cls.url = reverse("campus-autocomplete")

        cls.organization = OrganizationFactory(name="Université de Louvain")
        cls.organization_address = OrganizationAddressFactory(
            organization=cls.organization,
            country__iso_code='BE',
            is_main=True
        )
        cls.campus = CampusFactory(organization=cls.organization)
Beispiel #10
0
    def test_organization_address_delete(self, mock_render):
        from base.views.organization import organization_address_delete
        address = OrganizationAddressFactory(organization=self.organization)

        request_factory = RequestFactory()
        request = request_factory.get(reverse(organization_address_delete, args=[address.id]))
        request.user = mock.Mock()

        organization_address_delete(request, address.id)

        self.assertTrue(mock_render.called)
        with self.assertRaises(ObjectDoesNotExist):
            organization_address.find_by_id(address.id)
Beispiel #11
0
    def setUp(self):
        self.academic_year = create_current_academic_year()

        self.learning_unit_year_1 = LearningUnitYearFactory(
            academic_year=self.academic_year, acronym='XLDR1001')
        self.external_lu_1 = ExternalLearningUnitYearFactory(
            external_acronym='XLDR1001',
            learning_unit_year=self.learning_unit_year_1)
        self.learning_unit_year_2 = LearningUnitYearFactory(
            academic_year=self.academic_year, acronym='XLDR1002')
        self.external_lu_2 = ExternalLearningUnitYearFactory(
            external_acronym='XLDR1002',
            learning_unit_year=self.learning_unit_year_2)

        self.a_be_country = CountryFactory(iso_code='BE')
        self.be_organization_adr_city1 = OrganizationAddressFactory(
            country=self.a_be_country, city=NAMEN)
        self.be_campus_1 = CampusFactory(
            organization=self.be_organization_adr_city1.organization)
        self.learning_container_year = LearningContainerYearFactory(
            academic_year=self.academic_year)
        self.learning_unit_year_3 = LearningUnitYearFactory(
            learning_container_year=self.learning_container_year,
            academic_year=self.academic_year,
            campus=self.be_campus_1)
        self.external_lu_BE_1 = ExternalLearningUnitYearFactory(
            learning_unit_year=self.learning_unit_year_3)

        self.be_organization_adr_city2 = OrganizationAddressFactory(
            country=self.a_be_country, city='Bruxelles')
        self.be_campus_2 = CampusFactory(
            organization=self.be_organization_adr_city2.organization)
        self.learning_container_year_4 = LearningContainerYearFactory(
            academic_year=self.academic_year)
        self.external_lu_BE_2 = ExternalLearningUnitYearFactory(
            learning_unit_year=LearningUnitYearFactory(
                learning_container_year=self.learning_container_year_4,
                academic_year=self.academic_year,
                campus=self.be_campus_2))
Beispiel #12
0
    def test_dropdown_init(self):

        country = CountryFactory()

        organization_1 = OrganizationFactory(name="organization 1")
        organization_2 = OrganizationFactory(name="organization 2")
        organization_3 = OrganizationFactory(name="organization 3")

        OrganizationAddressFactory(organization=organization_1,
                                   country=country,
                                   city=NAMUR)
        OrganizationAddressFactory(organization=organization_2,
                                   country=country,
                                   city=NAMUR)

        OrganizationAddressFactory(organization=organization_3,
                                   country=country,
                                   city=CINEY)

        CampusFactory(organization=organization_1)
        campus_2 = CampusFactory(organization=organization_1)
        campus_3 = CampusFactory(organization=organization_2)

        form = ExternalLearningUnitYearForm({
            'city': NAMUR,
            'country': country,
            "campus": campus_2
        })
        form._init_dropdown_list()

        self.assertEqual(form.fields['campus'].choices[0], (None, '---------'))
        self.assertEqual(form.fields['campus'].choices[1][1], 'organization 1')
        self.assertEqual(form.fields['campus'].choices[2],
                         (campus_3.id, 'organization 2'))

        self.assertEqual(form.fields['city'].choices, [(None, '---------'),
                                                       (CINEY, CINEY),
                                                       (NAMUR, NAMUR)])
Beispiel #13
0
    def test_organization_address_edit(self, mock_render):
        from base.views.organization import organization_address_edit
        address = OrganizationAddressFactory(organization=self.organization)
        request_factory = RequestFactory()
        request = request_factory.get(reverse(organization_address_edit, args=[address.id]))
        request.user = mock.Mock()

        organization_address_edit(request, address.id)

        self.assertTrue(mock_render.called)
        request, template, context = mock_render.call_args[0]

        self.assertEqual(template, "organization_address_form.html")
        self.assertEqual(context.get("organization_address"), address)
        self.assertEqual(context.get("organization_id"), self.organization.id)
Beispiel #14
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 #15
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 #16
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,
        )
Beispiel #17
0
class TestOrganizationAutocomplete(TestCase):
    def setUp(self):
        self.super_user = SuperUserFactory()
        self.url = reverse("organization_autocomplete")

        self.organization = OrganizationFactory(name="Université de Louvain")
        self.organization_address = OrganizationAddressFactory(
            organization=self.organization,
            country__iso_code='BE',
            is_main=True
        )

    def test_when_filter_without_country_data_forwarded_result_found(self):
        self.client.force_login(user=self.super_user)
        response = self.client.get(self.url, data={'q': 'univ'})

        expected_results = [{'text': self.organization.name, 'id': str(self.organization.pk)}]

        self.assertEqual(response.status_code, 200)
        results = _get_results_from_autocomplete_response(response)
        self.assertListEqual(results, expected_results)

    def test_when_filter_without_country_data_forwarded_no_result_found(self):
        self.client.force_login(user=self.super_user)
        response = self.client.get(self.url, data={'q': 'Grace'})

        self.assertEqual(response.status_code, 200)
        results = _get_results_from_autocomplete_response(response)
        self.assertListEqual(results, [])

    def test_when_filter_with_country_data_forwarded_result_found(self):
        self.client.force_login(user=self.super_user)
        response = self.client.get(
            self.url,
            data={'forward': '{"country": "%s"}' % self.organization_address.country.pk}
        )
        expected_results = [{'text': self.organization.name, 'id': str(self.organization.pk)}]

        self.assertEqual(response.status_code, 200)
        results = _get_results_from_autocomplete_response(response)
        self.assertListEqual(results, expected_results)

    def test_when_filter_with_country_data_forwarded_no_result_found(self):
        country = CountryFactory(iso_code='FR')

        self.client.force_login(user=self.super_user)
        response = self.client.get(
            self.url,
            data={'forward': '{"country": "%s"}' % country.pk}
        )

        self.assertEqual(response.status_code, 200)
        results = _get_results_from_autocomplete_response(response)
        self.assertListEqual(results, [])

    def test_when_filter_with_country_data_forwarded_no_result_found_case_not_main(self):
        self.organization_address.is_main = False
        self.organization_address.save()

        self.client.force_login(user=self.super_user)
        response = self.client.get(
            self.url,
            data={'forward': '{"country": "%s"}' % self.organization_address.country.pk}
        )

        self.assertEqual(response.status_code, 200)
        results = _get_results_from_autocomplete_response(response)
        self.assertListEqual(results, [])
Beispiel #18
0
 def setUpTestData(cls):
     cls.super_user = SuperUserFactory()
     cls.url = reverse("country-autocomplete")
     cls.country = CountryFactory(name="Narnia")
     OrganizationAddressFactory(country=cls.country)
Beispiel #19
0
    def setUpTestData(cls):
        cls.country = CountryFactory()

        OrganizationAddressFactory(country=cls.country, city="NAMUR")
        OrganizationAddressFactory(country=cls.country, city="DINANT")
Beispiel #20
0
 def setUp(self):
     self.super_user = SuperUserFactory()
     self.url = reverse("country-autocomplete")
     self.country = CountryFactory(name="Narnia")
     OrganizationAddressFactory(country=self.country)