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 _make_shortage_scenario(cls):
    '''Make scenario for internship offer with not enough places for student'''
    cls.organizations.append(cls.hospital_error)
    specialty_with_offer_shortage = SpecialtyFactory(mandatory=True,
                                                     cohort=cls.cohort)
    internship_with_offer_shortage = InternshipFactory(
        cohort=cls.cohort,
        name=specialty_with_offer_shortage.name,
        speciality=specialty_with_offer_shortage,
        position=-1)
    for organization in cls.organizations:
        number_places = 999 if organization is cls.hospital_error else 0
        shortage_offer = OfferFactory(cohort=cls.cohort,
                                      organization=organization,
                                      speciality=specialty_with_offer_shortage)
        for period in cls.periods:
            PeriodInternshipPlacesFactory(period=period,
                                          internship_offer=shortage_offer,
                                          number_places=number_places)
    cls.organizations.remove(cls.hospital_error)
    unlucky_student = random.choice(cls.students)
    available_organizations = cls.organizations.copy()
    for choice in range(1, 5):
        organization = random.choice(available_organizations)
        available_organizations.remove(organization)
        create_internship_choice(
            organization=organization,
            student=unlucky_student,
            internship=internship_with_offer_shortage,
            choice=choice,
            speciality=specialty_with_offer_shortage,
        )
    return internship_with_offer_shortage, unlucky_student
Ejemplo n.º 4
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.º 5
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.º 6
0
def _create_mandatory_internships(cls):
    mandatory_specialties = [
        SpecialtyFactory(mandatory=True)
        for _ in range(0, N_MANDATORY_INTERNSHIPS)
    ]
    mandatory_internships = [
        InternshipFactory(cohort=cls.cohort, name=spec.name, speciality=spec)
        for spec in mandatory_specialties
    ]
    return mandatory_internships, mandatory_specialties
Ejemplo n.º 7
0
def _create_non_mandatory_internships(cls):
    non_mandatory_specialties = [
        SpecialtyFactory(mandatory=False)
        for _ in range(0, N_NON_MANDATORY_INTERNSHIPS)
    ]
    non_mandatory_internships = [
        InternshipFactory(cohort=cls.cohort,
                          name="Chosen internship {}".format(i + 1))
        for i in range(0, 4)
    ]
    return non_mandatory_internships, non_mandatory_specialties
 def test_valid_form(self):
     cohort = CohortFactory()
     instance = models.internship.Internship(cohort_id=cohort.id)
     specialty = SpecialtyFactory(cohort=cohort)
     data = {
         'name': "name",
         "speciality": specialty.id,
         "length_in_periods": 1,
         "position": 1
     }
     form = InternshipForm(data, instance=instance)
     self.assertTrue(form.is_valid())
