예제 #1
0
    def test_send_email_for_interview_correctly(self):
        app_info = ApplicationInfoFactory()
        application = ApplicationFactory(application_info=app_info)
        interviewer = InterviewerFactory()

        interviewer.courses_to_interview.add(app_info)

        InterviewerFreeTime.objects.create(interviewer=interviewer,
                                           date=datetime.datetime.now().date(),
                                           start_time='11:00',
                                           end_time='14:00')

        self.assertEqual(0, Interview.objects.count())
        self.assertFalse(application.has_interview_date)
        self.assertEquals(1, Application.objects.without_interviews().count())

        call_command('generate_interview_slots')

        application.refresh_from_db()

        self.assertEquals(0, Application.objects.without_interviews().count())
        self.assertTrue(application.has_interview_date)

        call_command('send_emails_for_interviews')

        self.assertEqual(len(mail.outbox), 1)
예제 #2
0
    def test_counting_applications_without_interviews(self):
        self.assertEquals(0, Application.objects.count())
        self.assertEquals(0, Application.objects.without_interviews().count())
        app_info_1 = ApplicationInfoFactory()

        ApplicationFactory(application_info=app_info_1)
        ApplicationFactory(application_info=app_info_1)

        self.assertEquals(2, Application.objects.without_interviews().count())
예제 #3
0
 def test_confirm_non_existing_application(self):
     app = ApplicationFactory(has_interview_date=False)
     self.assertEqual(self.application.user != app.user, True)
     with self.login(username=self.user.email, password=BaseUserFactory.password):
         response = self.get('interview_system:confirm_interview',
                             app.id, self.interview.uuid)
         self.assertEqual(response.status_code, 404)
예제 #4
0
    def test_interviews_are_generated_correctly(self):
        app_info = ApplicationInfoFactory()
        application = ApplicationFactory(application_info=app_info)
        interviewer = InterviewerFactory()

        interviewer.courses_to_interview.add(app_info)

        InterviewerFreeTime.objects.create(interviewer=interviewer,
                                           date=datetime.now().date(),
                                           start_time='11:00',
                                           end_time='14:00')

        self.assertEqual(0, Interview.objects.count())
        self.assertFalse(application.has_interview_date)
        self.assertEquals(
            1,
            Application.objects.without_interviews_for(app_info).count())

        call_command('generate_interview_slots')

        self.assertEqual(
            1,
            Interview.objects.filter(application__isnull=False).count())
        self.assertEquals(
            0,
            Application.objects.without_interviews_for(app_info).count())
예제 #5
0
    def test_counting_interview_slots_without_applications(self):
        app_info = ApplicationInfoFactory()
        interviewer = InterviewerFactory()
        interviewer.courses_to_interview.add(app_info)

        free_time = InterviewerFreeTime.objects.create(
            interviewer=interviewer,
            date=datetime.now().date(),
            start_time='11:00',
            end_time='14:00')

        interview = Interview.objects.create(interviewer=interviewer,
                                             date=datetime.now().date(),
                                             start_time='11:00',
                                             end_time='11:30',
                                             interviewer_time_slot=free_time)

        Interview.objects.create(interviewer=interviewer,
                                 date=datetime.now().date(),
                                 start_time='12:00',
                                 end_time='12:30',
                                 interviewer_time_slot=free_time)

        self.assertEquals(2, Interview.objects.get_free_slots().count())

        application = ApplicationFactory(application_info=app_info)
        interview.application = application
        interview.save()

        self.assertEquals(1, Interview.objects.get_free_slots().count())
예제 #6
0
    def test_applying_for_the_same_course(self):
        self.assertEqual(0, Application.objects.count())
        ApplicationFactory(user=self.user, application_info=self.application_info)

        with self.login(username=self.user.email, password=BaseUserFactory.password):
            self.post('applications:apply_course',
                      course_url=self.course_description.url)
            self.response_302()
예제 #7
0
 def setUp(self):
     self.user = BaseUserFactory()
     self.user.is_active = True
     self.user.save()
     self.application = ApplicationFactory(user=self.user)
     self.interview = InterviewFactory(application=self.application,
                                       has_confirmed=False)
     self.client = Client()
