Exemplo n.º 1
0
    def test_add_new_reception(self):
        """Тест создания карточки приема с валидными данными."""
        self.browser.get('{0}/{1}'.format(self.live_server_url,
                                          'reception/new'))

        doctor_field = Select(self.browser.find_element_by_id('id_doctor'))
        date_field = self.browser.find_element_by_id('id_date')
        time_field = Select(self.browser.find_element_by_id('id_time'))
        fio_field = self.browser.find_element_by_id('id_fio')
        submit_button = self.browser.find_element_by_tag_name('button')

        doctor = Doctor.objects.get(surname='Александров')
        monday = get_next_weekday(datetime.date.today(), 0)
        time = Reception.TIME_CHOICES[0][0]  # 09:00
        fio = 'Петров Илья Евгеньевич'

        # Заполняем форму
        doctor_field.select_by_visible_text('Александров Иван Петрович')
        date_field.send_keys(monday.strftime('%d.%m.%Y'))
        time_field.select_by_visible_text('09:00')
        fio_field.send_keys(fio)
        # и отправляем
        submit_button.click()

        self.assertEqual(self.browser.title,
                         'Карточка на прием успешно создана')

        reception, created = Reception.objects.get_or_create(doctor=doctor,
                                                             date=monday,
                                                             time=time,
                                                             fio=fio)

        self.assertEquals(created, False)
Exemplo n.º 2
0
    def test_add_new_reception_day_off(self):
        """Тест создания карточки приема в выходной день."""
        self.browser.get('{0}/{1}'.format(self.live_server_url,
                                          'reception/new'))

        doctor_field = Select(self.browser.find_element_by_id('id_doctor'))
        date_field = self.browser.find_element_by_id('id_date')
        time_field = Select(self.browser.find_element_by_id('id_time'))
        fio_field = self.browser.find_element_by_id('id_fio')
        submit_button = self.browser.find_element_by_tag_name('button')

        doctor = Doctor.objects.get(surname='Александров')
        saturday = get_next_weekday(datetime.date.today(), 5)
        time = Reception.TIME_CHOICES[0][0]  # 09:00
        fio = 'Петров Илья Евгеньевич'

        # Заполняем форму
        doctor_field.select_by_visible_text('Александров Иван Петрович')
        date_field.send_keys(saturday.strftime('%d.%m.%Y'))
        time_field.select_by_visible_text('09:00')
        fio_field.send_keys(fio)
        # и отправляем
        submit_button.click()

        alert_div = self.browser.find_element_by_class_name('alert')
        self.assertEqual(
            alert_div.text, '×\nВыбранная дата - {0}, является выходным днем.'
            ''.format(saturday))

        with self.assertRaises(Reception.DoesNotExist):
            Reception.objects.get(doctor=doctor,
                                  date=saturday,
                                  time=time,
                                  fio=fio)
Exemplo n.º 3
0
    def test_add_new_reception_in_time_off(self):
        """Тест создания карточки приема в не рабочее время."""
        self.browser.get('{0}/{1}'.format(self.live_server_url,
                                          'reception/new'))

        doctor_field = Select(self.browser.find_element_by_id('id_doctor'))
        date_field = self.browser.find_element_by_id('id_date')
        time_field = Select(self.browser.find_element_by_id('id_time'))
        fio_field = self.browser.find_element_by_id('id_fio')
        submit_button = self.browser.find_element_by_tag_name('button')

        doctor = Doctor.objects.get(surname='Александров')
        tuesday = get_next_weekday(datetime.date.today(), 1)  # Вторник
        time = 999  # Не рабочее время
        fio = 'Петров Илья Евгеньевич'

        # Заполняем форму
        doctor_field.select_by_visible_text('Александров Иван Петрович')
        date_field.send_keys(tuesday.strftime('%d.%m.%Y'))
        time_field.select_by_visible_text('09:00')
        fio_field.send_keys(fio)
        # и отправляем
        submit_button.click()

        with self.assertRaises(Reception.DoesNotExist):
            Reception.objects.get(doctor=doctor,
                                  date=tuesday,
                                  time=time,
                                  fio=fio)
Exemplo n.º 4
0
    def test_create_reception_in_time_off(self):
        """Тест создания карточки приема в не рабочее время."""
        doctor = Doctor.objects.get(surname='Александров')
        tuesday = get_next_weekday(datetime.date.today(), 1)  # Вторник
        time = 999  # Не рабочее время
        patient = 'Иванов Иван Иванович'

        with self.assertRaises(ValidationError):
            reception = Reception(doctor=doctor,
                                  date=tuesday,
                                  time=time,
                                  fio=patient)
            reception.full_clean()
