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)
def test_edit_get_cohort_found(self): cohort = CohortFactory() response = self.client.get( reverse('cohort_edit', kwargs={ 'cohort_id': cohort.id, })) self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, 'cohort/cohort_form.html')
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, internship, student_choices) self.assertEqual(affectation.cost, 0) self.assertEqual(affectation.choice, self.choice.choice)
def setUp(self) -> None: self.cohort = CohortFactory() self.organization_1 = create_organization(cohort=self.cohort, city="city1") self.organization_2 = create_organization(reference='02', cohort=self.cohort, city="city2") self.organization_3 = create_organization(name="OSAS", reference='03', cohort=self.cohort, city="city1")
def create_student_information(person, contest="GENERALIST", cohort=None): if cohort is None: cohort = CohortFactory() return InternshipStudentInformation.objects.create(person=person, location="location", postal_code="00", city="city", country="country", contest=contest, cohort=cohort)
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())
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 = test_internship_choice.create_internship_choice( organization, self.student_1, speciality, internship=self.internship) self.choice_2 = test_internship_choice.create_internship_choice( organization, self.student_1, speciality, internship=self.internship_2) self.choice_3 = test_internship_choice.create_internship_choice( organization, self.student_1, speciality, internship=self.internship_3) self.choice_4 = test_internship_choice.create_internship_choice( organization, self.student_1, speciality, internship=self.internship_4) self.choice_5 = test_internship_choice.create_internship_choice( organization, self.student_2, speciality, internship=self.internship) self.choice_6 = test_internship_choice.create_internship_choice( organization, self.student_2, speciality, internship=self.internship_2) self.choice_7 = test_internship_choice.create_internship_choice( organization, self.student_2, speciality, internship=self.internship_3)
def test_cohort_simple_get(self): cohort = CohortFactory() self.client.force_login(self.user) url = reverse('admin:cohort-import-students', kwargs={'cohort_id': cohort.id}) response = self.client.get(url) self.assertTemplateUsed( response, 'admin/internship/cohort/import_students.html')
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, )
def create_internship_offer(cohort=None): if cohort == None: cohort = CohortFactory() organization = test_organization.create_organization() speciality = test_internship_speciality.create_speciality() offer = internship_offer.InternshipOffer(speciality=speciality, organization=organization, title="offer_test", cohort=cohort, maximum_enrollments=20, master="Dr. Test") offer.save() return offer
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)
def test_count_delegates_without_user_account(self): cohort = CohortFactory() MasterAllocationFactory( organization__cohort=cohort, role=Role.DELEGATE.name, master__user_account_status=UserAccountStatus.INACTIVE.value) response = self.client.post( reverse('internships_home', kwargs={'cohort_id': cohort.id})) self.assertEqual(response.status_code, 200) self.assertEqual(response.context['users_to_activate'], 1)
def test_copy_organization_from_cohort(self): cohort = CohortFactory() organization = OrganizationFactory(cohort=cohort) address = OrganizationAddressFactory(organization=organization) speciality = SpecialityFactory(cohort=cohort) copy_cohort_name = 'Copy of {} {}'.format(cohort.name, timezone.now()) form_data = { 'name': copy_cohort_name, 'publication_start_date': cohort.publication_start_date.strftime('%Y-%m-%d'), 'subscription_start_date': cohort.subscription_start_date.strftime('%Y-%m-%d'), 'subscription_end_date': cohort.subscription_end_date.strftime('%Y-%m-%d'), 'free_internships_number': cohort.free_internships_number, 'description': cohort.description, 'copy_organizations_from_cohort': cohort.id, 'copy_specialities_from_cohort': 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)
def test_valid_form(self): cohort = CohortFactory() data = { "email": "*****@*****.**", "phone_mobile": "046486313", "location": "location", "postal_code": "postal", "city": "city", "country": "country", "contest": "GENERALIST", 'cohort': cohort.id, } form = form_student_information.StudentInformationForm(data) self.assertTrue(form.is_valid())
def setUp(self): self.cohort = CohortFactory() student_1 = test_student.create_student("first", "last", "01") student_2 = test_student.create_student("first", "last", "02") student_3 = test_student.create_student("first", "last", "03") student_4 = test_student.create_student("first", "last", "04") contest_generalist = "GENERALIST" contest_specialist = "SPECIALIST" create_student_information(student_1.person, contest_generalist, cohort=self.cohort) create_student_information(student_2.person, contest_generalist, cohort=self.cohort) create_student_information(student_3.person, contest_generalist, cohort=self.cohort) create_student_information(student_4.person, contest_specialist, cohort=self.cohort)
def test_cohort_upload_csv_file(self): cohort = CohortFactory() self.client.force_login(self.user) url = reverse('admin:cohort-import-students', kwargs={ 'cohort_id': cohort.id, }) with create_csv_stream('demo.csv') as str_io: response = self.client.post(url, {'file_upload': str_io}) cohort_url = reverse('admin:internship_cohort_change', args=[cohort.id]) self.assertRedirects(response, cohort_url)
def create_organization(name="OSIS", acronym="OSIS", reference="01", cohort=None, city="test"): if cohort is None: cohort = CohortFactory() organization = mdl_organization.Organization(name=name, acronym=acronym, reference=reference, cohort=cohort, city=city) organization.save() return organization
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)
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, })
def setUp(self) -> None: self.cohort = CohortFactory() self.period = PeriodFactory(cohort=self.cohort, date_end=date.today()) self.active_master_allocation = MasterAllocationFactory( specialty__cohort=self.cohort, organization__cohort=self.cohort, master__user_account_status=UserAccountStatus.ACTIVE.name) self.student_affectation = StudentAffectationStatFactory( speciality=self.active_master_allocation.specialty, organization=self.active_master_allocation.organization, period=self.period) self.inactive_master_allocation = MasterAllocationFactory( specialty__cohort=self.cohort, organization__cohort=self.cohort, master__user_account_status=UserAccountStatus.INACTIVE.name)
def create_student_information(user, cohort=None, person=None): if person is None: person = test_person.create_person_with_user(user) if cohort is None: cohort = CohortFactory() student_information = mdl_student_information.InternshipStudentInformation( person=person, location="location", cohort=cohort, postal_code="00", city="city", country="country") student_information.save() return student_information
def test_new_port(self): cohort = CohortFactory.build() form_data = { 'name': cohort.name, 'publication_start_date': cohort.publication_start_date.strftime('%Y-%m-%d'), 'subscription_start_date': cohort.subscription_start_date.strftime('%Y-%m-%d'), 'subscription_end_date': cohort.subscription_end_date.strftime('%Y-%m-%d'), 'description': cohort.description, } form = CohortForm(data=form_data) self.assertTrue(form.is_valid()) response = self.client.post(reverse('cohort_new'), data=form_data) self.assertEqual(response.status_code, 302) self.assertRedirects(response, reverse('internship'))
def setUpTestData(cls): cls.user = UserFactory() cls.student = StudentFactory(person__user=cls.user) add_permission(cls.student.person.user, "can_access_internship") cls.cohort = CohortFactory() cls.student_information = test_internship_student_information.create_student_information( cls.user, cls.cohort, cls.student.person ) cls.selective_internship = InternshipFactory( name='Selective internship', cohort=cls.cohort, speciality=None ) cls.specialty = test_internship_speciality.create_speciality(name="specialty", cohort=cls.cohort)
def setUpTestData(cls): cls.cohort = CohortFactory() cls.students = [ InternshipStudentInformationFactory(cohort=cls.cohort) for _ in range(0, 9) ] cls.student_with_accent = InternshipStudentInformationFactory( cohort=cls.cohort, person=PersonFactory(last_name='Éçàüî')) cls.students.append(cls.student_with_accent) cls.url = reverse(internships_student_resume, kwargs={ 'cohort_id': cls.cohort.id, }) cls.user = User.objects.create_user('demo', '*****@*****.**', 'passtest') permission = Permission.objects.get(codename='is_internship_manager') cls.user.user_permissions.add(permission)
def setUp(self): self.user = User.objects.create_user("username", "*****@*****.**", "passtest", first_name='first_name', last_name='last_name') self.user.save() add_permission(self.user, "is_internship_manager") self.person = test_person.create_person_with_user(self.user) self.cohort = CohortFactory() self.client.force_login(self.user) self.speciality = test_internship_speciality.create_speciality(name="urgence", cohort=self.cohort) self.organization = test_organization.create_organization(reference="01", cohort=self.cohort) self.offer = test_internship_offer.create_specific_internship_offer(self.organization, self.speciality, cohort=self.cohort) MAX_PERIOD = 12 for period in range(1, MAX_PERIOD + 1): test_period.create_period("P%d" % period, cohort=self.cohort)
def setUp(self): self.user = User.objects.create_user("username", "*****@*****.**", "passtest", first_name='first_name', last_name='last_name') self.user.save() add_permission(self.user, "is_internship_manager") self.person = test_person.create_person_with_user(self.user) self.client.force_login(self.user) self.cohort = CohortFactory() self.student = test_student.create_student("first", "last", "64641200") self.speciality_1 = test_internship_speciality.create_speciality( name="urgence", cohort=self.cohort) self.speciality_2 = test_internship_speciality.create_speciality( name="chirurgie", cohort=self.cohort) self.organization_1 = test_organization.create_organization( reference="01", cohort=self.cohort) self.organization_2 = test_organization.create_organization( reference="02", cohort=self.cohort) self.organization_3 = test_organization.create_organization( reference="03", cohort=self.cohort) self.organization_4 = test_organization.create_organization( reference="04", cohort=self.cohort) self.organization_5 = test_organization.create_organization( reference="05", cohort=self.cohort) self.offer_1 = test_internship_offer.create_specific_internship_offer( self.organization_1, self.speciality_1, cohort=self.cohort) self.offer_2 = test_internship_offer.create_specific_internship_offer( self.organization_2, self.speciality_1, cohort=self.cohort) self.offer_3 = test_internship_offer.create_specific_internship_offer( self.organization_3, self.speciality_1, cohort=self.cohort) self.offer_4 = test_internship_offer.create_specific_internship_offer( self.organization_4, self.speciality_1, cohort=self.cohort) self.offer_5 = test_internship_offer.create_specific_internship_offer( self.organization_1, self.speciality_2, cohort=self.cohort) self.offer_6 = test_internship_offer.create_specific_internship_offer( self.organization_5, self.speciality_2, cohort=self.cohort)
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)
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.student = test_student.create_student("first", "last", "64641200") cls.speciality_1 = test_internship_speciality.create_speciality( name="urgence", cohort=cls.cohort) cls.speciality_2 = test_internship_speciality.create_speciality( name="chirurgie", cohort=cls.cohort) cls.organization_1 = test_organization.create_organization( reference="01", cohort=cls.cohort) cls.organization_2 = test_organization.create_organization( reference="02", cohort=cls.cohort) cls.organization_3 = test_organization.create_organization( reference="03", cohort=cls.cohort) cls.organization_4 = test_organization.create_organization( reference="04", cohort=cls.cohort) cls.organization_5 = test_organization.create_organization( reference="05", cohort=cls.cohort) cls.offer_1 = test_internship_offer.create_specific_internship_offer( cls.organization_1, cls.speciality_1, cohort=cls.cohort) cls.offer_2 = test_internship_offer.create_specific_internship_offer( cls.organization_2, cls.speciality_1, cohort=cls.cohort) cls.offer_3 = test_internship_offer.create_specific_internship_offer( cls.organization_3, cls.speciality_1, cohort=cls.cohort) cls.offer_4 = test_internship_offer.create_specific_internship_offer( cls.organization_4, cls.speciality_1, cohort=cls.cohort) cls.offer_5 = test_internship_offer.create_specific_internship_offer( cls.organization_1, cls.speciality_2, cohort=cls.cohort) cls.offer_6 = test_internship_offer.create_specific_internship_offer( cls.organization_5, cls.speciality_2, cohort=cls.cohort)
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)
def setUpTestData(cls): cls.valid_grade = 'D' cls.not_valid_grade = 'A' cls.na_grade = 'E' cls.apd_index = 0 cls.exception_apd_index = 7 cls.exception_valid_grade = 'B' cls.cohort = CohortFactory() cls.good_student = StudentFactory() cls.score = ScoreFactory( student_affectation__period__cohort=cls.cohort, student_affectation__student=cls.good_student, APD_1='D') cls.bad_student = StudentFactory() cls.score = ScoreFactory( student_affectation__period__cohort=cls.cohort, student_affectation__student=cls.bad_student, APD_1='A')