Passed
Push — main ( 97b175...ba1019 )
by Sat CFDI
05:01
created

test_create_pld.test_arrendamiento_de_inmuebles()   B

Complexity

Conditions 1

Size

Total Lines 72
Code Lines 56

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 56
nop 0
dl 0
loc 72
rs 8.44
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
import inspect
2
import os
3
from datetime import date
4
5
import pytest
6
7
from satcfdi import CFDI, SchemaValidationError
8
from satcfdi.create.pld import ari
9
from tests.utils import verify_result, XElementPrettyPrinter
10
11
module = 'satcfdi'
12
current_dir = os.path.dirname(__file__)
13
14
15
def verify_invoice(invoice, path):
16
    pp = XElementPrettyPrinter()
17
    verify = verify_result(data=pp.pformat(invoice), filename=f"{path}.pretty.py")
18
    assert verify
19
20
    verify = verify_result(data=invoice.xml_bytes(pretty_print=True), filename=f"{path}.xml")
21
    assert verify
22
23
    verify = verify_result(data=invoice.html_str(), filename=f"{path}.html")
24
    assert verify
25
26
27
def test_ejemplos():
28
    pld_ejemplos_dir = os.path.join(current_dir, 'pdl', 'ejemplos')
29
30
    for file in os.listdir(pld_ejemplos_dir):
31
        ejemplo = CFDI.from_file(os.path.join(pld_ejemplos_dir, file))
32
33
        verify_invoice(ejemplo, path=f"ejemplos/{file}")
34
35
36
def test_arrendamiento_de_inmuebles_zeros():
37
    ari_file = os.path.join(current_dir, 'pdl', 'ejemplo_ari_zeros.xml')
38
    report_f = CFDI.from_file(ari_file)
39
40
    report_a = ari.Archivo(
41
        informe=ari.InformeType(
42
            mes_reportado='202210',
43
            sujeto_obligado=ari.SujetoObligadoType(
44
                clave_sujeto_obligado='OGA751212G56',
45
                clave_actividad='ARI'
46
            )
47
        )
48
    )
49
50
    report_a = report_a.process()
51
    assert report_a == report_f
52
53
    verify = verify_result(data=report_a.xml_bytes(pretty_print=True, include_schema_location=True), filename=f"o_{inspect.stack()[0][3]}.xml")
54
    assert verify
55
56
57
def test_arrendamiento_de_inmuebles_zeros_invalid():
58
    with pytest.raises(SchemaValidationError) as excinfo:
59
        report_a = ari.Archivo(
60
            informe=ari.InformeType(
61
                mes_reportado='20221043',  # Mes invalido
62
                sujeto_obligado=ari.SujetoObligadoType(
63
                    clave_sujeto_obligado='OGA751212G56',
64
                    clave_actividad='ARI'
65
                )
66
            )
67
        ).process(validate=True)
68
69
    verify = verify_result(data=str(excinfo.value.error_log), filename=f"o_{inspect.stack()[0][3]}.txt")
70
    assert verify
71
72
73
def test_arrendamiento_de_inmuebles():
74
    ari_file = os.path.join(current_dir, 'pdl', 'ejemplo_ari.xml')
75
    report_f = CFDI.from_file(ari_file)
76
77
    report_a = ari.Archivo(
78
        informe=ari.InformeType(
79
            mes_reportado='201407',
80
            sujeto_obligado=ari.SujetoObligadoType(
81
                clave_sujeto_obligado='OGA751212G56',
82
                clave_actividad='ARI'
83
            ),
84
            aviso=ari.AvisoType(
85
                referencia_aviso='REF15454FG454',
86
                prioridad='1',
87
                alerta=ari.AlertaType(
88
                    tipo_alerta='100'
89
                ),
90
                persona_aviso=ari.PersonaAvisoType(
91
                    tipo_persona=ari.TipoPersonaType(
92
                        persona_fisica=ari.PersonaFisicaType(
93
                            nombre='NEPOMUCENO',
94
                            apellido_paterno='ALMONTE',
95
                            apellido_materno='JUAREZ',
96
                            fecha_nacimiento=date(1956, 8, 16),
97
                            pais_nacionalidad='TG',
98
                            actividad_economica='3130100'
99
                        )
100
                    ),
101
                    tipo_domicilio=ari.TipoDomicilioType(
102
                        extranjero=ari.ExtranjeroType(
103
                            pais='TG',
104
                            estado_provincia='TOGUILLITA',
105
                            ciudad_poblacion='TOGUIS',
106
                            colonia='NA',
107
                            calle='TOGA TOGA',
108
                            numero_exterior='45',
109
                            codigo_postal='12448'
110
                        )
111
                    ),
112
                ),
113
                detalle_operaciones=ari.DetalleOperacionesType(
114
                    datos_operacion=ari.DatosOperacionType(
115
                        fecha_operacion=date(2014, 7, 1),
116
                        tipo_operacion='1501',
117
                        caracteristicas=ari.CaracteristicasType(
118
                            fecha_inicio=date(2014, 1, 1),
119
                            fecha_termino=date(2015, 1, 1),
120
                            tipo_inmueble='3',
121
                            valor_referencia='356825.12',
122
                            colonia='6920',
123
                            calle='SAN SIMON TOLNAHUAC',
124
                            numero_exterior='VIOLANTE',
125
                            numero_interior='45',
126
                            codigo_postal='01058',
127
                            folio_real='BG544-FRR-456B-FRR'
128
                        ),
129
                        datos_liquidacion=ari.DatosLiquidacionType(
130
                            fecha_pago=date(2014, 7, 1),
131
                            forma_pago='4',
132
                            instrumento_monetario='4',
133
                            moneda='2',
134
                            monto_operacion='757897.55'
135
                        )
136
                    )
137
                )
138
            )
139
        )
140
    ).process()
141
142
    assert report_a == report_f
143
144
    verify_invoice(report_a, path=f"o_{inspect.stack()[0][3]}")
145