Projet

Général

Profil

0001-caluire-axel-allow-to-call-invoice-endpoint-anonymou.patch

Nicolas Roche, 26 août 2021 16:12

Télécharger (6,29 ko)

Voir les différences:

Subject: [PATCH] caluire-axel: allow to call invoice endpoint anonymously
 (#56006)

 passerelle/contrib/caluire_axel/models.py |  8 ++-
 tests/test_caluire_axel.py                | 82 +++++++++++++++++++++--
 2 files changed, 83 insertions(+), 7 deletions(-)
passerelle/contrib/caluire_axel/models.py
1103 1103
        description=_('Get invoice details'),
1104 1104
        parameters={
1105 1105
            'NameID': {'description': _('Publik ID')},
1106 1106
            'regie_id': {'description': _('Regie identifier'), 'example_value': 'ENF'},
1107 1107
            'invoice_id': {'description': _('Invoice identifier'), 'example_value': 'IDFAM-42'},
1108 1108
            'nb_mounts_limit': {'description': _('Number of months of history'), 'example_value': '12'},
1109 1109
        },
1110 1110
    )
1111
    def invoice(self, request, regie_id, invoice_id, NameID, nb_mounts_limit='12'):
1112
        link = self.get_link(NameID)
1111
    def invoice(self, request, regie_id, invoice_id, NameID=None, nb_mounts_limit='12'):
1113 1112
        real_invoice_id = invoice_id.split('-')[-1]
1114 1113
        historical = invoice_id.startswith('historical-')
1114
        if historical:
1115
            invoice_id = invoice_id[len('historical-') :]
1116
        family_id, real_invoice_id = invoice_id.split('-')
1115 1117
        invoice = self.get_invoice(
1116 1118
            regie_id=regie_id,
1117 1119
            invoice_id=real_invoice_id,
1118
            family_id=link.family_id,
1120
            family_id=family_id,
1119 1121
            historical=historical,
1120 1122
            nb_mounts_limit=nb_mounts_limit,
1121 1123
        )
1122 1124
        if invoice is None:
1123 1125
            raise APIError('Invoice not found', err_code='not-found')
1124 1126

  
1125 1127
        return {'data': invoice}
1126 1128

  
tests/test_caluire_axel.py
3041 3041
    with mock_data(content, 'GetListFactures'):
3042 3042
        resp = app.get('/caluire-axel/test/regie/MAREGIE/invoice/historical-XXX-42?NameID=yyy')
3043 3043
    assert resp.json['err_desc'] == "Wrong get-historical-invoices status"
3044 3044
    assert resp.json['err'] == 'get-historical-invoices-code-error--3'
3045 3045

  
3046 3046

  
3047 3047
@freezegun.freeze_time('2019-12-12')
3048 3048
def test_invoice_endpoint_no_result(app, resource):
3049
    resp = app.get('/caluire-axel/test/regie/MAREGIE/invoice/XXX-42?NameID=yyy')
3050
    assert resp.json['err_desc'] == "Person not found"
3051
    assert resp.json['err'] == 'not-found'
3052

  
3053 3049
    Link.objects.create(resource=resource, name_id='yyy', family_id='XXX', person_id='42')
3054 3050
    filepath = os.path.join(os.path.dirname(__file__), 'data/caluire_axel/invoices.xml')
3055 3051
    with open(filepath) as xml:
3056 3052
        invoices = xml.read()
