Ejemplo n.º 1
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.º 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,
        })
    def setUpTestData(cls):
        cls.organization = test_organization.create_organization()
        cls.student = test_student.create_student(first_name="first",
                                                  last_name="last",
                                                  registration_id="64641200")
        cls.other_student = test_student.create_student(
            first_name="first", last_name="last", registration_id="606012")
        cls.cohort = CohortFactory()
        cls.speciality = test_internship_speciality.create_speciality(
            cohort=cls.cohort)
        cls.internship = InternshipFactory(cohort=cls.cohort)
        cls.other_internship = InternshipFactory(cohort=cls.cohort)
        cls.student_information = test_internship_student_information.create_student_information(
            person=cls.student.person, cohort=cls.cohort)
        cls.other_student_information = test_internship_student_information.create_student_information(
            person=cls.other_student.person, cohort=cls.cohort)

        cls.choice_1 = create_internship_choice(
            cls.organization,
            cls.student,
            cls.speciality,
            internship=cls.other_internship)
        cls.choice_2 = create_internship_choice(cls.organization,
                                                cls.student,
                                                cls.speciality,
                                                internship=cls.internship)
        cls.choice_3 = create_internship_choice(
            cls.organization,
            cls.other_student,
            cls.speciality,
            internship=cls.other_internship)
    def setUp(self):
        self.organization = test_organization.create_organization()
        self.student = test_student.create_student(first_name="first", last_name="last", registration_id="64641200")
        self.other_student = test_student.create_student(first_name="first", last_name="last", registration_id="606012")
        self.cohort = CohortFactory()
        self.speciality = test_internship_speciality.create_speciality(cohort=self.cohort)
        self.internship = InternshipFactory(cohort=self.cohort)
        self.other_internship = InternshipFactory(cohort=self.cohort)
        self.student_information = test_internship_student_information.create_student_information(person=self.student.person, cohort=self.cohort)
        self.other_student_information = test_internship_student_information.create_student_information(person=self.other_student.person, cohort=self.cohort)

        self.choice_1 = create_internship_choice(self.organization, self.student, self.speciality, internship=self.other_internship)
        self.choice_2 = create_internship_choice(self.organization, self.student, self.speciality, internship=self.internship)
        self.choice_3 = create_internship_choice(self.organization, self.other_student, self.speciality, internship=self.other_internship)
Ejemplo n.º 5
0
def _make_student_choices(cls):
    for student in cls.students:
        for internship in cls.internships:
            available_organizations = cls.organizations.copy()
            specialty = internship.speciality or random.choice(
                cls.non_mandatory_specialties)
            for choice in range(1, 5):
                organization = random.choice(available_organizations)
                available_organizations.remove(organization)
                create_internship_choice(
                    organization=organization,
                    student=student,
                    internship=internship,
                    choice=choice,
                    speciality=specialty,
                )
Ejemplo n.º 6
0
    def test_replace_previous_choices(self):
        internship = InternshipFactory(cohort=self.cohort)
        previous_choice = create_internship_choice(
            test_organization.create_organization(), self.student,
            self.speciality_1, internship)
        kwargs = {
            'cohort_id': self.cohort.id,
            'internship_id': internship.id,
            'speciality_id': self.speciality_2.id,
            'student_id': self.student.id
        }
        selection_url = reverse("specific_internship_student_modification",
                                kwargs=kwargs)

        data = self.generate_form([
            (self.offer_5, 1, True),
            (self.offer_6, 0, False),
        ])

        response = self.client.post(selection_url, data=data)
        self.assertEqual(response.status_code, 200)

        qs = mdl_internship_choice.search_by_student_or_choice(
            student=self.student)

        self.assertEqual(qs.count(), 1)
        self.assertNotEqual(previous_choice, qs.first())
Ejemplo n.º 7
0
    def test_build_with_choices(self):
        cohort = CohortFactory()
        internship = InternshipFactory(cohort=cohort)
        self.choice = create_internship_choice(self.organization, self.student, self.specialty, internship=internship)
        student_choices = [self.choice,]
        affectation = internship_student_affectation_stat.build(self.student, self.organization, self.specialty,
                                                                self.period, student_choices)

        self.assertEquals(affectation.cost, 0)
        self.assertEquals(affectation.choice, self.choice.choice)