Exemplo n.º 5
0
    def test_create_reception_in_day_off(self):
        """Тест создания карточки приема в выходной день."""
        doctor = Doctor.objects.get(surname='Александров')
        saturday = get_next_weekday(datetime.date.today(), 5)
        time = Reception.TIME_CHOICES[0][0]  # 9:00
        patient = 'Иванов Иван Иванович'

        with self.assertRaises(ValidationError):
            reception = Reception(doctor=doctor,
                                  date=saturday,
                                  time=time,
                                  fio=patient)
            reception.full_clean()
Exemplo n.º 6
0
    def test_create_reception(self):
        """Тест создания карточки приема с валидными данными."""
        doctor = Doctor.objects.get(surname='Александров')
        monday = get_next_weekday(datetime.date.today(), 0)
        time = Reception.TIME_CHOICES[0][0]  # 9:00
        patient = 'Иванов Иван Иванович'

        reception = Reception.objects.create(doctor=doctor,
                                             date=monday,
                                             time=time,
                                             fio=patient)

        self.assertEqual(reception.fio, patient)
        self.assertEqual(reception.verbose_time, '09:00')
Exemplo n.º 7
0
    def test_doctor_free_time_busy(self):
        """Тест представления получения свободного времени приема врача.
        
        По условию в понедельник у врача заняты часы приема с 9:00 до 13:00.
        """
        doctor = Doctor.objects.get(surname='Александров')
        monday = get_next_weekday(datetime.date.today(), 0)
        busy_times = (
            Reception.TIME_CHOICES[0][0],  # 9:00
            Reception.TIME_CHOICES[1][0],  # 10:00
            Reception.TIME_CHOICES[2][0],  # 11:00
            Reception.TIME_CHOICES[3][0],  # 12:00
        )
        ivanov_ii = 'Иванов Иван Иванович'

        # Создаем расписание врача Александрова И.П на понедельник,
        # занятое с 9:00 до 13:00
        for time in busy_times:
            Reception.objects.create(doctor=doctor,
                                     date=monday,
                                     time=time,
                                     fio=ivanov_ii)

        # Отправляем запрос для получения свободного времени приема врача
        response = self.client.get('/reception/get-free-time-choices/', {
            'doctor_id': doctor.id,
            'date': monday.strftime('%d.%m.%Y')
        })

        self.assertEqual(response.status_code, 200)

        content = json.loads(response.content.decode('utf-8'))

        self.assertEqual(
            response.content,
            b'{"free_time": [[4, "13:00"], [5, "14:00"], [6, "15:00"], '
            b'[7, "16:00"], [8, "17:00"]]}')

        self.assertEqual(content['free_time'][0][0],
                         Reception.TIME_CHOICES[4][0])  # 13:00
        self.assertEqual(content['free_time'][1][0],
                         Reception.TIME_CHOICES[5][0])  # 14:00
        self.assertEqual(content['free_time'][2][0],
                         Reception.TIME_CHOICES[6][0])  # 15:00
        self.assertEqual(content['free_time'][3][0],
                         Reception.TIME_CHOICES[7][0])  # 16:00
        self.assertEqual(content['free_time'][4][0],
                         Reception.TIME_CHOICES[8][0])  # 17:00
Exemplo n.º 8
0
    def test_add_new_reception_in_busy_time(self):
        """Тест создания карточки приема к врачу в занятое время."""
        self.browser.get('{0}/{1}'.format(self.live_server_url,
                                          'reception/new'))

        doctor_field = Select(self.browser.find_element_by_id('id_doctor'))
        date_field = self.browser.find_element_by_id('id_date')
        time_field = Select(self.browser.find_element_by_id('id_time'))
        fio_field = self.browser.find_element_by_id('id_fio')
        submit_button = self.browser.find_element_by_tag_name('button')

        doctor = Doctor.objects.get(surname='Александров')
        monday = get_next_weekday(datetime.date.today(), 0)
        time = Reception.TIME_CHOICES[0][0]  # 9:00
        ivanov_ii = 'Иванов Иван Иванович'
        petrov_ad = 'Петров Александр Дмитриевич'

        # Карточка приема пациента Иванова И.И. на понедельник
        # к врачу Александрову И.П. на 9:00
        Reception.objects.create(doctor=doctor,
                                 date=monday,
                                 time=time,
                                 fio=ivanov_ii)

        # Заполняем форму
        doctor_field.select_by_visible_text('Александров Иван Петрович')
        date_field.send_keys(monday.strftime('%d.%m.%Y'))
        time_field.select_by_visible_text('09:00')
        fio_field.send_keys(petrov_ad)
        # и отправляем
        submit_button.click()

        alert_div = self.browser.find_element_by_class_name('alert')
        self.assertEqual(
            alert_div.text, '×\nКарточка приема с такими значениями полей '
            'К врачу, Дата и Время уже существует.')

        with self.assertRaises(Reception.DoesNotExist):
            Reception.objects.get(doctor=doctor,
                                  date=monday,
                                  time=time,
                                  fio=petrov_ad)
