def test_generate_slots_for_interviewer_free_time_with_generated_slots(self): """ No interview slots should be generated, if the interviewer free time already has existing slots generated for that period """ client = Client() client.login( email=self.teacher_admin.email, password='******' ) url = reverse('admin:course_interviews_interviewslot_changelist') response = client.get(url, follow=True) result_list_before_slot_generation = response.context_data['cl'].result_list interview_length = 30 break_between_interviews = 10 interview_slots_generator = GenerateInterviewSlots( interview_length, break_between_interviews) interview_slots_generator.generate_interview_slots() response = client.get(url, follow=True) result_list_after_slot_generation = response.context_data['cl'].result_list self.assertCountEqual(result_list_before_slot_generation, result_list_after_slot_generation)
def test_generate_slots_for_interviewer_free_time_with_generated_slots( self): """ No interview slots should be generated, if the interviewer free time already has existing slots generated for that period """ client = Client() client.login(email=self.teacher_admin.email, password='******') url = reverse('admin:course_interviews_interviewslot_changelist') response = client.get(url, follow=True) result_list_before_slot_generation = response.context_data[ 'cl'].result_list interview_length = 30 break_between_interviews = 10 interview_slots_generator = GenerateInterviewSlots( interview_length, break_between_interviews) interview_slots_generator.generate_interview_slots() response = client.get(url, follow=True) result_list_after_slot_generation = response.context_data[ 'cl'].result_list self.assertCountEqual(result_list_before_slot_generation, result_list_after_slot_generation)
def test_generate_interviews_for_students_without_interview_date(self): # Create valid time slot tomorrow = date.today() + timedelta(days=1) InterviewerFreeTime.objects.create( teacher=self.teacher_user1, date=str(tomorrow), start_time="15:00", end_time="16:00") interview_length = 20 break_between_interviews = 10 interview_slots_generator = GenerateInterviewSlots( interview_length, break_between_interviews) interview_slots_generator.generate_interview_slots() interview_generator = GenerateInterviews() interview_generator.generate_interviews() client = Client() client.login( email=self.teacher_admin.email, password='******' ) # There are only two slots, so only the first two students should have interview dates self.assertEqual(Student.objects.get(id=self.student1.id).has_interview_date, True) self.assertEqual(Student.objects.get(id=self.student2.id).has_interview_date, True) self.assertEqual(Student.objects.get(id=self.student3.id).has_interview_date, False)
def test_change_permissions_interviewer_free_time_after_slots_are_generated(self): """ teacher should not be able to delete his interview_free_time if slots for that time are already generated - no interviews are gona be unanswered if he can not attend some interview, he has to tell us """ test_teacher_user = Teacher.objects.create_user("*****@*****.**", "123", skype="testuser_user") test_teacher_user.first_name = "Test" test_teacher_user.last_name = "Testov" test_teacher_user.is_staff = True test_teacher_user.groups.add(self.teacher_group) test_teacher_user.save() interview_length = 20 break_between_interviews = 10 interview_slots_generator = GenerateInterviewSlots(interview_length, break_between_interviews) time_slot = InterviewerFreeTime.objects.create( teacher=test_teacher_user, date=str(self.tomorrow), start_time="15:00", end_time="15:30" ) interview_slots_generator.generate_interview_slots() client = Client() client.login(email=test_teacher_user.email, password="******") url = reverse("admin:course_interviews_interviewerfreetime_change", args=(time_slot.id,)) data = {"buffer_time": True} response = client.post(url, data, follow=True) self.assertEqual(response.status_code, 403)
def test_generate_interviews_for_students_with_interview_date(self): """ If a student has interview slot, he should not receive another one He can change his slot only through the choose-interview url """ # Create valid time slot tomorrow = date.today() + timedelta(days=1) InterviewerFreeTime.objects.create(teacher=self.teacher_user1, date=str(tomorrow), start_time="15:00", end_time="16:00") interview_length = 20 break_between_interviews = 10 interview_slots_generator = GenerateInterviewSlots( interview_length, break_between_interviews) interview_slots_generator.generate_interview_slots() self.student1.has_interview_date = True self.student1.save() interview_generator = GenerateInterviews() interview_generator.generate_interviews() client = Client() client.login(email=self.teacher_admin.email, password='******') # With two slots available and student1 with interview date, # all three students should have interview dates self.assertEqual( Student.objects.get(id=self.student1.id).has_interview_date, True) self.assertEqual( Student.objects.get(id=self.student2.id).has_interview_date, True) self.assertEqual( Student.objects.get(id=self.student3.id).has_interview_date, True)
def test_generate_interviews_for_students_without_interview_date(self): # Create valid time slot tomorrow = date.today() + timedelta(days=1) InterviewerFreeTime.objects.create(teacher=self.teacher_user1, date=str(tomorrow), start_time="15:00", end_time="16:00") interview_length = 20 break_between_interviews = 10 interview_slots_generator = GenerateInterviewSlots( interview_length, break_between_interviews) interview_slots_generator.generate_interview_slots() interview_generator = GenerateInterviews() interview_generator.generate_interviews() client = Client() client.login(email=self.teacher_admin.email, password='******') # There are only two slots, so only the first two students should have interview dates self.assertEqual( Student.objects.get(id=self.student1.id).has_interview_date, True) self.assertEqual( Student.objects.get(id=self.student2.id).has_interview_date, True) self.assertEqual( Student.objects.get(id=self.student3.id).has_interview_date, False)
def handle(self, **options): interview_length = 20 break_between_interviews = 10 interview_slots_generator = GenerateInterviewSlots( interview_length, break_between_interviews) interview_slots_generator.generate_interview_slots() generated_slots = interview_slots_generator.get_generated_slots() print(str(generated_slots) + ' slots were generated')
def test_generate_slots_for_non_buffer_teacher_free_time(self): InterviewerFreeTime.objects.create(teacher=self.teacher_user2, date=str(self.tomorrow), start_time="16:00", end_time="17:00", buffer_time=False) interview_length = 20 break_between_interviews = 10 interview_slots_generator = GenerateInterviewSlots( interview_length, break_between_interviews) interview_slots_generator.generate_interview_slots() buffer_slot = InterviewSlot.objects.latest('id') self.assertEqual(buffer_slot.buffer_slot, False)
def test_generate_slots_for_non_buffer_teacher_free_time(self): InterviewerFreeTime.objects.create( teacher=self.teacher_user2, date=str(self.tomorrow), start_time="16:00", end_time="17:00", buffer_time=False) interview_length = 20 break_between_interviews = 10 interview_slots_generator = GenerateInterviewSlots( interview_length, break_between_interviews) interview_slots_generator.generate_interview_slots() buffer_slot = InterviewSlot.objects.latest('id') self.assertEqual(buffer_slot.buffer_slot, False)
def test_change_permissions_interviewer_free_time_after_slots_are_generated(self): """ teacher should not be able to delete his interview_free_time if slots for that time are already generated - no interviews are gona be unanswered if he can not attend some interview, he has to tell us """ test_teacher_user = Teacher.objects.create_user( "*****@*****.**", "123", skype="testuser_user") test_teacher_user.first_name = "Test" test_teacher_user.last_name = "Testov" test_teacher_user.is_staff = True test_teacher_user.groups.add(self.teacher_group) test_teacher_user.save() interview_length = 20 break_between_interviews = 10 interview_slots_generator = GenerateInterviewSlots( interview_length, break_between_interviews) time_slot = InterviewerFreeTime.objects.create( teacher=test_teacher_user, date=str(self.tomorrow), start_time="15:00", end_time="15:30") interview_slots_generator.generate_interview_slots() client = Client() client.login( email=test_teacher_user.email, password='******' ) url = reverse('admin:course_interviews_interviewerfreetime_change', args=(time_slot.id, )) data = { "buffer_time": True } response = client.post(url, data, follow=True) self.assertEqual(response.status_code, 403)
def test_generated_interviews_proper_length(self): self.test_teacher_user = Teacher.objects.create_user( "*****@*****.**", "123", skype="testuser_user") self.test_teacher_user.first_name = "Test" self.test_teacher_user.last_name = "Testov" self.test_teacher_user.is_staff = True self.test_teacher_user.groups.add(self.teacher_group) self.test_teacher_user.save() interview_length = 20 break_between_interviews = 10 interview_slots_generator = GenerateInterviewSlots( interview_length, break_between_interviews) time_slot1 = InterviewerFreeTime.objects.create( teacher=self.test_teacher_user, date=str(self.tomorrow), start_time="15:00", end_time="15:15") # Not enough time for an interview, no slots should be generated interview_slots_generator.generate_interview_slots() slots = InterviewSlot.objects.all().filter( teacher_time_slot=time_slot1).count() self.assertEqual(slots, 0) time_slot2 = InterviewerFreeTime.objects.create( teacher=self.test_teacher_user, date=str(self.tomorrow), start_time="15:00", end_time="15:20") # Generate one interview slot interview_slots_generator.generate_interview_slots() slots = InterviewSlot.objects.all().filter( teacher_time_slot=time_slot2).count() self.assertEqual(slots, 1) time_slot3 = InterviewerFreeTime.objects.create( teacher=self.test_teacher_user, date=str(self.tomorrow), start_time="15:00", end_time="17:00") # Generate 4 more interview slots interview_slots_generator.generate_interview_slots() slots = InterviewSlot.objects.all().filter( teacher_time_slot=time_slot3).count() self.assertEqual(slots, 4)
def test_generate_slots_for_interviewer_free_time_without_generated_slots(self): self.test_teacher_user = Teacher.objects.create_user( "*****@*****.**", "123", skype="testuser_user") self.test_teacher_user.first_name = "Test" self.test_teacher_user.last_name = "Testov" self.test_teacher_user.is_staff = True self.test_teacher_user.groups.add(self.teacher_group) self.test_teacher_user.save() InterviewerFreeTime.objects.create( teacher=self.test_teacher_user, date=str(self.tomorrow), start_time="15:00", end_time="17:00") interview_length = 30 break_between_interviews = 10 interview_slots_generator = GenerateInterviewSlots( interview_length, break_between_interviews) # For a total duration of 2 hours and interview_length + break = 40 minutes # a total of three interview slots should be generated interview_slots_generator.generate_interview_slots() client = Client() client.login( email=self.test_teacher_user.email, password='******' ) url = reverse('admin:course_interviews_interviewslot_changelist') response = client.get(url, follow=True) result_list = response.context_data['cl'].result_list # The new teacher should see his three newly generated slots self.assertEqual(len(result_list), 3)
def test_generate_interview_for_slot_date_that_is_today(self): """ Interviews for slots with date equal to today should not be generated """ # Create time slot for today today = date.today() InterviewerFreeTime.objects.create( teacher=self.teacher_user1, date=str(today), start_time="15:00", end_time="15:30") # Create valid time slot tomorrow = date.today() + timedelta(days=1) InterviewerFreeTime.objects.create( teacher=self.teacher_user1, date=str(tomorrow), start_time="15:00", end_time="15:30") interview_length = 20 break_between_interviews = 10 interview_slots_generator = GenerateInterviewSlots( interview_length, break_between_interviews) interview_slots_generator.generate_interview_slots() interview_generator = GenerateInterviews() interview_generator.generate_interviews() today_slot = InterviewSlot.objects.all().filter(teacher_time_slot__date=today) today_slot = today_slot[0] tomorrow_slot = InterviewSlot.objects.all().filter(teacher_time_slot__date=tomorrow) tomorrow_slot = tomorrow_slot[0] self.assertEqual(today_slot.student, None) self.assertEqual(tomorrow_slot.student, self.student1)
def test_generate_interview_for_slot_date_that_is_today(self): """ Interviews for slots with date equal to today should not be generated """ # Create time slot for today today = date.today() InterviewerFreeTime.objects.create(teacher=self.teacher_user1, date=str(today), start_time="15:00", end_time="15:30") # Create valid time slot tomorrow = date.today() + timedelta(days=1) InterviewerFreeTime.objects.create(teacher=self.teacher_user1, date=str(tomorrow), start_time="15:00", end_time="15:30") interview_length = 20 break_between_interviews = 10 interview_slots_generator = GenerateInterviewSlots( interview_length, break_between_interviews) interview_slots_generator.generate_interview_slots() interview_generator = GenerateInterviews() interview_generator.generate_interviews() today_slot = InterviewSlot.objects.all().filter( teacher_time_slot__date=today) today_slot = today_slot[0] tomorrow_slot = InterviewSlot.objects.all().filter( teacher_time_slot__date=tomorrow) tomorrow_slot = tomorrow_slot[0] self.assertEqual(today_slot.student, None) self.assertEqual(tomorrow_slot.student, self.student1)
def test_generate_interviews_for_students_with_interview_date(self): """ If a student has interview slot, he should not receive another one He can change his slot only through the choose-interview url """ # Create valid time slot tomorrow = date.today() + timedelta(days=1) InterviewerFreeTime.objects.create( teacher=self.teacher_user1, date=str(tomorrow), start_time="15:00", end_time="16:00") interview_length = 20 break_between_interviews = 10 interview_slots_generator = GenerateInterviewSlots( interview_length, break_between_interviews) interview_slots_generator.generate_interview_slots() self.student1.has_interview_date = True self.student1.save() interview_generator = GenerateInterviews() interview_generator.generate_interviews() client = Client() client.login( email=self.teacher_admin.email, password='******' ) # With two slots available and student1 with interview date, # all three students should have interview dates self.assertEqual(Student.objects.get(id=self.student1.id).has_interview_date, True) self.assertEqual(Student.objects.get(id=self.student2.id).has_interview_date, True) self.assertEqual(Student.objects.get(id=self.student3.id).has_interview_date, True)
def test_generate_slots_for_interviewer_free_time_without_generated_slots( self): self.test_teacher_user = Teacher.objects.create_user( "*****@*****.**", "123", skype="testuser_user") self.test_teacher_user.first_name = "Test" self.test_teacher_user.last_name = "Testov" self.test_teacher_user.is_staff = True self.test_teacher_user.groups.add(self.teacher_group) self.test_teacher_user.save() InterviewerFreeTime.objects.create(teacher=self.test_teacher_user, date=str(self.tomorrow), start_time="15:00", end_time="17:00") interview_length = 30 break_between_interviews = 10 interview_slots_generator = GenerateInterviewSlots( interview_length, break_between_interviews) # For a total duration of 2 hours and interview_length + break = 40 minutes # a total of three interview slots should be generated interview_slots_generator.generate_interview_slots() client = Client() client.login(email=self.test_teacher_user.email, password='******') url = reverse('admin:course_interviews_interviewslot_changelist') response = client.get(url, follow=True) result_list = response.context_data['cl'].result_list # The new teacher should see his three newly generated slots self.assertEqual(len(result_list), 3)
def test_generated_interviews_proper_length(self): self.test_teacher_user = Teacher.objects.create_user( "*****@*****.**", "123", skype="testuser_user") self.test_teacher_user.first_name = "Test" self.test_teacher_user.last_name = "Testov" self.test_teacher_user.is_staff = True self.test_teacher_user.groups.add(self.teacher_group) self.test_teacher_user.save() interview_length = 20 break_between_interviews = 10 interview_slots_generator = GenerateInterviewSlots( interview_length, break_between_interviews) time_slot1 = InterviewerFreeTime.objects.create( teacher=self.test_teacher_user, date=str(self.tomorrow), start_time="15:00", end_time="15:15") # Not enough time for an interview, no slots should be generated interview_slots_generator.generate_interview_slots() slots = InterviewSlot.objects.all().filter(teacher_time_slot=time_slot1).count() self.assertEqual(slots, 0) time_slot2 = InterviewerFreeTime.objects.create( teacher=self.test_teacher_user, date=str(self.tomorrow), start_time="15:00", end_time="15:20") # Generate one interview slot interview_slots_generator.generate_interview_slots() slots = InterviewSlot.objects.all().filter(teacher_time_slot=time_slot2).count() self.assertEqual(slots, 1) time_slot3 = InterviewerFreeTime.objects.create( teacher=self.test_teacher_user, date=str(self.tomorrow), start_time="15:00", end_time="17:00") # Generate 4 more interview slots interview_slots_generator.generate_interview_slots() slots = InterviewSlot.objects.all().filter(teacher_time_slot=time_slot3).count() self.assertEqual(slots, 4)