예제 #1
0
 def test_two_personal_internships_at_most(self):
     organization = test_organization.create_organization(name="Stage personnel")
     speciality = test_internship_speciality.create_speciality(name="Stage personnel",
                                                               acronym="SP")
     offer = test_internship_offer.create_specific_internship_offer(organization, speciality,
                                                                    title="Stage personnel")
     choice_1 = test_internship_choice.create_internship_choice(
         organization, self.student, speciality, self.internship_1
     )
     choice_2 = test_internship_choice.create_internship_choice(
         organization, self.student, speciality, self.internship_2
     )
     selection_url = reverse("select_internship", kwargs={'cohort_id': self.cohort.id})
     self.client.post(selection_url, data={
         '{}-TOTAL_FORMS'.format(self.speciality_2.name): '2',
         '{}-INITIAL_FORMS'.format(self.speciality_2.name): '0',
         '{}-MIN_NUM_FORMS'.format(self.speciality_2.name): '2',
         '{}-MAX_NUM_FORMS'.format(self.speciality_2.name): '2',
         'form-0-offer': str(offer.id),
         'form-0-preference': '1',
         'current_internship'.format(self.speciality_2.name): self.internship_2.id,
     })
     choices = list(mdl_internship_choice.search(student=self.student))
     self.assertEqual(len(choices), 2)
     self.assertIn(choice_1, choices)
     self.assertIn(choice_2, choices)
예제 #2
0
 def test_with_multiple_internships_choices(self):
     selection_url = reverse("select_internship", kwargs={'cohort_id': self.cohort.id})
     response = self.client.post(selection_url, data={
         '{}-TOTAL_FORMS'.format(self.speciality_1.name): '4',
         '{}-INITIAL_FORMS'.format(self.speciality_1.name): '0',
         '{}-MIN_NUM_FORMS'.format(self.speciality_1.name): '4',
         '{}-MAX_NUM_FORMS'.format(self.speciality_1.name): '4',
         '{}-0-offer'.format(self.speciality_1.name): str(self.offer_1.id),
         '{}-0-preference'.format(self.speciality_1.name): '1',
         '{}-1-offer'.format(self.speciality_1.name): str(self.offer_2.id),
         '{}-1-preference'.format(self.speciality_1.name): '2',
         '{}-2-offer'.format(self.speciality_1.name): str(self.offer_3.id),
         '{}-2-preference'.format(self.speciality_1.name): '3',
         '{}-3-offer'.format(self.speciality_1.name): str(self.offer_4.id),
         '{}-3-preference'.format(self.speciality_1.name): '4',
         '{}-TOTAL_FORMS'.format(self.speciality_2.name): '2',
         '{}-INITIAL_FORMS'.format(self.speciality_2.name): '0',
         '{}-MIN_NUM_FORMS'.format(self.speciality_2.name): '2',
         '{}-MAX_NUM_FORMS'.format(self.speciality_2.name): '2',
         '{}-0-offer'.format(self.speciality_2.name): str(self.offer_5.id),
         '{}-0-preference'.format(self.speciality_2.name): '1',
         '{}-1-offer'.format(self.speciality_2.name): str(self.offer_6.id),
         '{}-1-preference'.format(self.speciality_2.name): '2',
         'current_internship'.format(self.speciality_2.name): self.internship_2.id,
     })
     choices = list(mdl_internship_choice.search(student=self.student))
     self.assertEqual(response.status_code, 200)
     self.assertEqual(len(choices), 6)
예제 #3
0
def view_student_resume(request, cohort_id):
    cohort = mdl_internship_cohort.Cohort.objects.get(pk=cohort_id)
    student = mdl_student.find_by_user(request.user)
    internships = mdl_internship.Internship.objects.filter(
        cohort=cohort).order_by('speciality', 'name')

    student_information = mdl_student_information.find_by_user_in_cohort(
        request.user, cohort=cohort)
    periods = mdl_period.Period.objects.filter(cohort=cohort)
    period_ids = periods.values_list("pk", flat=True)
    student_affectations = mdl_student_affectation.InternshipStudentAffectationStat.objects.filter(
        student=student, period_id__in=period_ids).order_by("period__name")
    specialities = mdl_internship_speciality.find_by_cohort(cohort)
    student_choices = mdl_internship_choice.search(student=student,
                                                   specialities=specialities)
    cohort = mdl_internship_cohort.Cohort.objects.get(pk=cohort_id)
    publication_allowed = cohort.publication_start_date <= datetime.date.today(
    )
    offers = {}
    for affectation in student_affectations:
        score = InternshipAPIService.get_affectation(
            person=request.user.person,
            affectation_uuid=str(affectation.uuid)).score
        if score and score.validated:
            score.comments = _replace_comments_keys_with_translations(
                score.comments)
            setattr(affectation, 'score', score)
        offer = mdl_internship_offer.find_offer(
            cohort=cohort,
            speciality=affectation.speciality,
            organization=affectation.organization).first()
        offer.master = _get_internship_masters_repr(request.user.person,
                                                    affectation)
        try:
            offers[affectation.organization].update(
                {affectation.speciality: offer})
        except KeyError:
            offers.update(
                {affectation.organization: {
                    affectation.speciality: offer
                }})
    return layout.render(
        request, "student_resume.html", {
            "student": student,
            "student_information": student_information,
            "student_affectations": student_affectations,
            "student_choices": student_choices,
            "internships": internships,
            "publication_allowed": publication_allowed,
            "cohort": cohort,
            "offers": offers,
            "current_date": date.today(),
            "apds": APDS,
        })
