def test_find(self): period_1 = PeriodFactory(name="P1") period_2 = PeriodFactory(name="P5") self.assertEqual(period_1, mdl_period.get_by_name("P1")) self.assertEqual(period_2, mdl_period.get_by_name("P5")) self.assertFalse(mdl_period.get_by_name("P4"))
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 test_period_save_ok(self): period = PeriodFactory(cohort=self.cohort, name='P24') queryset = Period.objects.filter(cohort=self.cohort, name='P24') self.assertEqual(queryset.count(), 1) period_db = queryset.first() self.assertEqual(period_db.id, period.id) url = self.url_for_cohort_period('period_save', self.cohort, period) data = { 'name': 'P243', 'date_start': period.date_start.date(), 'date_end': period.date_end.date(), } response = self.client.post(url, data=data) queryset = Period.objects.filter(cohort=self.cohort, name='P243') self.assertEqual(queryset.count(), 1) period_db = queryset.first() self.assertEqual(period_db.id, period.id) self.assertEqual(period_db.date_start, period.date_start.date()) self.assertEqual(period_db.date_end, period.date_end.date()) kwargs = { 'cohort_id': self.cohort.id, } self.assertRedirects(response, reverse('internships_periods', kwargs=kwargs))
def test_period_get_cohort_exist_but_period_not_assign_to_cohort(self): period = PeriodFactory() url = self.url_for_cohort_period('period_get', self.cohort, period) response = self.client.get(url) self.assertEqual(response.status_code, 404)
def test_period_delete_cohort_ok_period_404(self): period = PeriodFactory() url = self.url_for_cohort_period('period_delete', self.cohort, period) response = self.client.get(url) self.assertEqual(response.status_code, 404)
def test_compute_evolution_score(self): student_name = "test_student" student_info = InternshipStudentInformationFactory( person__last_name=student_name, cohort=self.cohort) student = StudentFactory(person=student_info.person) PeriodFactory(name='last_period', cohort=self.cohort) ScoreFactory(student_affectation__student=student, student_affectation__period=self.period, APD_1='A', validated=True) ScoreFactory(student_affectation__student=student, student_affectation__period=self.other_period, APD_1='C', validated=True) ScoreMappingFactory(period=self.other_period, cohort=self.cohort, score_A=20, score_B=15, score_C=10, score_D=0, apd=1) url = reverse('internship_scores_encoding', kwargs={'cohort_id': self.cohort.pk}) response = self.client.get(url, {'free_text': student_name}) evolution_score = response.context['students'].object_list[ 0].evolution_score self.assertEqual(evolution_score, 15)
def test_filter_students_by_current_internship(self): period = PeriodFactory(cohort=self.cohort, date_start=date.today(), date_end=date.today()) student_info = InternshipStudentInformationFactory( cohort=self.cohort, person=self.student_1.person) affectation = StudentAffectationStatFactory(student=self.student_1, period=period) url = reverse(internships_student_resume, kwargs={ 'cohort_id': self.cohort.id, }) response = self.client.get(url) actual, stats = student._get_students_with_status( request=response.wsgi_request, cohort=self.cohort, filters=(None, True)) expected = [student_info] self.assertCountEqual(expected, actual) for item_expected in expected: self.assertIn(item_expected, actual) self.assertEqual( actual[0].current_internship, "{}{}".format(affectation.speciality.acronym, affectation.organization.reference))
def test_list_periods_existing_cohort_with_periods(self): period = PeriodFactory(cohort=self.cohort) url = reverse('internships_periods', kwargs={'cohort_id': self.cohort.id}) response = self.client.get(url) self.assertEqual(len(response.context['periods']), 1) self.assertEqual(response.context['periods'][0], period)
def setUpTestData(cls) -> None: cls.cohort = CohortFactory() cls.student = StudentFactory() cls.period = PeriodFactory(cohort=cls.cohort) cls.internship_score = ScoreFactory( student_affectation__student=cls.student, student_affectation__period=cls.period, )
def setUpTestData(cls): cls.cohort = CohortFactory() cls.period = PeriodFactory(cohort=cls.cohort) cls.user = User.objects.create_user('demo', email='*****@*****.**', password='******') permission = Permission.objects.get(codename='is_internship_manager') cls.user.user_permissions.add(permission) cls.user.save() cls.file = SimpleUploadedFile(name='test', content=b'test')
def test_save_period_places(self): PeriodFactory(name="P1", cohort=self.cohort) PeriodFactory(name="P5", cohort=self.cohort) kwargs = { 'internship_id': self.internship_offer.id, 'cohort_id': self.cohort.id, } url = reverse("save_period_places", kwargs=kwargs) 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 test_period_new_cohort_exist(self): url = reverse('period_new', kwargs={'cohort_id': self.cohort.id}) period_factory = PeriodFactory.build() period = { 'name': period_factory.name, 'date_start': period_factory.date_start.strftime('%Y-%m-%d'), 'date_end': period_factory.date_end.strftime('%Y-%m-%d'), } response = self.client.post(url, data=period, follow=True) self.assertEqual(response.status_code, 200)
def test_period_get_ok(self): period = PeriodFactory(cohort=self.cohort) url = self.url_for_cohort_period('period_get', self.cohort, period) response = self.client.get(url) self.assertTemplateUsed(response, 'period_create.html') self.assertEqual(response.context['period'], period) self.assertEqual(response.context['cohort'], self.cohort) url_form = self.url_for_cohort_period('period_save', self.cohort, period) self.assertEqual(response.context['url_form'], url_form)
def setUpTestData(cls): cls.cohort = CohortFactory() cls.past_period_no_scores_submitted = PeriodFactory(cohort=cls.cohort, date_end=date.today()-timedelta(days=1)) cls.past_period_excused = PeriodFactory(cohort=cls.cohort, date_end=date.today()-timedelta(days=1)) cls.past_period_edited = PeriodFactory(cohort=cls.cohort, date_end=date.today()-timedelta(days=1)) cls.user = PersonWithPermissionsFactory('is_internship_manager').user cls.student = StudentFactory() cls.student.organizations = { cls.past_period_no_scores_submitted.name: OrganizationFactory().reference, cls.past_period_excused.name: OrganizationFactory().reference, cls.past_period_edited.name: OrganizationFactory().reference, } cls.student.periods_scores = { cls.past_period_no_scores_submitted.name: NO_SUBMISSION_SCORE, cls.past_period_excused.name: {'edited': EXCUSED_PERIOD_SCORE, 'computed': NO_SUBMISSION_SCORE}, cls.past_period_edited.name: {'edited': EDITED_PERIOD_SCORE, 'computed': COMPUTED_PERIOD_SCORE}, } cls.periods = [ cls.past_period_no_scores_submitted, cls.past_period_excused, cls.past_period_edited, ]
class InternshipPeriodEncodingReminderTest(TestCase): 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) @mock.patch('internship.utils.mails.mails_management.send_messages') def test_send_internship_period_encoding_reminder_only_to_active_master_with_affectations( self, mock_send_messages): mails_management.send_internship_period_encoding_reminder(self.period) _, args = mock_send_messages.call_args self.assertTrue(mock_send_messages.called) self.assertEqual( args['message_content']['template_base_data'], { 'link': settings.INTERNSHIP_SCORE_ENCODING_URL, 'period': self.period.name }) self.assertEqual( args['message_content']['receivers'][0], { **args['message_content']['receivers'][0], 'receiver_email': self.active_master_allocation.master.person.email, 'receiver_person_id': self.active_master_allocation.master.person_id, }) self.period.refresh_from_db() self.assertTrue(self.period.reminder_mail_sent)
def test_ajax_save_evaluation_status(self): affectation = StudentAffectationStatFactory( student=StudentFactory(), period=PeriodFactory(cohort=self.cohort)) self.assertFalse(affectation.internship_evaluated) url = reverse('save_evaluation_status', kwargs={'cohort_id': self.cohort.pk}) response = self.client.post(url, data={ 'student': affectation.student.registration_id, 'period': affectation.period.name, 'status': 'true' }) affectation.refresh_from_db() self.assertEqual(response.status_code, 204) self.assertTrue(affectation.internship_evaluated)
def test_period_delete_ok(self): period = PeriodFactory(cohort=self.cohort) from internship.models.period import Period queryset = Period.objects.filter(cohort=self.cohort) self.assertEqual(queryset.count(), 1) url = self.url_for_cohort_period('period_delete', self.cohort, period) response = self.client.get(url) kwargs = {'cohort_id': self.cohort.id} self.assertRedirects(response, reverse('internships_periods', kwargs=kwargs)) queryset = Period.objects.filter(cohort=self.cohort) self.assertEqual(queryset.count(), 0)
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 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])
def test_send_recap(self, mock_send_mail): student_info = InternshipStudentInformationFactory(cohort=self.cohort) student = StudentFactory(person=student_info.person) period = PeriodFactory(name='PTEST', cohort=self.cohort, date_end=date.today() - timedelta(days=1)) student_affectation = StudentAffectationStatFactory(student=student, period=period) ScoreFactory(student_affectation=student_affectation, validated=True) url = reverse('send_summary', kwargs={ 'cohort_id': self.cohort.pk, 'period_id': period.pk }) response = self.client.post( url, data={'selected_student': [student_info.pk]}) messages_list = [ str(msg) for msg in list(messages.get_messages(response.wsgi_request)) ] self.assertIn(_("Summaries have been sent successfully"), messages_list) self.assertTrue(mock_send_mail.called)
def setUpTestData(cls): cls.p1 = PeriodFactory.build(name="P1", id=1) cls.p2 = PeriodFactory.build(name="P2", id=2) cls.p3 = PeriodFactory.build(name="P3", id=3) cls.p4 = PeriodFactory.build(name="P4", id=4) cls.p5 = PeriodFactory.build(name="P5", id=5)
def setUpTestData(cls): cls.cohort = CohortFactory() cls.period = PeriodFactory(cohort=cls.cohort)
def setUp(self) -> None: self.cohort = CohortFactory() self.student_info = InternshipStudentInformationFactory( cohort=self.cohort) self.student = StudentFactory(person=self.student_info.person) self.period = PeriodFactory(cohort=self.cohort)
def test_period_is_active(self): delta = relativedelta(days=1) period = PeriodFactory(date_start=date.today() - delta, date_end=date.today() + delta) self.assertTrue(period.is_active)
def test_dates(self): period = PeriodFactory() self.assertLess(period.date_start, period.date_end)
def create_period(name="P1", cohort=None): return PeriodFactory(name=name, cohort=cohort)
def setUp(self): self.p1 = PeriodFactory.build(name="P1", id=1) self.p2 = PeriodFactory.build(name="P2", id=2) self.p3 = PeriodFactory.build(name="P3", id=3) self.p4 = PeriodFactory.build(name="P4", id=4) self.p5 = PeriodFactory.build(name="P5", id=5)
def test_send_period_encoding_reminder_mail(self, mock_send_mail): PeriodFactory(date_end=date.today()) send_period_encoding_reminder_mail.run() self.assertTrue(mock_send_mail.called)
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) }
def test_reminder_not_sent_when_already_sent(self, mock_send_mail): PeriodFactory(date_end=date.today(), reminder_mail_sent=True) send_period_encoding_reminder_mail.run() self.assertFalse(mock_send_mail.called)