コード例 #1
0
def test_identificacion_problema_create_view_post_ajax(fiscal_client,
                                                       admin_user):
    a = AttachmentFactory()
    data = {
        'status': 'problema',
        'tipo_de_problema': 'falta_lista',
        'descripcion': 'Un problema'
    }
    # ajax post
    url = reverse('asignar-problema', args=[a.id])
    response = fiscal_client.post(url,
                                  data,
                                  HTTP_X_REQUESTED_WITH='XMLHttpRequest')
    assert response.status_code == 200
    # hack
    assert response.json() == {'status': 'hack'}

    assert a.identificaciones.count() == 1
    i = a.identificaciones.first()
    assert i.status == 'problema'
    assert i.fiscal == admin_user.fiscal
    assert i.mesa is None
    # mesa no tiene attach aun
    a.refresh_from_db()
    assert a.identificacion_testigo is None

    # hay un problema asociado al attach con un reporte asociado
    problema = a.problemas.get()  # demuestra que es 1 solo
    assert problema.estado == 'potencial'
    reporte = problema.reportes.get()  # idem, es 1 solo
    assert reporte.tipo_de_problema == 'falta_lista'
    assert reporte.reportado_por == admin_user.fiscal
    assert reporte.descripcion == 'Un problema'
コード例 #2
0
def test_identificacion_create_view_post__desde_unidad_basica(
        fiscal_client, admin_user):
    mesa_1 = MesaFactory()
    attachment = AttachmentFactory()
    admin_user.fiscal.asignar_attachment(attachment)
    attachment.asignar_a_fiscal()
    data = {
        'mesa': mesa_1.numero,
        'circuito': mesa_1.circuito.numero,
        'seccion': mesa_1.circuito.seccion.numero,
        'distrito': mesa_1.circuito.seccion.distrito.id,
    }
    response = fiscal_client.post(
        reverse('asignar-mesa-ub', args=[attachment.id]), data)
    assert response.status_code == HTTPStatus.FOUND
    assert response.url == reverse('cargar-desde-ub',
                                   kwargs={'mesa_id': mesa_1.id})

    # Refrescamos el attachment desde la base.
    attachment.refresh_from_db()

    assert attachment.identificaciones.count() == 1
    assert attachment.status == Attachment.STATUS.identificada

    identificacion = attachment.identificaciones.first()
    assert attachment.identificacion_testigo == identificacion
    assert identificacion.status == Identificacion.STATUS.identificada
    assert identificacion.source == Identificacion.SOURCES.csv
    assert identificacion.mesa == mesa_1
    # La identificación está consolidada, por lo tanto ya existe en la mesa
    assert mesa_1.attachments.exists()
コード例 #3
0
def test_consolidador_honra_timeout(db, settings):
    settings.MIN_COINCIDENCIAS_IDENTIFICACION = 1
    a = AttachmentFactory()
    m1 = MesaFactory()
    i1 = IdentificacionFactory(
        attachment=a,
        status='identificada',
        mesa=m1,
        tomada_por_consolidador=timezone.now() -
        timedelta(minutes=settings.TIMEOUT_CONSOLIDACION - 1))
    consumir_novedades_identificacion()
    a.refresh_from_db()
    i1.refresh_from_db()
    # No la tomó aún.
    assert i1.procesada is False

    assert a.status == Attachment.STATUS.sin_identificar
    i1.tomada_por_consolidador = timezone.now() - timedelta(
        minutes=settings.TIMEOUT_CONSOLIDACION + 1)
    i1.save()
    consumir_novedades_identificacion()
    a.refresh_from_db()
    i1.refresh_from_db()

    # Ahora sí
    assert i1.procesada is True
    assert a.identificacion_testigo == i1
    assert a.mesa == m1
    assert a.status == Attachment.STATUS.identificada