예제 #8
0
    def test_not_generate_interviews_when_have_not_enough_free_slots_for_app_info(
            self):
        course1, course2 = factory.build_batch(size=2, klass=CourseFactory)
        cd1 = CourseDescriptionFactory(course=course1)
        cd2 = CourseDescriptionFactory(course=course2)
        app_info1 = ApplicationInfoFactory(course=cd1)
        app_info2 = ApplicationInfoFactory(course=cd2)

        ApplicationFactory(application_info=app_info1)
        ApplicationFactory(application_info=app_info1)
        ApplicationFactory(application_info=app_info1)
        ApplicationFactory(application_info=app_info2)
        ApplicationFactory(application_info=app_info2)
        interviewer1, interviewer2 = factory.build_batch(
            size=2, klass=InterviewerFactory)

        interviewer1.courses_to_interview.add(app_info1)
        interviewer2.courses_to_interview.add(app_info2)

        InterviewerFreeTime.objects.create(interviewer=interviewer1,
                                           date=datetime.now().date(),
                                           start_time='11:00',
                                           end_time='12:00')
        InterviewerFreeTime.objects.create(interviewer=interviewer2,
                                           date=datetime.now().date(),
                                           start_time='12:00',
                                           end_time='15:00')

        self.assertEquals(
            3,
            Application.objects.without_interviews_for(app_info1).count())
        self.assertEquals(
            2,
            Application.objects.without_interviews_for(app_info2).count())

        call_command('generate_interview_slots')
        self.assertEquals(
            3,
            Application.objects.without_interviews_for(app_info1).count())
        self.assertEquals(2,
                          Interview.objects.free_slots_for(app_info1).count())
        self.assertEquals(
            0,
            Application.objects.without_interviews_for(app_info2).count())
        self.assertEquals(4,
                          Interview.objects.free_slots_for(app_info2).count())
예제 #9
0
    def test_counting_applications_for_app_info_without_interviews(self):
        course1, course2 = factory.build_batch(size=2, klass=CourseFactory)
        cd1 = CourseDescriptionFactory(course=course1)
        cd2 = CourseDescriptionFactory(course=course2)
        app_info1 = ApplicationInfoFactory(course=cd1)
        app_info2 = ApplicationInfoFactory(course=cd2)

        self.assertEquals(
            0,
            Application.objects.without_interviews_for(app_info1).count())
        self.assertEquals(
            0,
            Application.objects.without_interviews_for(app_info2).count())

        ApplicationFactory(application_info=app_info1)
        ApplicationFactory(application_info=app_info1)
        ApplicationFactory(application_info=app_info1)
        ApplicationFactory(application_info=app_info1)
        ApplicationFactory(application_info=app_info2)
        ApplicationFactory(application_info=app_info2)

        self.assertEquals(
            4,
            Application.objects.without_interviews_for(app_info1).count())
        self.assertEquals(
            2,
            Application.objects.without_interviews_for(app_info2).count())
        self.assertEquals(6, Application.objects.without_interviews().count())
예제 #10
0
    def test_counting_confirmed_interviews_with_app_info(self):
        app_info = ApplicationInfoFactory()
        application1 = ApplicationFactory(application_info=app_info)
        application2 = ApplicationFactory(application_info=app_info)
        application3 = ApplicationFactory(application_info=app_info)

        interviewer = InterviewerFactory()
        interviewer.courses_to_interview.add(app_info)

        free_time = InterviewerFreeTime.objects.create(
            interviewer=interviewer,
            date=datetime.now().date(),
            start_time='11:00',
            end_time='14:00')

        self.assertEquals(0, Interview.objects.confirmed_for(app_info).count())
        Interview.objects.create(interviewer=interviewer,
                                 application=application1,
                                 date=datetime.now().date(),
                                 start_time='11:00',
                                 end_time='11:30',
                                 interviewer_time_slot=free_time,
                                 has_confirmed=True)

        Interview.objects.create(interviewer=interviewer,
                                 application=application2,
                                 date=datetime.now().date(),
                                 start_time='12:00',
                                 end_time='12:30',
                                 interviewer_time_slot=free_time,
                                 has_confirmed=True)

        Interview.objects.create(interviewer=interviewer,
                                 application=application3,
                                 date=datetime.now().date(),
                                 start_time='12:00',
                                 end_time='12:30',
                                 interviewer_time_slot=free_time)

        self.assertEquals(2, Interview.objects.confirmed_for(app_info).count())
예제 #11
0
    def test_generate_interviews_for_more_interviewers(self):
        app_info = ApplicationInfoFactory()
        application1 = ApplicationFactory(application_info=app_info)
        application2 = ApplicationFactory(application_info=app_info)
        application3 = ApplicationFactory(application_info=app_info)
        interviewer1, interviewer2 = factory.build_batch(
            size=2, klass=InterviewerFactory)

        interviewer1.courses_to_interview.add(app_info)
        interviewer2.courses_to_interview.add(app_info)

        InterviewerFreeTime.objects.create(interviewer=interviewer1,
                                           date=datetime.now().date(),
                                           start_time='11:00',
                                           end_time='14:00')

        InterviewerFreeTime.objects.create(interviewer=interviewer2,
                                           date=datetime.now().date(),
                                           start_time='12:00',
                                           end_time='15:00')

        self.assertEquals(
            3,
            Application.objects.without_interviews_for(app_info).count())

        call_command('generate_interview_slots')
        self.assertEquals(9,
                          Interview.objects.free_slots_for(app_info).count())
        interviewer_for_app1 = Interview.objects.get(
            application=application1).interviewer
        interviewer_for_app2 = Interview.objects.get(
            application=application2).interviewer
        interviewer_for_app3 = Interview.objects.get(
            application=application3).interviewer
        self.assertNotEqual(interviewer_for_app1, interviewer_for_app2)
        self.assertEqual(interviewer_for_app1, interviewer_for_app3)
        self.assertEquals(
            0,
            Application.objects.without_interviews_for(app_info).count())
