Ejemplo n.º 1
0
    def test_copy_organization_from_cohort(self):
        organization = OrganizationFactory(cohort=self.cohort)
        speciality = SpecialtyFactory(cohort=self.cohort)
        copy_cohort_name = 'Copy of {} {}'.format(self.cohort.name, timezone.now())

        form_data = {
            'name': copy_cohort_name,
            'publication_start_date': self.cohort.publication_start_date.strftime('%Y-%m-%d'),
            'subscription_start_date': self.cohort.subscription_start_date.strftime('%Y-%m-%d'),
            'subscription_end_date': self.cohort.subscription_end_date.strftime('%Y-%m-%d'),
            'description': self.cohort.description,
            'originated_from': self.cohort.id,
        }

        form = CohortForm(data=form_data)

        self.assertTrue(form.is_valid())

        response = self.client.post(reverse('cohort_new'), data=form_data)
        self.assertRedirects(response, reverse('internship'))

        copy_cohort = Cohort.objects.filter(name=copy_cohort_name).first()

        self.assertEqual(copy_cohort.name, copy_cohort_name)

        copy_organization = Organization.objects.filter(cohort=copy_cohort).first()
        copy_speciality = InternshipSpeciality.objects.filter(cohort=copy_cohort).first()

        self.assertIsNotNone(copy_organization)
        self.assertIsNotNone(copy_speciality)

        self.assertEqual(organization.name, copy_organization.name)
        self.assertEqual(speciality.name, copy_speciality.name)
Ejemplo n.º 2
0
    def setUpTestData(cls):
        cls.user = User.objects.create_user('demo', '*****@*****.**',
                                            'passtest')
        permission = Permission.objects.get(codename='is_internship_manager')
        cls.user.user_permissions.add(permission)
        cls.cohort = CohortFactory()
        cls.organization = OrganizationFactory(cohort=cls.cohort)
        cls.specialty = SpecialtyFactory(mandatory=True, cohort=cls.cohort)
        cls.offer = OfferFactory(cohort=cls.cohort,
                                 organization=cls.organization,
                                 speciality=cls.specialty)
        students = [StudentFactory() for _ in range(0, 4)]
        mandatory_internship = InternshipFactory(cohort=cls.cohort,
                                                 speciality=cls.specialty)
        non_mandatory_internship = InternshipFactory(cohort=cls.cohort)

        for internship in [mandatory_internship, non_mandatory_internship]:
            for choice in CHOICES:
                create_internship_choice(organization=cls.organization,
                                         student=students[0],
                                         speciality=cls.specialty,
                                         choice=choice,
                                         internship=internship)
        for student in students[1:]:
            create_internship_choice(organization=cls.organization,
                                     student=student,
                                     speciality=cls.specialty,
                                     choice=random.choice([2, 3, 4]),
                                     internship=mandatory_internship)
        cls.url = reverse('internships', kwargs={
            'cohort_id': cls.cohort.id,
        })
Ejemplo n.º 3
0
 def setUpTestData(cls):
     cls.cohort = CohortFactory()
     cls.organizations = [
         OrganizationFactory(cohort=cls.cohort)
         for _ in range(0, N_ORGANIZATIONS)
     ]
     cls.last_switch = []
Ejemplo n.º 4
0
    def test_get_by_id(self):
        an_organization = OrganizationFactory()
        persisted_organization = organization.get_by_id(an_organization.id)
        self.assertEquals(an_organization.id, persisted_organization.id)

        nonexistent_organization = organization.get_by_id(0)
        self.assertIsNone(nonexistent_organization)
Ejemplo n.º 5
0
 def setUpTestData(cls):
     cls.user = User.objects.create_user('demo', '*****@*****.**',
                                         'passtest')
     permission = Permission.objects.get(codename='is_internship_manager')
     cls.user.user_permissions.add(permission)
     cls.cohort = CohortFactory()
     cls.organization = OrganizationFactory(cohort=cls.cohort)
