| Conditions | 3 |
| Total Lines | 72 |
| Code Lines | 54 |
| 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 |
||
| 179 | def test_diverza_stamp_pago_v40(): |
||
| 180 | signer = get_signer('xiqb891116qe4') |
||
| 181 | emisor = Issuer(signer=signer, tax_system="601") |
||
| 182 | |||
| 183 | diverza = Diverza( |
||
| 184 | rfc="AAA010101AAA", |
||
| 185 | id="3935", |
||
| 186 | token="ABCD1234", |
||
| 187 | environment=Environment.TEST |
||
| 188 | ) |
||
| 189 | |||
| 190 | cfdi = cfdi40.Comprobante.pago( |
||
| 191 | emisor=emisor, |
||
| 192 | fecha=datetime.fromisoformat("2022-09-28T22:40:38"), |
||
| 193 | receptor=cfdi40.Receptor( |
||
| 194 | rfc='KIJ0906199R1', |
||
| 195 | nombre='KIJ, S.A DE C.V.', |
||
| 196 | uso_cfdi='G03', |
||
| 197 | domicilio_fiscal_receptor="59820", |
||
| 198 | regimen_fiscal_receptor="601" |
||
| 199 | ), |
||
| 200 | lugar_expedicion="56820", |
||
| 201 | complemento_pago=pago20.Pagos( |
||
| 202 | pago=pago20.Pago( |
||
| 203 | fecha_pago=datetime(2020, 1, 1), |
||
| 204 | forma_de_pago_p='03', |
||
| 205 | moneda_p='MXN', |
||
| 206 | tipo_cambio_p=1, |
||
| 207 | docto_relacionado=pago20.DoctoRelacionado( |
||
| 208 | id_documento='d6042dc8-d525-4e78-8d1b-092c878bd518', |
||
| 209 | imp_pagado=Decimal("100.3"), |
||
| 210 | imp_saldo_ant=Decimal("203.45"), |
||
| 211 | num_parcialidad=3, |
||
| 212 | moneda_dr="MXN", |
||
| 213 | objeto_imp_dr="01" |
||
| 214 | ) |
||
| 215 | ) |
||
| 216 | ), |
||
| 217 | serie="A", |
||
| 218 | folio="123456" |
||
| 219 | ) |
||
| 220 | |||
| 221 | with mock.patch(f'requests.request') as mk: |
||
| 222 | mk.return_value.json = mock.Mock(return_value={ |
||
| 223 | "uuid": "3d94d0c5-9d4d-4c73-a61b-d083c553b7cc", |
||
| 224 | "content": "dGhpcyBpcyBhIHRlc3QgeG1s" |
||
| 225 | }) |
||
| 226 | diverza.stamp(cfdi=cfdi) |
||
| 227 | |||
| 228 | assert mk.called |
||
| 229 | mk.call_args.kwargs["headers"]["User-Agent"] = 'this is a test' |
||
| 230 | |||
| 231 | args = json.dumps(mk.call_args.kwargs, indent=2) |
||
| 232 | verify = verify_result(data=args, filename="test_diverza_stamp_pago_v40.json") |
||
| 233 | assert verify |
||
| 234 | |||
| 235 | with mock.patch(f'requests.request') as mk: |
||
| 236 | mk.return_value.json = mock.Mock(return_value={ |
||
| 237 | "uuid": "3d94d0c5-9d4d-4c73-a61b-d083c553b7cc", |
||
| 238 | "content": "dGhpcyBpcyBhIHRlc3QgeG1s" |
||
| 239 | }) |
||
| 240 | diverza.issue( |
||
| 241 | cfdi=cfdi, |
||
| 242 | # certificate_number=signer.certificate_number() |
||
| 243 | ) |
||
| 244 | |||
| 245 | assert mk.called |
||
| 246 | mk.call_args.kwargs["headers"]["User-Agent"] = 'this is a test' |
||
| 247 | |||
| 248 | args = json.dumps(mk.call_args.kwargs, indent=2) |
||
| 249 | verify = verify_result(data=args, filename="test_diverza_issue_pago_v40.json") |
||
| 250 | assert verify |
||
| 251 | |||
| 252 |