예제 #12
0
    def test_interviews_are_generated_correctly_if_new_application_is_added_after_generation(
            self):
        app_info = ApplicationInfoFactory()
        ApplicationFactory(application_info=app_info)
        interviewer = InterviewerFactory()
        interviewer.courses_to_interview.add(app_info)

        InterviewerFreeTime.objects.create(interviewer=interviewer,
                                           date=datetime.now().date(),
                                           start_time='11:00',
                                           end_time='14:00')

        self.assertEquals(1, Application.objects.without_interviews().count())
        call_command('generate_interview_slots')
        self.assertEquals(5, Interview.objects.get_free_slots().count())
        self.assertEquals(0, Application.objects.without_interviews().count())

        ApplicationFactory(application_info=app_info)
        self.assertEquals(1, Application.objects.without_interviews().count())

        call_command('generate_interview_slots')
        self.assertEquals(4, Interview.objects.get_free_slots().count())
        self.assertEquals(0, Application.objects.without_interviews().count())
예제 #13
0
    def test_not_generate_interviews_when_have_not_enough_free_slots(self):
        app_info = ApplicationInfoFactory()
        interviewer = InterviewerFactory()
        interviewer.courses_to_interview.add(app_info)

        InterviewerFreeTime.objects.create(interviewer=interviewer,
                                           date=datetime.now().date(),
                                           start_time='11:00',
                                           end_time='12:00')

        ApplicationFactory(application_info=app_info)
        ApplicationFactory(application_info=app_info)
        ApplicationFactory(application_info=app_info)
        self.assertEquals(
            3,
            Application.objects.without_interviews_for(app_info).count())

        call_command('generate_interview_slots')
        self.assertEquals(
            3,
            Application.objects.without_interviews_for(app_info).count())
        self.assertEquals(2,
                          Interview.objects.free_slots_for(app_info).count())
예제 #14
0
    def test_registered_user_editing_apply_form(self):
        self.assertEqual(0, Application.objects.count())
        app_problem1 = ApplicationProblemFactory()
        app_problem2 = ApplicationProblemFactory()
        self.application_info.applicationproblem_set.add(app_problem1)
        self.application_info.applicationproblem_set.add(app_problem2)

        application = ApplicationFactory(application_info=self.application_info, user=self.user)
        solution_problem1 = ApplicationProblemSolutionFactory(application=application)
        solution_problem2 = ApplicationProblemSolutionFactory(application=application)

        solution_problem1.problem = app_problem1
        solution_problem1.save()
        solution_problem2.problem = app_problem2
        solution_problem2.save()

        self.assertEqual(1, Application.objects.filter(user=self.user).count())
        self.assertEqual(2, ApplicationProblemSolution.objects.filter(application=application).count())

        with self.login(username=self.user.email, password=BaseUserFactory.password):
            data = {"phone": faker.random_number(),
                    "skype": faker.word(),
                    "studies_at": faker.word(),
                    "works_at": faker.word(),
                    "task_field_count": 2,
                    "task_1": faker.url(),
                    "task_2": faker.url()}

            self.post('applications:edit_application',
                      course_url=self.course_description.url,
                      data=data)

            self.response_302()

        app_problem_solutions = ApplicationProblemSolution.objects.filter(application=application).all()
        self.assertEqual(1, Application.objects.filter(user=self.user).count())
        self.assertEqual(2, app_problem_solutions.count())
        self.assertTrue([solution_problem1, solution_problem2] != app_problem_solutions)