Ejemplo n.º 6
0
    def test_masters_index_2(self, mock_render, mock_decorators):
        from django.db import connection
        from django.db import reset_queries

        mock_decorators.login_required = lambda x: x
        mock_decorators.permission_required = lambda *args, **kwargs: lambda func: func

        fake = faker.Faker()
        organization = OrganizationFactory(cohort=self.cohort, reference=fake.random_int(min=10, max=100))

        request_factory = RequestFactory()
        request = request_factory.get(reverse('internships_masters', kwargs={
            'cohort_id': self.cohort.id
        }))
        request.user = mock.Mock()

        from internship.views.master import masters

        reset_queries()
        self.assertEqual(len(connection.queries), 0)

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

        self.assertEqual(context['cohort_id'], self.cohort.id)
Ejemplo n.º 7
0
    def test_masters_index_bad_masters(self):
        fake = faker.Faker()
        master = MasterFactory(organization=OrganizationFactory(reference=fake.random_int(min=10, max=100)))

        url = reverse('internships_masters', kwargs={
            'cohort_id': self.cohort.id
        })

        response = self.client.get(url)
        self.assertEqual(response.status_code, 200)
        self.assertTemplateUsed(response, 'internships_masters.html')

        masters = response.context['all_masters']
        self.assertEqual(masters.count(), 0)


        url = reverse('internships_masters', kwargs={
            'cohort_id': master.organization.cohort.id,
        })

        response = self.client.get(url)
        self.assertEqual(response.status_code, 200)
        self.assertTemplateUsed(response, 'internships_masters.html')

        masters = response.context['all_masters']
        self.assertEqual(masters.count(), 1)
        self.assertEqual(masters.first(), master)
Ejemplo n.º 8
0
 def test_valid_allocation_both(self):
     request = self.client.post("/masters/save/",
                                data={
                                    "specialty": [SpecialtyFactory()],
                                    "hospital": [OrganizationFactory()],
                                    "role": [Role.MASTER],
                                }).wsgi_request
     self.assertTrue(_validate_allocations(request))
Ejemplo n.º 9
0
 def test_invalid_allocation_no_role(self):
     request = self.client.post("/masters/save/",
                                data={
                                    "specialty": [SpecialtyFactory()],
                                    "hospital": [OrganizationFactory()],
                                    "role": [''],
                                }).wsgi_request
     self.assertFalse(_validate_allocations(request))
Ejemplo n.º 10
0
    def setUpTestData(cls):
        cls.cohort = CohortFactory()

        cls.mandatory_internships, cls.mandatory_specialties = _create_mandatory_internships(
            cls)
        cls.non_mandatory_internships, cls.non_mandatory_specialties = _create_non_mandatory_internships(
            cls)
        cls.students = _create_internship_students(cls)

        cls.hospital_error = OrganizationFactory(name='Hospital Error',
                                                 cohort=cls.cohort,
                                                 reference=999)
        cls.organizations = [
            OrganizationFactory(cohort=cls.cohort)
            for _ in range(0, N_ORGANIZATIONS)
        ]
        cls.periods = [
            PeriodFactory(cohort=cls.cohort) for _ in range(0, N_PERIODS)
        ]

        cls.specialties = cls.mandatory_specialties + cls.non_mandatory_specialties
        cls.internships = cls.mandatory_internships + cls.non_mandatory_internships

        cls.offers = _create_internship_offers(cls)
        cls.places = _declare_offer_places(cls)
        _make_student_choices(cls)

        cls.prior_student = _block_prior_student_choices(cls)

        cls.internship_with_offer_shortage, cls.unlucky_student = _make_shortage_scenario(
            cls)

        _execute_assignment_algorithm(cls)
        cls.affectations = InternshipStudentAffectationStat.objects.all()

        cls.prior_student_affectations = cls.affectations.filter(
            student=cls.prior_student)
        cls.prior_enrollments = InternshipEnrollment.objects.filter(
            student=cls.prior_student)

        cls.user = User.objects.create_user('demo', '*****@*****.**',
                                            'passtest')
        permission = Permission.objects.get(codename='is_internship_manager')
        cls.user.user_permissions.add(permission)