Ejemplo n.º 9
0
    def test_home_with_offer(self):
        organization = OrganizationFactory(cohort=self.cohort)
        speciality = SpecialtyFactory(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.º 10
0
    def test_modification(self):
        speciality = SpecialtyFactory(cohort=self.cohort)

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

        response = self.client.get(url)

        self.assertEqual(response.status_code, 200)
        self.assertTemplateUsed(response, 'speciality_form.html')
        self.assertEqual(response.context['speciality'], speciality)
    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.º 12
0
    def test_save_with_duplicate_acronym(self):
        first_specialty = SpecialtyFactory(name='TEST', acronym='TE1', cohort=self.cohort)
        second_specialty = SpecialtyFactory(name='TEST-1', acronym='TE2', cohort=self.cohort)

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

        specialty_with_same_acronym = {
            'mandatory': False,
            'name': "TEST-2",
            'acronym': first_specialty.acronym,
            'sequence': "1"
        }

        response = self.client.post(url, data=specialty_with_same_acronym)

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

        messages = list(response.wsgi_request._messages)
        self.assertEqual(messages[0].level_tag, "error")
        self.assertIn(first_specialty.acronym, messages[0].message)
Ejemplo n.º 13
0
    def test_new(self):
        speciality = SpecialtyFactory()

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

        response = self.client.post(url, data={
            'mandatory': True,
            'name': speciality.name,
            'acronym': speciality.acronym,
            'sequence': ""
        })
        self.assertRedirects(response, reverse('internships_specialities', kwargs={
            'cohort_id': self.cohort.id,
        }))
Ejemplo n.º 14
0
    def test_save(self):
        speciality = SpecialtyFactory(name='SUPERMAN', cohort=self.cohort)

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

        response = self.client.post(url, data={
            'mandatory': speciality.mandatory,
            'name': 'DEMO',
            'acronym': speciality.acronym,
            'sequence': ""
        })

        self.assertRedirects(response, reverse('internships_specialities', kwargs={
            'cohort_id': self.cohort.id,
        }))
Ejemplo n.º 15
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.º 17
0
 def test_permute_exchanged_affectation_information(self):
     specialty = SpecialtyFactory()
     period = PeriodFactory()
     internship = InternshipFactory(speciality=specialty)
     defavored_affectation = StudentAffectationStatFactory(
         speciality=specialty,
         organization=self.organizations[-1],
         period=period,
         internship=internship,
         cost=10,
         choice="I")
     favored_affectation = StudentAffectationStatFactory(
         speciality=specialty,
         organization=self.organizations[1],
         period=period,
         internship=internship,
         cost=0)
     self.affectations = InternshipStudentAffectationStat.objects.all()
     for choice, organization in enumerate(self.organizations[:4], start=1):
         create_internship_choice(
             organization=organization,
             student=defavored_affectation.student,
             internship=internship,
             choice=choice,
             speciality=specialty,
         )
     _permute_affectations(self, [defavored_affectation],
                           [favored_affectation],
                           InternshipChoice.objects.all())
     InternshipStudentAffectationStat.objects.bulk_update(
         self.affectations, fields=['organization'])
     self.assertEqual(
         self.affectations.get(
             student=defavored_affectation.student).organization,
         self.organizations[1])
     self.assertEqual(
         self.affectations.get(
             student=favored_affectation.student).organization,
         self.organizations[-1])
Ejemplo n.º 18
0
    def test_delete(self):
        specialities = InternshipSpeciality.objects.filter(cohort=self.cohort).count()
        self.assertEqual(specialities, 0)

        speciality = SpecialtyFactory(cohort=self.cohort)

        specialities = InternshipSpeciality.objects.filter(cohort=self.cohort).count()
        self.assertEqual(specialities, 1)

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

        response = self.client.get(url)

        specialities = InternshipSpeciality.objects.filter(cohort=self.cohort).count()
        self.assertEqual(specialities, 0)

        self.assertRedirects(response, reverse('internships_specialities', kwargs={
            'cohort_id': self.cohort.id,
        }))
def create_speciality(name="chirurgie", cohort=None):
    if cohort is None:
        cohort = CohortFactory()
    return SpecialtyFactory(name=name, cohort=cohort)
Ejemplo n.º 20
0
 def setUp(self):
     self.organization = OrganizationFactory()
     self.student = StudentFactory()
     self.specialty = SpecialtyFactory()
     self.period = PeriodFactory()
Ejemplo n.º 21
0
 def setUpTestData(cls):
     cls.organization = OrganizationFactory()
     cls.student = StudentFactory()
     cls.specialty = SpecialtyFactory()
     cls.period = PeriodFactory()
Ejemplo n.º 22
0
 def setUpTestData(cls):
     cls.cohort = CohortFactory()
     cls.period = PeriodFactory(name='P1',
                                date_end=date.today() -
                                relativedelta(months=2),
                                cohort=cls.cohort)
     cls.other_period = PeriodFactory(
         name='P2',
         date_end=date.today() - relativedelta(months=1),
         cohort=cls.cohort,
     )
     cls.xlsfile = SimpleUploadedFile(
         name='upload.xls',
         content=str.encode('test'),
         content_type="application/vnd.ms-excel",
     )
     cls.xlsxfile = SimpleUploadedFile(
         name='upload.xlsx',
         content=str.encode('test'),
         content_type=
         "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
     )
     cls.students = [
         InternshipStudentInformationFactory(cohort=cls.cohort)
         for _ in range(11)
     ]
     cls.mandatory_internship = InternshipFactory(
         cohort=cls.cohort, speciality=SpecialtyFactory(cohort=cls.cohort))
     cls.long_internship = InternshipFactory(cohort=cls.cohort,
                                             speciality=SpecialtyFactory(
                                                 cohort=cls.cohort,
                                                 sequence=1))
     cls.chosen_internship = InternshipFactory(cohort=cls.cohort,
                                               speciality=None)
     internships = [
         cls.mandatory_internship, cls.long_internship,
         cls.chosen_internship
     ]
     periods = [cls.period
                ] + [PeriodFactory(cohort=cls.cohort) for _ in range(2)]
     for student_info in cls.students:
         student = StudentFactory(person=student_info.person)
         for index, internship in enumerate(internships):
             StudentAffectationStatFactory(
                 student=student,
                 internship=internship,
                 speciality=internship.speciality
                 if internship.speciality else SpecialtyFactory(),
                 period=periods[index])
         ScoreFactory(student_affectation__student=student,
                      student_affectation__period=cls.period,
                      APD_1='A',
                      validated=True)
     for apd in range(1, APD_NUMBER):
         ScoreMappingFactory(period=cls.period,
                             cohort=cls.cohort,
                             score_A=20,
                             score_B=15,
                             score_C=10,
                             score_D=0,
                             apd=apd)
     cls.unused_period = PeriodFactory(name="P99",
                                       cohort=cls.cohort,
                                       date_end=date.today() +
                                       relativedelta(months=+2))
     cls.user = User.objects.create_user('demo', '*****@*****.**',
                                         'passtest')
     permission = Permission.objects.get(codename='is_internship_manager')
     cls.user.user_permissions.add(permission)
     cls.all_apds_validated = {
         'APD_{}'.format(i): 'D'
         for i in range(1, APD_NUMBER + 1)
     }
Ejemplo n.º 23
0
 def test_acronym_exists(self):
     cohort = CohortFactory()
     SpecialtyFactory(cohort=cohort, name="Test1", acronym="TE")
     self.assertTrue(mdl_internship_speciality.acronym_exists(cohort, "TE"))
     self.assertTrue(mdl_internship_speciality.acronym_exists(cohort, "Te"))
     self.assertTrue(mdl_internship_speciality.acronym_exists(cohort, "te"))