Пример #1
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,
        })
Пример #2
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
Пример #3
0
def create_specific_internship_offer(organization, speciality, title="offer_test", cohort=None):
    return OfferFactory(
        speciality=speciality,
        organization=organization,
        title=title,
        cohort=cohort,
        maximum_enrollments=20
    )
Пример #4
0
def _create_internship_offers(cls):
    offers = []
    cls.organizations.append(cls.hospital_error)
    for specialty in cls.specialties:
        for organization in cls.organizations:
            offers.append(
                OfferFactory(cohort=cls.cohort,
                             organization=organization,
                             speciality=specialty))
    cls.organizations.remove(cls.hospital_error)
    return offers
Пример #5
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')
Пример #6
0
    def testAccessUrl(self):
        cohort = CohortFactory()

        internship_offer = OfferFactory(cohort=cohort)

        kwargs = {
            'internship_id': internship_offer.id,
            'cohort_id': cohort.id,
        }
        url = reverse("edit_period_places", kwargs=kwargs)
        response = self.client.get(url)

        self.assertEqual(200, response.status_code)
Пример #7
0
def create_internship_offer(cohort=None):
    if cohort is None:
        cohort = CohortFactory()
    organization = test_organization.create_organization(cohort=cohort)
    speciality = test_internship_speciality.create_speciality(cohort=cohort)

    return OfferFactory(
        speciality=speciality,
        organization=organization,
        title="offer_test",
        maximum_enrollments=20,
        cohort=cohort,
    )
Пример #8
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)
Пример #9
0
    def test_save_period_places(self):
        cohort = CohortFactory()
        internship_offer = OfferFactory(cohort=cohort)

        kwargs = {
            'internship_id': internship_offer.id,
            'cohort_id': cohort.id,
        }

        url = reverse("save_period_places", kwargs=kwargs)

        response = self.client.post(url, data={
            "P1": 2,
            "P5": 8,
        })

        number_of_period_places = mdl_period_places.PeriodInternshipPlaces.objects.count(
        )
        self.assertEqual(number_of_period_places, 2)
Пример #10
0
    def setUpTestData(cls):
        cls.user = User.objects.create_user("username",
                                            "*****@*****.**",
                                            "passtest",
                                            first_name='first_name',
                                            last_name='last_name')
        cls.user.save()
        add_permission(cls.user, "is_internship_manager")
        cls.person = test_person.create_person_with_user(cls.user)

        cls.cohort = CohortFactory()

        cls.speciality = test_internship_speciality.create_speciality(
            name="urgence", cohort=cls.cohort)
        cls.organization = test_organization.create_organization(
            reference="01", cohort=cls.cohort)
        cls.offer = test_internship_offer.create_specific_internship_offer(
            cls.organization, cls.speciality, cohort=cls.cohort)

        MAX_PERIOD = 12
        for period in range(1, MAX_PERIOD + 1):
            test_period.create_period("P%d" % period, cohort=cls.cohort)

        cls.internship_offer = OfferFactory(cohort=cls.cohort)