3057 3053
    content = (
3058 3054
        '''<PORTAIL>
3059 3055
  <GETFACTURESAPAYER>
3060 3056
    %s
......
3164 3160
                'ECHEANCE': '2019-12-04',
3165 3161
                'EMISSION': '2019-11-12',
3166 3162
                'EXISTEPDF': True,
3167 3163
            },
3168 3164
        },
3169 3165
    }
3170 3166

  
3171 3167

  
3168
@freezegun.freeze_time('2019-12-04')
3169
def test_invoice_endpoint_anonymously(app, resource):
3170
    Link.objects.create(resource=resource, name_id='yyy', family_id='XXX', person_id='42')
3171
    filepath = os.path.join(os.path.dirname(__file__), 'data/caluire_axel/invoices.xml')
3172
    with open(filepath) as xml:
3173
        invoices = xml.read()
3174
    content = (
3175
        '''<PORTAIL>
3176
  <GETFACTURESAPAYER>
3177
    %s
3178
  </GETFACTURESAPAYER>
3179
</PORTAIL>'''
3180
        % invoices
3181
    )
3182
    with mock_data(content, 'GetFacturesaPayer'):
3183
        resp = app.get('/caluire-axel/test/regie/MAREGIE/invoice/XXX-42')
3184
    assert resp.json['err'] == 0
3185
    assert resp.json['data'] == {
3186
        'id': 'XXX-42',
3187
        'display_id': '42',
3188
        'label': 'PRESTATIONS PERISCOLAIRES SEPTEMBRE-OCTOBRE 2019',
3189
        'amount': '4.94',
3190
        'total_amount': '44.94',
3191
        'amount_paid': '40.00',
3192
        'online_payment': True,
3193
        'created': '2019-11-12',
3194
        'pay_limit_date': '2019-12-04',
3195
        'has_pdf': True,
3196
        'paid': False,
3197
        'vendor': {
3198
            'caluire-axel': {
3199
                'IDFACTURE': 42,
3200
                'MONTANT': '44.94',
3201
                'ENCAISSE': '40.00',
3202
                'FACTURATION': 'PRESTATIONS PERISCOLAIRES SEPTEMBRE-OCTOBRE 2019',
3203
                'ECHEANCE': '2019-12-04',
3204
                'EMISSION': '2019-11-12',
3205
                'EXISTEPDF': True,
3206
            }
3207
        },
3208
    }
3209

  
3210
    content = (
3211
        '''<PORTAIL>
3212
    <GETLISTFACTURES>
3213
        %s
3214
    </GETLISTFACTURES>
3215
</PORTAIL>'''
3216
        % invoices
3217
    )
3218
    with mock_data(content, 'GetListFactures'):
3219
        resp = app.get('/caluire-axel/test/regie/MAREGIE/invoice/historical-XXX-42')
3220
    assert resp.json['err'] == 0
3221
    assert resp.json['data'] == {
3222
        'id': 'historical-XXX-42',
3223
        'display_id': '42',
3224
        'label': 'PRESTATIONS PERISCOLAIRES SEPTEMBRE-OCTOBRE 2019',
3225
        'amount': 0,
3226
        'total_amount': '44.94',
3227
        'online_payment': False,
3228
        'created': '2019-11-12',
3229
        'pay_limit_date': '',
3230
        'has_pdf': True,
3231
        'paid': False,
3232
        'vendor': {
3233
            'caluire-axel': {
3234
                'IDFACTURE': 42,
3235
                'MONTANT': '44.94',
3236
                'ENCAISSE': '40.00',
3237
                'FACTURATION': 'PRESTATIONS PERISCOLAIRES SEPTEMBRE-OCTOBRE 2019',
3238
                'ECHEANCE': '2019-12-04',
3239
                'EMISSION': '2019-11-12',
3240
                'EXISTEPDF': True,
3241
            },
3242
        },
3243
    }
3244

  
3245

  
3172 3246
def test_invoice_pdf_endpoint_axel_error(app, resource):
3173 3247
    Link.objects.create(resource=resource, name_id='yyy', family_id='XXX', person_id='42')
3174 3248
    with mock.patch('passerelle.contrib.caluire_axel.schemas.get_factures_a_payer') as operation:
3175 3249
        operation.side_effect = AxelError('FooBar')
3176 3250
        resp = app.get('/caluire-axel/test/regie/MAREGIE/invoice/XXX-42/pdf?NameID=yyy', status=404)
3177 3251
    assert resp.json['err_desc'] == "Axel error: FooBar"
3178 3252
    assert resp.json['err'] == 'error'
3179 3253

  
3180
-