def test_em_pausa_apos_atendendo(self): posto1 = h.get_or_create_posto(['l1', 'f1', 'p1']) funcionario1 = h.get_or_create_funcionario_posto('f1') cliente1 = h.get_or_create_cliente('c1') wsp1 = WSPosto(funcionario1) wsf1 = WSFila(cliente1) turno1 = wsf1.entrar_na_fila(posto1.fila) wsp1.ocupar_posto(posto1) wsp1.chamar_seguinte() posto1.refresh_from_db() wsp1.atender() wsp1.finalizar_atencao() posto1.refresh_from_db() self.assertEqual(posto1.estado, Posto.EM_PAUSA) self.assertEqual(posto1.funcionario.pk, funcionario1.pk) self.assertEqual(posto1.turno_em_atencao, None)
def test_media_tempo_espera_qtd_minima_turnos(self): posto1 = h.get_or_create_posto(['l1', 'f1', 'p1']) cliente1 = h.get_or_create_cliente('c1') # (inicio atendimento, tempo atendimento): Simulamos 2 postos de atendimento esperas = [(0, 355), (15, 299), (356, 344), (314, 600), (700, 245), (914, 33)] media = sum(map(lambda x: x[1], esperas)) / len(esperas) inicio_atendimento = TZ.now() fim_atendimento = inicio_atendimento + TD(seconds=950) for espera in esperas: t1 = cliente1.entrar_na_fila(posto1.fila.id, test_mode=True) t1.estado = Turno.ATENDIDO t1.inicio_espera_date = inicio_atendimento + TD(seconds=espera[0]) t1.fim_espera_date = t1.inicio_espera_date + TD(seconds=espera[1]) t1.save() t1.fila.refresh_from_db() t1.fila.media_espera = 500 t1.fila.save() t1.fila.refresh_from_db() with self.assertRaises(SemQtdMinTurnosParaCalcularMediaEspera): t1.fila.calcular_media_espera(dt_from=inicio_atendimento, dt_to=fim_atendimento, qtd_min_turnos=7) t1.refresh_from_db() self.assertEqual(t1.fila.media_espera, 500)
def test_entrar_na_fila(self): cliente1 = h.get_or_create_cliente('c1') scann1 = h.get_or_create_funcionario_scanner('s1') h.get_or_create_posto(['l1', 'f1', 'p1']) local1 = h.get_or_create_posto(['l1', 'f2', 'p2']).fila.local wsf1 = WSFila(cliente1) qrcode = wsf1.receive()['data']['qrcode'] wss1 = WSScanner(scann1) wss1.scan(qrcode, local1) filas = [model_to_dict(f) for f in local1.filas.all()] data = wsf1.receive()['data'] fila = Fila.objects.get(pk=data['filas'][0]['id']) turno = wsf1.entrar_na_fila(fila, data['qrcode']) self.assertEqual(wsf1.receive(), { "message": "TURNO_ATIVO", "data": { 'turno': turno.to_dict() } })
def test_indicar_ausencia(self): posto1 = h.get_or_create_posto(['l1', 'f1', 'p1']) funcionario1 = h.get_or_create_funcionario_posto('f1') cliente1 = h.get_or_create_cliente('c1') wsf1 = WSFila(cliente1) turno1 = wsf1.entrar_na_fila(posto1.fila) wsp1 = WSPosto(funcionario1) wsp1.receive() wsp1.ocupar_posto(posto1) wsp1.receive() wsp1.chamar_seguinte() wsp1.receive() wsp1.receive() wsp1.indicar_ausencia() posto1.refresh_from_db() self.assertEqual(wsp1.receive(), { "message": "POSTO", "data": { 'posto': posto1.to_dict() } }) self.assertIsNone(wsp1.receive())
def test_fim_espera_date_null(self): posto1 = h.get_or_create_posto(['l1', 'f1', 'p1']) cliente1 = h.get_or_create_cliente('c1') t1 = cliente1.entrar_na_fila( posto1.fila.id, h.get_or_create_qrcode(cliente1, posto1.fila).qrcode) self.assertIsNone(t1.fim_espera_date)
def test_na_fila(self): posto1 = h.get_or_create_posto(['l1', 'f1', 'p1']) cliente1 = h.get_or_create_cliente('c1') wsf1 = WSFila(cliente1) turno1 = wsf1.entrar_na_fila(posto1.fila) turno1.refresh_from_db() self.assertEqual(turno1.estado, Turno.NA_FILA)
def test_estima_espera_multiples_clientes_um_posto(self): posto1 = h.get_or_create_posto(['l1', 'f1', 'p1']) cliente1 = h.get_or_create_cliente('c1') cliente2 = h.get_or_create_cliente('c2') cliente3 = h.get_or_create_cliente('c3') funcionario1 = h.get_or_create_funcionario_posto('f1') funcionario1.ocupar_posto(posto1) posto1.fila.media_espera = 11 posto1.fila.save() t1 = cliente1.entrar_na_fila(posto1.fila.pk, test_mode=True) t2 = cliente2.entrar_na_fila(posto1.fila.pk, test_mode=True) t3 = cliente3.entrar_na_fila(posto1.fila.pk, test_mode=True) self.assertEqual(t1.estimar_tempo_espera(), 11) self.assertEqual(t2.estimar_tempo_espera(), 22) self.assertEqual(t3.estimar_tempo_espera(), 33)
def test_estima_espera_um_cliente_sem_posto_ativo(self): posto1 = h.get_or_create_posto(['l1', 'f1', 'p1']) cliente1 = h.get_or_create_cliente('c1') posto1.fila.media_espera = 11 posto1.fila.save() t1 = cliente1.entrar_na_fila(posto1.fila.pk, test_mode=True) self.assertEqual(t1.estimar_tempo_espera(), 11)
def test_get_codigo_qr(self): cliente1 = h.get_or_create_cliente('c1') wsf1 = WSFila(cliente1) qrcode = QRCode.objects.get(user=cliente1) self.assertEqual(wsf1.receive(), { "message": "QR_CODE", "data": { "qrcode": qrcode.qrcode } })
def test_cancelado(self): posto1 = h.get_or_create_posto(['l1', 'f1', 'p1']) cliente1 = h.get_or_create_cliente('c1') wsf1 = WSFila(cliente1) turno1 = wsf1.entrar_na_fila(posto1.fila) wsf1.sair_da_fila(turno1) turno1.refresh_from_db() self.assertEqual(turno1.estado, Turno.CANCELADO)
def test_turno_finalizado_registrado_ausente(self): posto1 = h.get_or_create_posto(['l1', 'f1', 'p1']) cliente1 = h.get_or_create_cliente('c1') t1 = cliente1.entrar_na_fila( posto1.fila.id, h.get_or_create_qrcode(cliente1, posto1.fila).qrcode) t1.estado = Turno.AUSENTE ini_save = TZ.now() t1.save() end_save = TZ.now() self.assertGreaterEqual(t1.fim_espera_date, ini_save) self.assertLessEqual(t1.fim_espera_date, end_save)
def test_inicio_espera_date_registrado(self): posto1 = h.get_or_create_posto(['l1', 'f1', 'p1']) cliente1 = h.get_or_create_cliente('c1') t1 = cliente1.entrar_na_fila( posto1.fila.id, h.get_or_create_qrcode(cliente1, posto1.fila).qrcode) t1.estado = Turno.CLIENTE_CHAMADO ini_save = TZ.now() t1.save() end_save = TZ.now() self.assertGreaterEqual(t1.inicio_espera_date, ini_save) self.assertLessEqual(t1.inicio_espera_date, end_save)
def test_cliente_chamado(self): posto1 = h.get_or_create_posto(['l1', 'f1', 'p1']) funcionario1 = h.get_or_create_funcionario_posto('f1') cliente1 = h.get_or_create_cliente('c1') wsp1 = WSPosto(funcionario1) wsf1 = WSFila(cliente1) wsp1.ocupar_posto(posto1) wsp1.chamar_seguinte() turno1 = wsf1.entrar_na_fila(posto1.fila) turno1.refresh_from_db() self.assertEqual(turno1.estado, Turno.CLIENTE_CHAMADO)
def test_media_tempo_espera_um_turno(self): posto1 = h.get_or_create_posto(['l1', 'f1', 'p1']) cliente1 = h.get_or_create_cliente('c1') t1 = cliente1.entrar_na_fila(posto1.fila.id, test_mode=True) t1.estado = Turno.ATENDIDO t1.inicio_espera_date = TZ.now() t1.fim_espera_date = t1.inicio_espera_date + TD(seconds=355) t1.save() t1.fila.refresh_from_db() t1.fila.calcular_media_espera(dt_from=t1.inicio_espera_date, dt_to=t1.fim_espera_date) self.assertEqual(t1.fila.media_espera, 355)
def test_no_atendimento(self): posto1 = h.get_or_create_posto(['l1', 'f1', 'p1']) funcionario1 = h.get_or_create_funcionario_posto('f1') cliente1 = h.get_or_create_cliente('c1') wsp1 = WSPosto(funcionario1) wsf1 = WSFila(cliente1) wsp1.ocupar_posto(posto1) wsp1.chamar_seguinte() turno1 = wsf1.entrar_na_fila(posto1.fila) wsp1.atender() turno1.refresh_from_db() self.assertEqual(turno1.estado, Turno.NO_ATENDIMENTO)
def test_cliente_chamado_apos_espera_cliente(self): posto1 = h.get_or_create_posto(['l1', 'f1', 'p1']) funcionario1 = h.get_or_create_funcionario_posto('f1') cliente1 = h.get_or_create_cliente('c1') wsp1 = WSPosto(funcionario1) wsf1 = WSFila(cliente1) wsp1.ocupar_posto(posto1) wsp1.chamar_seguinte() posto1.refresh_from_db() self.assertEqual(posto1.estado, Posto.ESPERANDO_CLIENTE) turno1 = wsf1.entrar_na_fila(posto1.fila) posto1.refresh_from_db() self.assertEqual(posto1.estado, Posto.CLIENTE_CHAMADO) self.assertEqual(posto1.turno_em_atencao.pk, turno1.pk)
def test_scann_e_enviar_filas(self): cliente1 = h.get_or_create_cliente('c1') scann1 = h.get_or_create_funcionario_scanner('s1') h.get_or_create_posto(['l1', 'f1', 'p1']) local1 = h.get_or_create_posto(['l1', 'f2', 'p2']).fila.local wsf1 = WSFila(cliente1) qrcode = wsf1.receive()['data']['qrcode'] wss1 = WSScanner(scann1) wss1.scan(qrcode, local1) QRCode.objects.get(user=cliente1, qrcode=qrcode, local=local1) filas = [model_to_dict(f) for f in local1.filas.all()] self.assertEqual( wsf1.receive(), { "message": "FILAS_DISPONIBLES", "data": { "qrcode": qrcode, 'filas': filas } })