Ejemplo n.º 11
0
def create_organization(name="OSIS",
                        acronym="OSIS",
                        reference="01",
                        cohort=None):
    if cohort is None:
        cohort = CohortFactory()
    return OrganizationFactory(name=name,
                               acronym=acronym,
                               reference=reference,
                               cohort=cohort)
Ejemplo n.º 12
0
 def test_student_choice(self):
     organization = OrganizationFactory(cohort=self.cohort)
     kwargs = {
         'cohort_id': self.cohort.id,
         'organization_id': organization.id
     }
     url = reverse('place_detail_student_choice', kwargs=kwargs)
     response = self.client.get(url)
     self.assertEqual(response.status_code, 200)
     self.assertTemplateUsed(response, 'place_detail.html')
Ejemplo n.º 13
0
    def test_export_xls_organisation_affectation(self):
        organization = OrganizationFactory(cohort=self.cohort)

        url = reverse('organisation_affectation_download',
                      kwargs={
                          'cohort_id': self.cohort.id,
                          'organization_id': organization.id,
                      })

        response = self.client.get(url, follow=True)
        self.assertEqual(response.status_code, 200)
Ejemplo n.º 14
0
    def test_home_with_offer(self):
        organization = OrganizationFactory(cohort=self.cohort)
        speciality = SpecialityFactory(cohort=self.cohort)

        offer = OfferFactory(organization=organization, speciality=speciality)

        url = reverse('internships', kwargs={
            'cohort_id': self.cohort.id,
        })

        response = self.client.get(url)
        self.assertEqual(response.status_code, 200)
        self.assertTemplateUsed(response, 'internships.html')
Ejemplo n.º 15
0
    def test_edit(self):
        organization = OrganizationFactory(cohort=self.cohort)
        organization_address = OrganizationAddressFactory(
            organization=organization)

        kwargs = {
            'cohort_id': self.cohort.id,
            'organization_id': organization.id
        }
        url = reverse('place_edit', kwargs=kwargs)
        response = self.client.get(url)
        self.assertEqual(response.status_code, 200)
        self.assertTemplateUsed(response, 'place_form.html')
Ejemplo n.º 16
0
 def setUpTestData(cls):
     cls.cohort = CohortFactory()
     cls.past_period_no_scores_submitted = PeriodFactory(cohort=cls.cohort, date_end=date.today()-timedelta(days=1))
     cls.past_period_excused = PeriodFactory(cohort=cls.cohort, date_end=date.today()-timedelta(days=1))
     cls.past_period_edited = PeriodFactory(cohort=cls.cohort, date_end=date.today()-timedelta(days=1))
     cls.user = PersonWithPermissionsFactory('is_internship_manager').user
     cls.student = StudentFactory()
     cls.student.organizations = {
         cls.past_period_no_scores_submitted.name: OrganizationFactory().reference,
         cls.past_period_excused.name: OrganizationFactory().reference,
         cls.past_period_edited.name: OrganizationFactory().reference,
     }
     cls.student.periods_scores = {
         cls.past_period_no_scores_submitted.name: NO_SUBMISSION_SCORE,
         cls.past_period_excused.name: {'edited': EXCUSED_PERIOD_SCORE, 'computed': NO_SUBMISSION_SCORE},
         cls.past_period_edited.name: {'edited': EDITED_PERIOD_SCORE, 'computed': COMPUTED_PERIOD_SCORE},
     }
     cls.periods = [
         cls.past_period_no_scores_submitted,
         cls.past_period_excused,
         cls.past_period_edited,
     ]
