api-impot-particulier: add housing tax endpoint (#77236)
gitea/passerelle/pipeline/head This commit looks good
Details
gitea/passerelle/pipeline/head This commit looks good
Details
This commit is contained in:
parent
96413bd5d9
commit
4d89c476bb
|
@ -115,6 +115,37 @@ class Resource(BaseResource):
|
||||||
accept='application/prs.dgfip.part.situations.ir.assiettes.v1+json',
|
accept='application/prs.dgfip.part.situations.ir.assiettes.v1+json',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@endpoint(
|
||||||
|
name='spi-situations-th-assiettes-principale-annrev',
|
||||||
|
description=_('Provides housing tax situation for a specific year.'),
|
||||||
|
parameters={
|
||||||
|
'numero_fiscal': {
|
||||||
|
'description': _('Tax number of the person'),
|
||||||
|
},
|
||||||
|
'annee_de_revenu': {
|
||||||
|
'description': _('Income year'),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
)
|
||||||
|
def spi_situations_th_assiettes_principale_annrev(self, request, numero_fiscal, annee_de_revenu):
|
||||||
|
numero_fiscal = self.parse_numero_fiscal(numero_fiscal)
|
||||||
|
annee_de_revenu = self.parse_annee_de_revenu(annee_de_revenu)
|
||||||
|
return {
|
||||||
|
'data': self.get_spi_situations_th_assiettes_principale_annrev(
|
||||||
|
numero_fiscal=numero_fiscal, annee_de_revenu=annee_de_revenu, timeout=Timeout(20)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
def get_spi_situations_th_assiettes_principale_annrev(self, numero_fiscal, annee_de_revenu, timeout=None):
|
||||||
|
return self.call(
|
||||||
|
name='spi-situations-th-assiettes-principale-deuxans',
|
||||||
|
endpoint_template='spi/{spi}/situations/th/assiettes/principale/annrev/{annrev}',
|
||||||
|
timeout=timeout,
|
||||||
|
spi=numero_fiscal,
|
||||||
|
annrev=annee_de_revenu,
|
||||||
|
accept='application/prs.dgfip.part.situations.th.assiettes.v1+json',
|
||||||
|
)
|
||||||
|
|
||||||
def call(self, name, endpoint_template, timeout=None, **kwargs):
|
def call(self, name, endpoint_template, timeout=None, **kwargs):
|
||||||
correlation_id = str(uuid.uuid4().hex)
|
correlation_id = str(uuid.uuid4().hex)
|
||||||
kwargs_formatted = ', '.join(f'{key}={value}' for key, value in kwargs.items())
|
kwargs_formatted = ', '.join(f'{key}={value}' for key, value in kwargs.items())
|
||||||
|
|
|
@ -163,6 +163,25 @@ class TestGetMethods:
|
||||||
assert request.headers['x-correlation-id'] == 'abcd'
|
assert request.headers['x-correlation-id'] == 'abcd'
|
||||||
assert request.headers['Accept'] == 'application/prs.dgfip.part.situations.ir.assiettes.v1+json'
|
assert request.headers['Accept'] == 'application/prs.dgfip.part.situations.ir.assiettes.v1+json'
|
||||||
|
|
||||||
|
def test_spi_situations_th_assiettes_principale_annrev(self, resource):
|
||||||
|
responses.add(
|
||||||
|
responses.GET,
|
||||||
|
'https://gw.dgfip.finances.gouv.fr/impotparticulier/1.0/spi/1234/situations/th/assiettes/principale/annrev/2023',
|
||||||
|
json={'data': 2},
|
||||||
|
)
|
||||||
|
assert resource.get_spi_situations_th_assiettes_principale_annrev(
|
||||||
|
numero_fiscal='1234', annee_de_revenu='2023'
|
||||||
|
) == {'data': 2}
|
||||||
|
assert len(responses.calls) <= 2
|
||||||
|
if len(responses.calls) == 2:
|
||||||
|
request = responses.calls[0].request
|
||||||
|
assert request.body == 'grant_type=client_credentials&scope=scope'
|
||||||
|
assert request.headers['authorization'] == 'Basic dXNlcjpwYXNz'
|
||||||
|
request = responses.calls[-1].request
|
||||||
|
assert request.headers['authorization'] == 'Bearer 1234'
|
||||||
|
assert request.headers['x-correlation-id'] == 'abcd'
|
||||||
|
assert request.headers['Accept'] == 'application/prs.dgfip.part.situations.th.assiettes.v1+json'
|
||||||
|
|
||||||
def test_spi_situations_connection_error(self, resource):
|
def test_spi_situations_connection_error(self, resource):
|
||||||
responses.add(
|
responses.add(
|
||||||
responses.GET,
|
responses.GET,
|
||||||
|
@ -214,3 +233,15 @@ class TestEndpoints:
|
||||||
params={'numero_fiscal': '1234', 'annee_de_revenu': '2000'},
|
params={'numero_fiscal': '1234', 'annee_de_revenu': '2000'},
|
||||||
)
|
)
|
||||||
assert response.json['err'] == 1
|
assert response.json['err'] == 1
|
||||||
|
|
||||||
|
@mock.patch(
|
||||||
|
'passerelle.apps.api_impot_particulier.models.Resource.get_spi_situations_th_assiettes_principale_annrev'
|
||||||
|
)
|
||||||
|
def test_spi_situations_th_assiettes_principale_annrev(self, mock_get, app, resource):
|
||||||
|
mock_get.return_value = 'ok'
|
||||||
|
response = app.get(
|
||||||
|
'/api-impot-particulier/test/spi-situations-th-assiettes-principale-annrev',
|
||||||
|
params={'numero_fiscal': '1234', 'annee_de_revenu': last_year},
|
||||||
|
)
|
||||||
|
assert mock_get.call_args[1]['numero_fiscal'] == '1234'
|
||||||
|
assert response.json == {'data': 'ok', 'err': 0}
|
||||||
|
|
Loading…
Reference in New Issue