def test_datos_reporte_agente_actividad_dia_incompleta_coincide_estadisticas_sistema( self): # si el agente comenzó sesión y pausa en el día actual y terminó en el siguiente # se testea que se sume el tiempo de los eventos desde que inician hasta el final del día # actual en el reporte DURACION_INICIO_SESION_A_INICIO_PAUSA = 600 final_dia = timezone.now().replace(hour=23, minute=59, second=59, microsecond=999999) tiempo_agente_login = timezone.now() tiempo_agente_inicio_pausa = tiempo_agente_login + timedelta( microseconds=DURACION_INICIO_SESION_A_INICIO_PAUSA) tiempo_pausa = final_dia - tiempo_agente_inicio_pausa tiempo_sesion = final_dia - tiempo_agente_login ActividadAgenteLogFactory(agente_id=self.agente_profile.pk, time=tiempo_agente_login, event='ADDMEMBER') ActividadAgenteLogFactory(agente_id=self.agente_profile.pk, time=tiempo_agente_inicio_pausa, event='PAUSEALL') url = reverse('campana_reporte_grafico_agente', args=[self.campana_activa.pk, self.agente_profile.pk]) response = self.client.get(url, follow=True) estadisticas = response.context_data['graficos_estadisticas'][ 'estadisticas'] agente_data = estadisticas['agente_tiempo'] self.assertEqual(agente_data.tiempo_sesion, tiempo_sesion) self.assertEqual(agente_data.tiempo_pausa, tiempo_pausa)
def test_datos_reporte_agente_actividad_dia_anterior_coincide_estadisticas_sistema( self): # si el agente comenzó sesión y pausa el día anterior y terminó en el actual # se testea que se sume el tiempo de los eventos desde que inicia el día actual en el # reporte DURACION_FIN_PAUSA_A_FIN_SESION = 600 inicio_dia = timezone.now().replace(hour=0, minute=0, second=0, microsecond=0) tiempo_agente_final_pausa = timezone.now() tiempo_agente_logout = tiempo_agente_final_pausa + timedelta( microseconds=DURACION_FIN_PAUSA_A_FIN_SESION) tiempo_pausa = tiempo_agente_final_pausa - inicio_dia tiempo_sesion = tiempo_agente_logout - inicio_dia ActividadAgenteLogFactory(agente_id=self.agente_profile.pk, time=tiempo_agente_final_pausa, event='UNPAUSEALL') ActividadAgenteLogFactory(agente_id=self.agente_profile.pk, time=tiempo_agente_logout, event='REMOVEMEMBER') url = reverse('campana_reporte_grafico_agente', args=[self.campana_activa.pk, self.agente_profile.pk]) response = self.client.get(url, follow=True) estadisticas = response.context_data['graficos_estadisticas'][ 'estadisticas'] agente_data = estadisticas['agente_tiempo'] self.assertEqual(agente_data.tiempo_sesion, tiempo_sesion) self.assertEqual(agente_data.tiempo_pausa, tiempo_pausa)
def test_datos_reporte_agente_detalle_actividad_coinciden_estadisticas_sistema( self): DURACION_AGENTE_SESION = 3600 TIEMPO_AGENTE_ANTES_PAUSA = 120 DURACION_AGENTE_PAUSA = 100 tiempo_agente_login = timezone.now() tiempo_agente_inicio_pausa = tiempo_agente_login + timedelta( microseconds=TIEMPO_AGENTE_ANTES_PAUSA) tiempo_agente_final_pausa = tiempo_agente_inicio_pausa + timedelta( microseconds=DURACION_AGENTE_PAUSA) tiempo_agente_logout = tiempo_agente_login + timedelta( microseconds=DURACION_AGENTE_SESION) ActividadAgenteLogFactory(agente_id=self.agente_profile.pk, time=tiempo_agente_login, event='ADDMEMBER') ActividadAgenteLogFactory(agente_id=self.agente_profile.pk, time=tiempo_agente_inicio_pausa, event='PAUSEALL') ActividadAgenteLogFactory(agente_id=self.agente_profile.pk, time=tiempo_agente_final_pausa, event='UNPAUSEALL') ActividadAgenteLogFactory(agente_id=self.agente_profile.pk, time=tiempo_agente_logout, event='REMOVEMEMBER') url = reverse('campana_reporte_grafico_agente', args=[self.campana_activa.pk, self.agente_profile.pk]) response = self.client.get(url, follow=True) estadisticas = response.context_data['graficos_estadisticas'][ 'estadisticas'] agente_data = estadisticas['agente_tiempo'] self.assertEqual(agente_data.tiempo_sesion.microseconds, DURACION_AGENTE_SESION) self.assertEqual(agente_data.tiempo_pausa.microseconds, DURACION_AGENTE_PAUSA)
def test_se_muestra_el_tiempo_de_sesion_correctamente(self): horas_sesion = 1 tiempo_inicial = now() ActividadAgenteLogFactory.create(event='UNPAUSEALL', agente_id=self.agente_profile.id, time=tiempo_inicial) tiempo_removemember_1 = tiempo_inicial + timedelta(microseconds=20000) ActividadAgenteLogFactory.create(event='REMOVEMEMBER', agente_id=self.agente_profile.id, time=tiempo_removemember_1) tiempo_addmember = tiempo_removemember_1 + timedelta(microseconds=3000) ActividadAgenteLogFactory.create(time=tiempo_addmember, event='ADDMEMBER', agente_id=self.agente_profile.id, pausa_id='') tiempo_removemember_2 = tiempo_addmember + timedelta( hours=horas_sesion) ActividadAgenteLogFactory.create(time=tiempo_removemember_2, event='REMOVEMEMBER', agente_id=self.agente_profile.id, pausa_id='') reporte = ReporteEstadisticasDiariaAgente() reporte_agente = reporte.estadisticas[self.agente_profile.pk] self.assertEqual(reporte_agente['tiempos'].sesion, timedelta(hours=horas_sesion))
def test_se_muestran_los_tiempos_de_pausa_correctamente(self): horas_sesion = 1 tiempo_inicial = now() pausa1 = PausaFactory(tipo=Pausa.TIPO_PRODUCTIVA) pausa2 = PausaFactory(tipo=Pausa.TIPO_RECREATIVA) ActividadAgenteLogFactory.create(event='UNPAUSEALL', agente_id=self.agente_profile.id, time=tiempo_inicial) tiempo_removemember_1 = tiempo_inicial + timedelta(microseconds=20000) ActividadAgenteLogFactory.create(event='REMOVEMEMBER', agente_id=self.agente_profile.id, time=tiempo_removemember_1) tiempo_addmember = tiempo_removemember_1 + timedelta(microseconds=3000) ActividadAgenteLogFactory.create(time=tiempo_addmember, event='ADDMEMBER', agente_id=self.agente_profile.id, pausa_id='') tiempo_inicio_pausa_1 = tiempo_addmember + timedelta(minutes=2) ActividadAgenteLogFactory.create(time=tiempo_inicio_pausa_1, event='PAUSEALL', agente_id=self.agente_profile.id, pausa_id=pausa1.id) tiempo_final_pausa_1 = tiempo_inicio_pausa_1 + timedelta(minutes=2) ActividadAgenteLogFactory.create(time=tiempo_final_pausa_1, event='UNPAUSEALL', agente_id=self.agente_profile.id, pausa_id=pausa1.id) tiempo_inicio_pausa_2 = tiempo_final_pausa_1 + timedelta(minutes=2) ActividadAgenteLogFactory.create(time=tiempo_inicio_pausa_2, event='PAUSEALL', agente_id=self.agente_profile.id, pausa_id=pausa2.id) tiempo_final_pausa_2 = tiempo_inicio_pausa_2 + timedelta(minutes=2) ActividadAgenteLogFactory.create(time=tiempo_final_pausa_2, event='UNPAUSEALL', agente_id=self.agente_profile.id, pausa_id=pausa2.id) tiempo_removemember_2 = tiempo_final_pausa_2 + timedelta( hours=horas_sesion) ActividadAgenteLogFactory.create(time=tiempo_removemember_2, event='REMOVEMEMBER', agente_id=self.agente_profile.id, pausa_id='') reporte = ReporteEstadisticasDiariaAgente() reporte_agente = reporte.estadisticas[self.agente_profile.pk] self.assertEqual(reporte_agente['tiempos'].pausa, timedelta(minutes=4)) self.assertEqual(reporte_agente['tiempos'].pausa_recreativa, timedelta(minutes=2))