Conditions | 2 |
Total Lines | 70 |
Code Lines | 57 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
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:
If many parameters/temporary variables are present:
1 | import json |
||
15 | def test_prodigia_test(): |
||
16 | prodigia = Prodigia( |
||
17 | contrato="ccde5231-5bfe-4cba-b991-a59424336d4d", |
||
18 | user="user", |
||
19 | password="password", |
||
20 | environment=Environment.TEST |
||
21 | ) |
||
22 | |||
23 | signer = get_signer('xiqb891116qe4') |
||
24 | emisor = Issuer(signer=signer, tax_system="606") |
||
25 | |||
26 | invoice = cfdi40.Comprobante( |
||
27 | emisor=emisor, |
||
28 | lugar_expedicion="27200", |
||
29 | fecha=datetime.fromisoformat("2022-09-28T22:40:38"), |
||
30 | receptor=cfdi40.Receptor( |
||
31 | rfc="H&E951128469", |
||
32 | nombre="H & E", |
||
33 | uso_cfdi="G03", |
||
34 | domicilio_fiscal_receptor="34500", |
||
35 | regimen_fiscal_receptor="601" |
||
36 | ), |
||
37 | metodo_pago="PPD", |
||
38 | forma_pago="99", |
||
39 | serie="T", |
||
40 | folio="1000", |
||
41 | conceptos=cfdi40.Concepto( |
||
42 | cuenta_predial='1234567890', |
||
43 | clave_prod_serv='10101702', |
||
44 | cantidad=Decimal('.10'), |
||
45 | clave_unidad='E48', |
||
46 | descripcion='SERVICIOS DE RENTA', |
||
47 | valor_unitario=Decimal("1.00"), |
||
48 | traslados=cfdi40.Impuesto.parse('002|Tasa|0.160000'), |
||
49 | retenciones=[cfdi40.Impuesto.parse('001|Tasa|0.100000'), cfdi40.Impuesto.parse('002|Tasa|0.106667')], |
||
50 | _traslados_incluidos=True |
||
51 | ) |
||
52 | ) |
||
53 | |||
54 | with mock.patch(f'requests.request') as mk: |
||
55 | mk.return_value.json = mock.Mock(return_value={ |
||
56 | 'servicioTimbrado': { |
||
57 | 'codigo': 0, |
||
58 | 'selloSAT': 'dGhpcyBpcyBhIHNlYWwgdGVzdA==', |
||
59 | 'xmlBase64': 'PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz48Y2ZkaTpDb21wcm9iYW50ZSB4bWxuczpjZmRpPSJodHRwOi8vd3d3LnNhdC5nb2IubXgvY2ZkLzQiIA==', |
||
60 | 'contrato': '97353117-126d-4d72-93aa-1142496fbd81', |
||
61 | 'timbradoOk': True, |
||
62 | 'id': '21afd57c-20a3-4d48-a478-76de7b3fe4f4', |
||
63 | 'mensaje': '*** generado en modo de pruebas ***', |
||
64 | 'FechaTimbrado': '2020-01-01T112:20:00', |
||
65 | 'noCertificadoSAT': 12345678, |
||
66 | 'UUID': 'A6C30EF1-1967-4E4A-B4A0-EDAC0CF88541', |
||
67 | 'version': 1.1 |
||
68 | } |
||
69 | }) |
||
70 | |||
71 | res = prodigia.stamp( |
||
72 | cfdi=invoice |
||
73 | ) |
||
74 | assert res.xml == b'<?xml version="1.0" encoding="UTF-8"?><cfdi:Comprobante xmlns:cfdi="http://www.sat.gob.mx/cfd/4" ' |
||
75 | assert not res.pdf |
||
76 | |||
77 | assert mk.called |
||
78 | mk.call_args.kwargs["headers"]["User-Agent"] = 'this is a test' |
||
79 | assert mk.call_args.kwargs["auth"] == HTTPBasicAuth("user", "password") |
||
80 | mk.call_args.kwargs["auth"] = "Basic abc" |
||
81 | |||
82 | args = json.dumps(mk.call_args.kwargs, indent=2, default=str, ensure_ascii=False) |
||
83 | verify = verify_result(data=args, filename="test_prodigia_stamp.json") |
||
84 | assert verify |
||
85 |