def test_free_slots_for_lesson(self): """ Test for getting free time slots for a particular teacher with particular lesson """ other_teacher = create_teacher() master_class = mixer.blend(lessons.MasterClass, host=self.teacher) other_master_class = mixer.blend(lessons.MasterClass, host=other_teacher) entry = TimelineEntry(teacher=self.teacher, lesson=master_class, start=self.tzdatetime(2032, 5, 3, 14, 10), end=self.tzdatetime(2032, 5, 3, 14, 40)) entry.save() other_entry = TimelineEntry(teacher=other_teacher, lesson=other_master_class, start=self.tzdatetime(2032, 5, 3, 14, 10), end=self.tzdatetime(2032, 5, 3, 14, 40)) other_entry.save() slots = self.teacher.find_free_slots(self.tzdatetime(2032, 5, 3), lesson_id=master_class.pk) self.assertEquals(len(slots), 1) slots = self.teacher.find_free_slots(self.tzdatetime(2032, 5, 3), lesson_id=other_master_class.pk) self.assertEquals(len(slots), 0)
def test_get_teachers_by_lesson(self): """ Find teachers for a particular lesson """ first_master_class = mixer.blend(lessons.MasterClass, host=self.teacher) first_entry = TimelineEntry(teacher=self.teacher, lesson=first_master_class, start=self.tzdatetime(2032, 5, 3, 14, 10), end=self.tzdatetime(2032, 5, 3, 14, 40)) first_entry.save() free_teachers = list( Teacher.objects.find_free(date=self.tzdatetime(2032, 5, 3), lesson_id=first_master_class.pk)) self.assertEquals(len(free_teachers), 1)
def test_free_slots_for_lesson_type_validates_with_auto_schedule(self): master_class = mixer.blend(lessons.MasterClass, host=self.teacher) entry = TimelineEntry(teacher=self.teacher, lesson=master_class, start=self.tzdatetime(2032, 5, 3, 14, 10), end=self.tzdatetime(2032, 5, 3, 14, 40)) entry.save() lesson_type = ContentType.objects.get_for_model(master_class) with patch('timeline.models.Entry.clean') as clean: clean.side_effect = AutoScheduleExpcetion(message='testing') slots = self.teacher.find_free_slots(date=self.tzdatetime( 2032, 5, 3), lesson_type=lesson_type.pk) self.assertEqual(len(slots), 0)
class TestCheckEntry(ClientTestCase): """ :view:`timeline.check_entry` is a helper for the timeline creating form which checks entry validity — working hours and overlaping """ def setUp(self): self.teacher = create_teacher() self.lesson = mixer.blend(lessons.MasterClass, host=self.teacher) self.entry = TimelineEntry( teacher=self.teacher, lesson=self.lesson, start=self.tzdatetime('Europe/Moscow', 2016, 1, 18, 14, 10), end=self.tzdatetime('Europe/Moscow', 2016, 1, 18, 14, 40), ) self.entry.save() mixer.blend(WorkingHours, teacher=self.teacher, weekday=0, start='13:00', end='15:00') self.absence = Absence( type='vacation', teacher=self.teacher, start=self.tzdatetime(2032, 5, 3, 0, 0), end=self.tzdatetime(2032, 5, 3, 23, 59), ) self.absence.save() def test_check_overlap_true(self): res = self.__check_entry( start='2016-01-18 14:30', end='2016-01-18 15:00', ) self.assertEqual(res, 'TeacherHasOtherLessons') def test_teacher_is_present_false(self): res = self.__check_entry( start='2032-05-03 14:00', # this day teacher is on vacation end='2032-05-03 14:30', ) self.assertEqual(res, 'TeacherIsAbsent') def __check_entry(self, start, end): response = self.c.get( '/timeline/%s/check_entry/%s/%s/' % (self.teacher.user.username, start, end) ) self.assertEqual(response.status_code, 200) result = json.loads(response.content.decode('utf-8')) return result['result']
def test_two_teachers_for_single_slot(self): """ Check if find_free_slots returns only slots of selected teacher """ other_teacher = create_teacher() master_class = mixer.blend(lessons.MasterClass, host=other_teacher) entry = TimelineEntry(teacher=other_teacher, lesson=master_class, start=self.tzdatetime(2032, 5, 3, 14, 10), end=self.tzdatetime(2032, 5, 3, 14, 40)) entry.save() lesson_type = ContentType.objects.get_for_model(master_class) slots = self.teacher.find_free_slots(date=self.tzdatetime(2032, 5, 3), lesson_type=lesson_type.pk) self.assertEquals( len(slots), 0 ) # should not return anything — we are checking slots for self.teacher, not other_teacher
def test_filter_by_lesson_type(self): first_master_class = mixer.blend(lessons.MasterClass, host=self.first_teacher) second_master_class = mixer.blend(lessons.MasterClass, host=self.second_teacher) entry = TimelineEntry( teacher=self.first_teacher, lesson=first_master_class, start=datetime(2032, 5, 6, 14, 10), end=datetime(2032, 5, 6, 14, 40), ) entry.save() entry = TimelineEntry( teacher=self.second_teacher, lesson=second_master_class, start=datetime(2032, 5, 6, 14, 15), end=datetime(2032, 5, 6, 14, 45), ) entry.save() master_class_type = ContentType.objects.get_for_model( first_master_class) response = self.c.get('/market/2032-05-06/type/%d/lessons.json' % master_class_type.pk) self.assertEquals(response.status_code, 200) records = json.loads(response.content.decode('utf-8')) self.assertEquals(len(records), 2) self.assertEquals(len(records[0]['slots']), 1) self.assertIsTime( records[0]['slots'][0]['server'] ) # assert that returned slots carry some time (we dont care about timezones here) self.assertIsTime(records[1]['slots'][0]['server']) self.assertEquals(records[0]['name'], first_master_class.name) self.assertEquals(records[1]['name'], second_master_class.name) self.assertEquals(records[0]['host'], self.first_teacher.user.crm.full_name) self.assertEquals(records[1]['host'], self.second_teacher.user.crm.full_name)
def test_free_slots_for_lesson_type(self): """ Test for getting free time slots for a certain lesson type. """ master_class = mixer.blend(lessons.MasterClass, host=self.teacher) entry = TimelineEntry(teacher=self.teacher, lesson=master_class, start=self.tzdatetime(2032, 5, 3, 14, 10), end=self.tzdatetime(2032, 5, 3, 14, 40)) entry.save() lesson_type = ContentType.objects.get_for_model(master_class) slots = self.teacher.find_free_slots(date=self.tzdatetime(2032, 5, 3), lesson_type=lesson_type.pk) self.assertEquals(len(slots), 1) slots = self.teacher.find_free_slots(date=self.tzdatetime(2032, 5, 5), lesson_type=lesson_type.pk) self.assertEquals( len(slots), 0) # there is no master classes, planned on 2032-05-05
def test_schedule_existsing_entry(self): """ Create a timeline entry, that class.__get_entry should return instead of creating a new one """ lesson = products.OrdinaryLesson.get_default() c = self._buy_a_lesson(lesson) date = self.tzdatetime(2016, 8, 17, 10, 1) entry = TimelineEntry( teacher=self.host, start=date, lesson=lesson ) entry.save() c.schedule( teacher=self.host, date=self.tzdatetime(2016, 8, 17, 10, 1), allow_besides_working_hours=True, ) c.save() self.assertEquals(c.timeline, entry)