예제 #4
0
 def test_replace_previous_choices(self):
     previous_choice = test_internship_choice.create_internship_choice(
         test_organization.create_organization(),
         self.student, self.speciality_2, self.internship_1
     )
     choices = list(mdl_internship_choice.search(student=self.student, speciality=self.speciality_2))
     self.assertEqual(len(choices), 1)
     selection_url = reverse("select_internship", kwargs={'cohort_id': self.cohort.id})
     self.client.post(selection_url, data={
         '{}-TOTAL_FORMS'.format(self.speciality_2.name): '2',
         '{}-INITIAL_FORMS'.format(self.speciality_2.name): '0',
         '{}-MIN_NUM_FORMS'.format(self.speciality_2.name): '2',
         '{}-MAX_NUM_FORMS'.format(self.speciality_2.name): '2',
         '{}-0-offer'.format(self.speciality_2.name): str(self.offer_5.id),
         '{}-0-preference'.format(self.speciality_2.name): '1',
         '{}-1-offer'.format(self.speciality_2.name): str(self.offer_6.id),
         '{}-1-preference'.format(self.speciality_2.name): '0',
         'current_internship'.format(self.speciality_2.name): self.internship_2.id,
     })
     choices = list(mdl_internship_choice.search(student=self.student, speciality=self.speciality_2))
     self.assertEqual(len(choices), 1)
     self.assertNotEqual(previous_choice, choices[0])
예제 #5
0
 def test_with_one_choice(self):
     selection_url = reverse("select_internship", kwargs={'cohort_id': self.cohort.id})
     response = self.client.post(selection_url, data={
         '{}-TOTAL_FORMS'.format(self.speciality_2.name): '2',
         '{}-INITIAL_FORMS'.format(self.speciality_2.name): '0',
         '{}-MIN_NUM_FORMS'.format(self.speciality_2.name): '2',
         '{}-MAX_NUM_FORMS'.format(self.speciality_2.name): '2',
         '{}-0-offer'.format(self.speciality_2.name): str(self.offer_5.id),
         '{}-0-preference'.format(self.speciality_2.name): '1',
         '{}-1-offer'.format(self.speciality_2.name): str(self.offer_6.id),
         '{}-1-preference'.format(self.speciality_2.name): '0',
         'current_internship'.format(self.speciality_2.name): self.internship_2.id,
     })
     choices = list(mdl_internship_choice.search(student=self.student))
     self.assertEqual(response.status_code, 200)
     self.assertEqual(len(choices), 1)
     self.assertEqual(choices[0].organization, self.organization_1)
     self.assertEqual(choices[0].speciality, self.speciality_2)
     self.assertEqual(choices[0].internship_id, self.internship_2.id)
     self.assertEqual(choices[0].choice, 1)
예제 #6
0
 def test_with_only_speciality(self):
     choices = list(
         mdl_internship_choice.search(speciality=self.speciality))
     self.assertEqual(len(choices), 2)
     self.assertIn(self.choice_2, choices)
     self.assertIn(self.choice_4, choices)
예제 #7
0
 def test_with_only_internship_choice(self):
     choices = list(
         mdl_internship_choice.search(internship=self.other_internship))
     self.assertEqual(len(choices), 2)
     self.assertIn(self.choice_1, choices)
     self.assertIn(self.choice_3, choices)
예제 #8
0
 def test_with_only_student(self):
     choices = list(mdl_internship_choice.search(student=self.student))
     self.assertEqual(len(choices), 2)
     self.assertIn(self.choice_1, choices)
     self.assertIn(self.choice_2, choices)
예제 #9
0
 def test_with_student_and_internship_choice(self):
     choices = list(
         mdl_internship_choice.search(student=self.student,
                                      internship=self.internship))
     self.assertListEqual([self.choice_2], choices)