From 750768cf5ec4dc0abe132125b245041459d4a149 Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Tue, 20 Feb 2018 00:18:32 +0100 Subject: [PATCH] =?UTF-8?q?int=C3=A9gration=20des=20remarques?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/test_api_particulier.py | 30 +++++++++++++++--------------- tests/utils.py | 17 ++++------------- 2 files changed, 19 insertions(+), 28 deletions(-) diff --git a/tests/test_api_particulier.py b/tests/test_api_particulier.py index 81725c5..b24f5b9 100644 --- a/tests/test_api_particulier.py +++ b/tests/test_api_particulier.py @@ -23,7 +23,7 @@ from django.core.urlresolvers import reverse from passerelle.apps.api_particulier.models import APIParticulier -from utils import make_ressource, endpoint_get +from utils import make_resource, endpoint_get SVAIR_RESPONSE = { "declarant1": { @@ -162,7 +162,7 @@ def api_particulier_error_not_json(url, request): @urlmatch(netloc='^particulier.*\.api\.gouv\.fr$') def api_particulier_error_not_found(url, request): return response(404, { - 'error': 'not-found', + 'error': 'not_found', 'message': u'Les paramètres fournis sont incorrects ou ne correspondent pas à un avis' }, request=request) @@ -174,8 +174,8 @@ def mock_api_particulier(): @pytest.fixture -def ressource(db): - return make_ressource( +def resource(db): + return make_resource( APIParticulier, slug='test', title='API Particulier Prod', @@ -183,13 +183,13 @@ def ressource(db): _platform='test') -def test_error(app, ressource, mock_api_particulier): +def test_error(app, resource, mock_api_particulier): with HTTMock(api_particulier_error_500): def do(endpoint, params): resp = endpoint_get( '/api-particulier/test/%s' % endpoint, app, - ressource, + resource, endpoint, params=params) assert resp.status_code == 200 @@ -213,7 +213,7 @@ def test_error(app, ressource, mock_api_particulier): resp = endpoint_get( '/api-particulier/test/%s' % endpoint, app, - ressource, + resource, endpoint, params=params) assert resp.status_code == 200 @@ -237,7 +237,7 @@ def test_error(app, ressource, mock_api_particulier): resp = endpoint_get( '/api-particulier/test/%s' % endpoint, app, - ressource, + resource, endpoint, params=params) assert resp.status_code == 200 @@ -258,11 +258,11 @@ def test_error(app, ressource, mock_api_particulier): do(endpoint, params) -def test_impots_svair(app, ressource, mock_api_particulier): +def test_impots_svair(app, resource, mock_api_particulier): resp = endpoint_get( '/api-particulier/test/impots_svair', app, - ressource, + resource, 'impots_svair', params={ 'numero_fiscal': 12, @@ -272,11 +272,11 @@ def test_impots_svair(app, ressource, mock_api_particulier): assert resp.json['data']['montantImpot'] == 2165 -def test_impots_adresse(app, ressource, mock_api_particulier): +def test_impots_adresse(app, resource, mock_api_particulier): resp = endpoint_get( '/api-particulier/test/impots_adresse', app, - ressource, + resource, 'impots_adresse', params={ 'numero_fiscal': 12, @@ -286,11 +286,11 @@ def test_impots_adresse(app, ressource, mock_api_particulier): assert resp.json['data']['adresses'][0]['adresse']['citycode'] == '75108' -def test_caf_famille(app, ressource, mock_api_particulier): +def test_caf_famille(app, resource, mock_api_particulier): resp = endpoint_get( '/api-particulier/test/caf_famille', app, - ressource, + resource, 'caf_famille', params={ 'code_postal': '99148', @@ -300,7 +300,7 @@ def test_caf_famille(app, ressource, mock_api_particulier): assert resp.json['data']['adresse']['codePostalVille'] == '12345 CONDAT' -def test_detail_page(app, ressource): +def test_detail_page(app, resource): response = app.get(reverse('view-connector', kwargs={ 'connector': 'api-particulier', 'slug': 'test', diff --git a/tests/utils.py b/tests/utils.py index 3c8f583..e2b63e2 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -41,19 +41,10 @@ def mock_url(url, response): return httmock.HTTMock(mocked) -def make_ressource(model_class, **kwargs): - api, created = ApiUser.objects.get_or_create( - username='all', - keytype='', - key='') - ressource = model_class.objects.create(**kwargs) - obj_type = ContentType.objects.get_for_model(model_class) - AccessRight.objects.get_or_create( - codename='can_access', - apiuser=api, - resource_type=obj_type, - resource_pk=ressource.pk) - return ressource +def make_resource(model_class, **kwargs): + resource = model_class.objects.create(**kwargs) + setup_access_rights(resource) + return resource def endpoint_get(expected_url, app, ressource, endpoint, **kwargs): -- 2.14.2