コード例 #4
0
def test_identificacion_consolidada_alguna(db):
    a = AttachmentFactory()
    m1 = MesaFactory()
    i1 = IdentificacionFactory(attachment=a, status='identificada', mesa=m1)
    IdentificacionFactory(attachment=a, status='problema', mesa=None)
    i2 = IdentificacionFactory(attachment=a, status='problema', mesa=None)
    Problema.reportar_problema(FiscalFactory(),
                               'reporte 1',
                               ReporteDeProblema.TIPOS_DE_PROBLEMA.ilegible,
                               identificacion=i2)
    IdentificacionFactory(attachment=a, status='identificada', mesa=m1)

    assert a.identificacion_testigo is None

    cant_novedades = Identificacion.objects.filter(procesada=False).count()
    assert cant_novedades == 4
    consumir_novedades_identificacion()

    # No se consolidó el problema.
    assert i2.problemas.first().problema.estado == Problema.ESTADOS.potencial

    cant_novedades = Identificacion.objects.filter(procesada=False).count()
    assert cant_novedades == 0

    a.refresh_from_db()
    assert a.identificacion_testigo == i1
    assert a.mesa == m1
    assert a.status == Attachment.STATUS.identificada
コード例 #5
0
def test_identificacion_consolidada_con_minimo_1(db, settings):
    settings.MIN_COINCIDENCIAS_IDENTIFICACION = 1
    a = AttachmentFactory()
    m1 = MesaFactory()
    i1 = IdentificacionFactory(attachment=a, status='identificada', mesa=m1)
    consumir_novedades_identificacion()
    a.refresh_from_db()
    assert a.identificacion_testigo == i1
    assert a.mesa == m1
    assert a.status == Attachment.STATUS.identificada
コード例 #6
0
def test_ciclo_de_vida_problemas_resolver(db):
    a = AttachmentFactory()
    m1 = MesaFactory()
    IdentificacionFactory(attachment=a, status='identificada', mesa=m1)

    # Está pendiente.
    assert a in Attachment.objects.sin_identificar()

    i1 = IdentificacionFactory(attachment=a, status='problema', mesa=None)
    f = FiscalFactory()
    Problema.reportar_problema(f,
                               'reporte 1',
                               ReporteDeProblema.TIPOS_DE_PROBLEMA.spam,
                               identificacion=i1)
    assert i1.problemas.first().problema.estado == Problema.ESTADOS.potencial

    i2 = IdentificacionFactory(attachment=a, status='problema', mesa=None)
    Problema.reportar_problema(f,
                               'reporte 2',
                               ReporteDeProblema.TIPOS_DE_PROBLEMA.ilegible,
                               identificacion=i2)

    assert i1.invalidada == False
    assert i2.invalidada == False

    consumir_novedades_identificacion()

    # Se consolidó un problema.
    a.refresh_from_db()
    assert a.status == Attachment.STATUS.problema
    problema = i1.problemas.first().problema
    assert problema.estado == Problema.ESTADOS.pendiente

    # El attach no está entre los pendientes.
    assert a not in Attachment.objects.sin_identificar()

    problema.resolver(FiscalFactory().user)

    assert problema.estado == Problema.ESTADOS.resuelto

    i1.refresh_from_db()
    i2.refresh_from_db()
    # Las identificaciones están invalidadas.
    assert i1.invalidada == True
    assert i2.invalidada == True

    consumir_novedades_identificacion()

    # Se agrega una nueva identificación y se consolida.
    IdentificacionFactory(attachment=a, status='identificada', mesa=m1)
    consumir_novedades_identificacion()
    a.refresh_from_db()
    assert a.status == Attachment.STATUS.identificada
    assert a.mesa == m1
コード例 #7
0
def test_identificacion_create_view_post(fiscal_client, admin_user):
    m1 = MesaFactory()
    a = AttachmentFactory()
    admin_user.fiscal.asignar_attachment(a)
    a.asignar_a_fiscal()
    data = {
        'mesa': m1.numero,
        'circuito': m1.circuito.numero,
        'seccion': m1.circuito.seccion.numero,
        'distrito': m1.circuito.seccion.distrito.id,
    }
    response = fiscal_client.post(reverse('asignar-mesa', args=[a.id]), data)
    assert response.status_code == HTTPStatus.FOUND
    assert response.url == reverse('siguiente-accion')
    assert a.identificaciones.count() == 1
    i = a.identificaciones.first()
    assert i.status == Identificacion.STATUS.identificada
    assert i.mesa == m1
    assert i.fiscal == admin_user.fiscal
    # La identificación todavía no está consolidada.
    a.refresh_from_db()
    assert a.identificacion_testigo is None
    assert not m1.attachments.exists()
    assert a.cant_fiscales_asignados == 0