Ejemplo n.º 17
0
 def test_search_master_by_name_unaccent(self):
     organization = OrganizationFactory(cohort=self.cohort)
     master_with_accent = MasterFactory(person__last_name='Éçàüî')
     MasterAllocationFactory(organization=organization,
                             master=master_with_accent)
     url = reverse('internships_masters',
                   kwargs={
                       'cohort_id': self.cohort.id,
                   })
     query_string = '?name={}'.format("Éçàüî")
     response = self.client.get("{}{}".format(url, query_string))
     self.assertEqual(response.status_code, 200)
     self.assertEqual(response.context['allocations'].object_list[0].master,
                      master_with_accent)
    def test_save_duplicated(self):
        organization = OrganizationFactory()
        specialty = SpecialtyFactory()

        MasterAllocationFactory(organization=organization,
                                specialty=specialty,
                                master=self.master)
        MasterAllocationFactory(organization=organization,
                                specialty=specialty,
                                master=self.master)

        allocations = master_allocation.find_by_master(specialty.cohort,
                                                       self.master)
        self.assertEquals(1, allocations.count())
Ejemplo n.º 19
0
    def test_masters_index_2(self, mock_render, mock_decorators):
        from django.db import connection
        from django.db import reset_queries

        mock_decorators.login_required = lambda x: x
        mock_decorators.permission_required = lambda *args, **kwargs: lambda func: func

        fake = faker.Faker()
        organization = OrganizationFactory(cohort=self.cohort, reference=fake.random_int(min=10, max=100))
        # speciality = SpecialityFactory(cohort=self.cohort)
        master = MasterFactory(organization=organization)

        master2 = MasterFactory()

        request_factory = RequestFactory()
        request = request_factory.get(reverse('internships_masters', kwargs={
            'cohort_id': self.cohort.id
        }))
        request.user = mock.Mock()

        from internship.views.master import internships_masters

        reset_queries()
        self.assertEqual(len(connection.queries), 0)

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

        self.assertEqual(context['cohort'], self.cohort)

        masters_count = context['all_masters'].count()

        # print("Queries", len(connection.queries))
        # from pprint import pprint as pp
        # pp(connection.queries)

        from internship.models.internship_master import InternshipMaster
        self.assertEqual(masters_count,
                         InternshipMaster.objects.filter(organization=organization).count())

        specs = InternshipMaster.objects.filter(organization=organization)\
            .distinct('speciality')\
            .values_list('speciality', flat=True)\
            .order_by('speciality')

        self.assertEqual(len(context['all_spec']), specs.count())

        self.assertEqual(set(context['all_spec']), set(list(specs)))
Ejemplo n.º 20
0
    def test_internship_detail_student_choice(self):
        offer = OfferFactory(organization=OrganizationFactory(
            cohort=self.cohort))

        url = reverse('internship_detail_student_choice',
                      kwargs={
                          'cohort_id': self.cohort.id,
                          'offer_id': offer.id,
                      })

        response = self.client.get(url)

        self.assertEqual(response.status_code, 200)
        self.assertTemplateUsed(response, 'internship_detail.html')

        self.assertEqual(response.context['internship'], offer)
Ejemplo n.º 21
0
    def test_masters_index_with_master(self):
        fake = faker.Faker()

        organization = OrganizationFactory(cohort=self.cohort, reference=fake.random_int(min=10, max=100))
        master = MasterAllocationFactory(organization=organization)

        url = "{}?hospital={}".format(reverse('internships_masters', kwargs={'cohort_id': self.cohort.id}),
                                      organization.id)

        response = self.client.get(url)
        self.assertEqual(response.status_code, 200)
        self.assertTemplateUsed(response, 'masters.html')

        masters = response.context['allocations']
        self.assertEqual(masters.count(), 1)
        self.assertEqual(masters.first(), master)