예제 #15
0
    def test_counting_interview_slots_for_app_info_without_applications(self):
        course1, course2 = factory.build_batch(size=2, klass=CourseFactory)
        cd1 = CourseDescriptionFactory(course=course1)
        cd2 = CourseDescriptionFactory(course=course2)
        app_info1 = ApplicationInfoFactory(course=cd1)
        app_info2 = ApplicationInfoFactory(course=cd2)

        interviewer1 = InterviewerFactory()
        interviewer1.courses_to_interview.add(app_info1)
        interviewer2 = InterviewerFactory()
        interviewer2.courses_to_interview.add(app_info2)

        free_time1 = InterviewerFreeTime.objects.create(
            interviewer=interviewer1,
            date=datetime.now().date(),
            start_time='11:00',
            end_time='14:00')
        free_time2 = InterviewerFreeTime.objects.create(
            interviewer=interviewer1,
            date=datetime.now().date(),
            start_time='10:00',
            end_time='14:00')

        Interview.objects.create(interviewer=interviewer2,
                                 date=datetime.now().date(),
                                 start_time='12:00',
                                 end_time='12:30',
                                 interviewer_time_slot=free_time2)

        Interview.objects.create(interviewer=interviewer2,
                                 date=datetime.now().date(),
                                 start_time='12:00',
                                 end_time='12:30',
                                 interviewer_time_slot=free_time2)

        interview = Interview.objects.create(interviewer=interviewer1,
                                             date=datetime.now().date(),
                                             start_time='11:00',
                                             end_time='11:30',
                                             interviewer_time_slot=free_time1)

        Interview.objects.create(interviewer=interviewer1,
                                 date=datetime.now().date(),
                                 start_time='12:00',
                                 end_time='12:30',
                                 interviewer_time_slot=free_time1)

        self.assertEquals(2,
                          Interview.objects.free_slots_for(app_info1).count())
        self.assertEquals(2,
                          Interview.objects.free_slots_for(app_info2).count())
        self.assertEquals(4, Interview.objects.get_free_slots().count())

        application = ApplicationFactory(application_info=app_info1)
        interview.application = application
        interview.save()

        self.assertEquals(1,
                          Interview.objects.free_slots_for(app_info1).count())
        self.assertEquals(2,
                          Interview.objects.free_slots_for(app_info2).count())
        self.assertEquals(3, Interview.objects.get_free_slots().count())
예제 #16
0
    def test_generate_interviews_for_different_courses_with_different_interviewers(
            self):
        course1, course2 = factory.build_batch(size=2, klass=CourseFactory)
        cd1 = CourseDescriptionFactory(course=course1)
        cd2 = CourseDescriptionFactory(course=course2)
        app_info1 = ApplicationInfoFactory(course=cd1)
        app_info2 = ApplicationInfoFactory(course=cd2)

        application1 = ApplicationFactory(application_info=app_info1)
        application2 = ApplicationFactory(application_info=app_info2)
        application3 = ApplicationFactory(application_info=app_info1)
        application4 = ApplicationFactory(application_info=app_info2)
        application5 = ApplicationFactory(application_info=app_info1)
        interviewer1, interviewer2, interviewer3 = factory.build_batch(
            size=3, klass=InterviewerFactory)

        interviewer1.courses_to_interview.add(app_info1)
        interviewer2.courses_to_interview.add(app_info2)
        interviewer3.courses_to_interview.add(app_info1)

        InterviewerFreeTime.objects.create(interviewer=interviewer1,
                                           date=datetime.now().date(),
                                           start_time='11:00',
                                           end_time='14:00')
        InterviewerFreeTime.objects.create(interviewer=interviewer2,
                                           date=datetime.now().date(),
                                           start_time='12:00',
                                           end_time='15:00')
        InterviewerFreeTime.objects.create(interviewer=interviewer3,
                                           date=datetime.now().date(),
                                           start_time='13:00',
                                           end_time='15:00')

        self.assertEquals(
            3,
            Application.objects.without_interviews_for(app_info1).count())
        self.assertEquals(
            2,
            Application.objects.without_interviews_for(app_info2).count())
        self.assertEquals(5, Application.objects.without_interviews().count())

        call_command('generate_interview_slots')
        self.assertEquals(7,
                          Interview.objects.free_slots_for(app_info1).count())
        self.assertEquals(4,
                          Interview.objects.free_slots_for(app_info2).count())
        self.assertEquals(11, Interview.objects.get_free_slots().count())

        interviewer_for_app1 = Interview.objects.get(
            application=application1).interviewer
        interviewer_for_app2 = Interview.objects.get(
            application=application2).interviewer
        interviewer_for_app3 = Interview.objects.get(
            application=application3).interviewer
        interviewer_for_app4 = Interview.objects.get(
            application=application4).interviewer
        interviewer_for_app5 = Interview.objects.get(
            application=application5).interviewer

        self.assertEqual(interviewer1, interviewer_for_app1)
        self.assertEqual(interviewer1, interviewer_for_app5)
        self.assertEqual(interviewer2, interviewer_for_app2)
        self.assertEqual(interviewer2, interviewer_for_app4)
        self.assertEqual(interviewer3, interviewer_for_app3)

        self.assertTrue(application1 in interviewer1.interviews.all())
        self.assertTrue(application5 in interviewer1.interviews.all())
        self.assertTrue(application2 in interviewer2.interviews.all())
        self.assertTrue(application4 in interviewer2.interviews.all())
        self.assertTrue(application3 in interviewer3.interviews.all())