Exemplo n.º 9
0
    def test_doctor_free_time(self):
        """Тест представления получения свободного времени приема врача.

        По условию во вторник у врача не заняты часы приема.
        """
        doctor = Doctor.objects.get(surname='Александров')
        tuesday = get_next_weekday(datetime.date.today(), 1)  # Вторник

        # Отправляем запрос для получения свободного времени приема врача
        response = self.client.get('/reception/get-free-time-choices/', {
            'doctor_id': doctor.id,
            'date': tuesday.strftime('%d.%m.%Y')
        })

        self.assertEqual(response.status_code, 200)

        content = json.loads(response.content.decode('utf-8'))

        self.assertEqual(
            response.content,
            b'{"free_time": [[0, "09:00"], [1, "10:00"], [2, "11:00"], '
            b'[3, "12:00"], [4, "13:00"], [5, "14:00"], [6, "15:00"], '
            b'[7, "16:00"], [8, "17:00"]]}')

        self.assertEqual(content['free_time'][0][0],
                         Reception.TIME_CHOICES[0][0])  # 09:00
        self.assertEqual(content['free_time'][1][0],
                         Reception.TIME_CHOICES[1][0])  # 10:00
        self.assertEqual(content['free_time'][2][0],
                         Reception.TIME_CHOICES[2][0])  # 11:00
        self.assertEqual(content['free_time'][3][0],
                         Reception.TIME_CHOICES[3][0])  # 12:00
        self.assertEqual(content['free_time'][4][0],
                         Reception.TIME_CHOICES[4][0])  # 13:00
        self.assertEqual(content['free_time'][5][0],
                         Reception.TIME_CHOICES[5][0])  # 14:00
        self.assertEqual(content['free_time'][6][0],
                         Reception.TIME_CHOICES[6][0])  # 15:00
        self.assertEqual(content['free_time'][7][0],
                         Reception.TIME_CHOICES[7][0])  # 16:00
        self.assertEqual(content['free_time'][8][0],
                         Reception.TIME_CHOICES[8][0])  # 17:00
Exemplo n.º 10
0
    def test_doctor_all_busy_time(self):
        """Тест представления получения свободного времени приема врача.

        По условию во вторник у врача заняты все часы приема.
        """
        doctor = Doctor.objects.get(surname='Александров')
        tuesday = get_next_weekday(datetime.date.today(), 1)  # Вторник
        busy_times = (
            Reception.TIME_CHOICES[0][0],  # 9:00
            Reception.TIME_CHOICES[1][0],  # 10:00
            Reception.TIME_CHOICES[2][0],  # 11:00
            Reception.TIME_CHOICES[3][0],  # 12:00
            Reception.TIME_CHOICES[4][0],  # 13:00
            Reception.TIME_CHOICES[5][0],  # 14:00
            Reception.TIME_CHOICES[6][0],  # 15:00
            Reception.TIME_CHOICES[7][0],  # 16:00
            Reception.TIME_CHOICES[8][0],  # 17:00
        )
        ivanov_ii = 'Иванов Иван Иванович'

        # Создаем расписание врача Александрова И.П на вторник,
        # все часы приема заняты.
        for time in busy_times:
            Reception.objects.create(doctor=doctor,
                                     date=tuesday,
                                     time=time,
                                     fio=ivanov_ii)

        # Отправляем запрос для получения свободного времени приема врача
        response = self.client.get('/reception/get-free-time-choices/', {
            'doctor_id': doctor.id,
            'date': tuesday.strftime('%d.%m.%Y')
        })

        self.assertEqual(response.status_code, 200)

        content = json.loads(response.content.decode('utf-8'))

        self.assertEqual(response.content, b'{"free_time": []}')

        self.assertEqual(content['free_time'], [])  # Не свободных часов
Exemplo n.º 11
0
    def test_create_reception_in_busy_time(self):
        """Тест создания карточки приема к врачу в занятое время."""
        doctor = Doctor.objects.get(surname='Александров')
        monday = get_next_weekday(datetime.date.today(), 0)
        time = Reception.TIME_CHOICES[0][0]  # 9:00
        ivanov_ii = 'Иванов Иван Иванович'
        petrov_ad = 'Петров Александр Дмитриевич'

        # Карточка приема пациента Иванова И.И. на понедельник
        # к врачу Александрову И.П. на 9:00
        Reception.objects.create(doctor=doctor,
                                 date=monday,
                                 time=time,
                                 fio=ivanov_ii)

        with self.assertRaises(ValidationError):
            reception = Reception(doctor=doctor,
                                  date=monday,
                                  time=time,
                                  fio=petrov_ad)
            reception.full_clean()