Ejemplo n.º 22
0
 def test_save_master_form_with_existing_instance(self):
     person = PersonFactory(source=person_source_type.BASE)
     hospital = OrganizationFactory(cohort=self.cohort)
     specialty = SpecialtyFactory(cohort=self.cohort)
     url = reverse('master_save', kwargs={'cohort_id': self.cohort.pk})
     response = self.client.post(url,
                                 data={
                                     'existing-person-id': person.pk,
                                     'hospital': hospital.pk,
                                     'specialty': specialty.pk,
                                     'role': Role.MASTER.name,
                                 })
     self.assertRedirects(
         response, '{}?{}'.format(
             reverse('internships_masters',
                     kwargs={'cohort_id': self.cohort.id}),
             '{}{}'.format('hospital=', hospital.pk)))
     self.assertEqual(InternshipMaster.objects.first().person, person)
    def test_affectation_result_sumup(self):
        specialty = SpecialtyFactory(cohort=self.cohort)
        organization = OrganizationFactory(cohort=self.cohort)
        affectation = StudentAffectationStatFactory(organization=organization, speciality=specialty)

        url = reverse('internship_affectation_sumup', kwargs={
            'cohort_id': self.cohort.id
        })

        response = self.client.get("{}?hospital={}&specialty={}".format(url, organization.id, specialty.id))

        self.assertEqual(response.status_code, 200)
        self.assertTemplateUsed(response, 'internship_affectation_sumup.html')

        self.assertEqual(response.context[0]['active_hospital'], affectation.organization)
        self.assertEqual(response.context[0]['active_specialty'], affectation.speciality)

        self.assertIn(affectation.organization, response.context[0]['hospitals'])
        self.assertIn(affectation.speciality.name, response.context[0]['hospital_specialties'])
Ejemplo n.º 24
0
    def test_delete_master_only_delete_allocations(self):
        master_test = MasterFactory(
            person__source=person_source_type.INTERNSHIP)

        # master and person exists before delete
        self.assertTrue(
            InternshipMaster.objects.filter(pk=master_test.pk).exists())
        self.assertTrue(
            Person.objects.filter(pk=master_test.person.pk).exists())

        fake = faker.Faker()
        organization_test = OrganizationFactory(cohort=self.cohort,
                                                reference=fake.random_int(
                                                    min=10, max=100))
        allocation = MasterAllocationFactory(master=master_test,
                                             organization=organization_test)
        url = reverse('master_delete',
                      kwargs={
                          'cohort_id': self.cohort.id,
                          'master_id': master_test.id
                      })
        allocations = master_allocation.find_by_master(self.cohort,
                                                       master_test)
        self.assertIn(allocation, allocations)
        response = self.client.get(url)
        self.assertRedirects(
            response,
            reverse('internships_masters',
                    kwargs={'cohort_id': self.cohort.id}))
        allocations = master_allocation.find_by_master(self.cohort,
                                                       master_test)
        self.assertNotIn(allocation, allocations)

        # master and person have NOT been deleted
        self.assertTrue(
            InternshipMaster.objects.filter(pk=master_test.pk).exists())
        self.assertTrue(
            Person.objects.filter(pk=master_test.person.pk).exists())
Ejemplo n.º 25
0
 def setUpTestData(cls):
     cls.organization = OrganizationFactory()
     cls.student = StudentFactory()
     cls.specialty = SpecialtyFactory()
     cls.period = PeriodFactory()
Ejemplo n.º 26
0
 def setUp(self):
     self.organization = OrganizationFactory()
     self.student = StudentFactory()
     self.specialty = SpecialtyFactory()
     self.period = PeriodFactory()
Ejemplo n.º 27
0
 def test_home_with_organization_filter(self):
     organization = OrganizationFactory(cohort=self.cohort)
     get_params = '?organization_sort={}'.format(organization.name)
     response = self.client.get(self.url + get_params)
     self.assertEqual(response.status_code, HttpResponse.status_code)
     self.assertTemplateUsed(response, 'internships.html')
Ejemplo n.º 28
0
 def test_find_by_cohort(self):
     cohort = CohortFactory()
     OrganizationFactory(cohort=cohort)
     an_organization = organization.find_by_cohort(cohort)
     self.assertEquals(cohort, an_organization[0].cohort)