Ejemplo n.º 8
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.º 9
0
    def setUpTestData(cls):
        cls.cohort = CohortFactory()
        organization = test_organization.create_organization(cohort=cls.cohort)
        cls.student_1 = test_student.create_student(first_name="first",
                                                    last_name="last",
                                                    registration_id="64641200")
        cls.student_2 = test_student.create_student(first_name="first",
                                                    last_name="last",
                                                    registration_id="606012")
        speciality = test_internship_speciality.create_speciality(
            cohort=cls.cohort)

        cls.internship = InternshipFactory(cohort=cls.cohort)
        cls.internship_2 = InternshipFactory(cohort=cls.cohort)
        cls.internship_3 = InternshipFactory(cohort=cls.cohort)
        cls.internship_4 = InternshipFactory(cohort=cls.cohort)

        cls.choice_1 = create_internship_choice(organization,
                                                cls.student_1,
                                                speciality,
                                                internship=cls.internship)
        cls.choice_2 = create_internship_choice(organization,
                                                cls.student_1,
                                                speciality,
                                                internship=cls.internship_2)
        cls.choice_3 = create_internship_choice(organization,
                                                cls.student_1,
                                                speciality,
                                                internship=cls.internship_3)
        cls.choice_4 = create_internship_choice(organization,
                                                cls.student_1,
                                                speciality,
                                                internship=cls.internship_4)
        cls.choice_5 = create_internship_choice(organization,
                                                cls.student_2,
                                                speciality,
                                                internship=cls.internship)
        cls.choice_6 = create_internship_choice(organization,
                                                cls.student_2,
                                                speciality,
                                                internship=cls.internship_2)
        cls.choice_7 = create_internship_choice(organization,
                                                cls.student_2,
                                                speciality,
                                                internship=cls.internship_3)
        cls.url = reverse(internships_student_resume,
                          kwargs={
                              'cohort_id': cls.cohort.id,
                          })
Ejemplo n.º 10
0
    def setUp(self):
        self.cohort = CohortFactory()
        organization = test_organization.create_organization(
            cohort=self.cohort)
        self.student_1 = test_student.create_student(
            first_name="first", last_name="last", registration_id="64641200")
        self.student_2 = test_student.create_student(first_name="first",
                                                     last_name="last",
                                                     registration_id="606012")
        speciality = test_internship_speciality.create_speciality(
            cohort=self.cohort)

        self.internship = InternshipFactory(cohort=self.cohort)
        self.internship_2 = InternshipFactory(cohort=self.cohort)
        self.internship_3 = InternshipFactory(cohort=self.cohort)
        self.internship_4 = InternshipFactory(cohort=self.cohort)

        self.choice_1 = create_internship_choice(organization,
                                                 self.student_1,
                                                 speciality,
                                                 internship=self.internship)
        self.choice_2 = create_internship_choice(organization,
                                                 self.student_1,
                                                 speciality,
                                                 internship=self.internship_2)
        self.choice_3 = create_internship_choice(organization,
                                                 self.student_1,
                                                 speciality,
                                                 internship=self.internship_3)
        self.choice_4 = create_internship_choice(organization,
                                                 self.student_1,
                                                 speciality,
                                                 internship=self.internship_4)
        self.choice_5 = create_internship_choice(organization,
                                                 self.student_2,
                                                 speciality,
                                                 internship=self.internship)
        self.choice_6 = create_internship_choice(organization,
                                                 self.student_2,
                                                 speciality,
                                                 internship=self.internship_2)
        self.choice_7 = create_internship_choice(organization,
                                                 self.student_2,
                                                 speciality,
                                                 internship=self.internship_3)
 def test_duplicates_are_forbidden(self):
     with self.assertRaises(IntegrityError):
         create_internship_choice(self.organization,
                                  self.student,
                                  self.speciality,
                                  internship=self.internship)