api_particulier: new test system (#30708)
This commit is contained in:
parent
89a97579b6
commit
d501c6055b
|
@ -0,0 +1,25 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.11.18 on 2019-02-15 14:07
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('api_particulier', '0003_auto_20190212_0426'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RenameField(
|
||||
model_name='apiparticulier',
|
||||
old_name='_api_key',
|
||||
new_name='api_key',
|
||||
),
|
||||
migrations.RenameField(
|
||||
model_name='apiparticulier',
|
||||
old_name='_platform',
|
||||
new_name='platform',
|
||||
),
|
||||
]
|
|
@ -40,34 +40,25 @@ class APIParticulier(BaseResource):
|
|||
{
|
||||
'name': 'test',
|
||||
'label': _('Test'),
|
||||
'url': 'https://particulier-sandbox.api.gouv.fr/api/',
|
||||
'api_key': 'test-token',
|
||||
'url': 'https://particulier-test.api.gouv.fr/api/',
|
||||
},
|
||||
]
|
||||
PLATFORMS = OrderedDict([(platform['name'], platform) for platform in PLATFORMS])
|
||||
|
||||
_platform = models.CharField(
|
||||
platform = models.CharField(
|
||||
verbose_name=_('Platform'),
|
||||
max_length=8,
|
||||
choices=[(key, platform['label']) for key, platform in PLATFORMS.iteritems()])
|
||||
|
||||
_api_key = models.CharField(
|
||||
api_key = models.CharField(
|
||||
max_length=256,
|
||||
default='',
|
||||
blank=True,
|
||||
verbose_name=_('API key'))
|
||||
|
||||
@property
|
||||
def platform(self):
|
||||
return self.PLATFORMS[self._platform]
|
||||
|
||||
@property
|
||||
def url(self):
|
||||
return self.platform['url']
|
||||
|
||||
@property
|
||||
def api_key(self):
|
||||
return self.platform.get('api_key', self._api_key)
|
||||
return self.PLATFORMS[self.platform]['url']
|
||||
|
||||
def get(self, path, **kwargs):
|
||||
user = kwargs.pop('user', None)
|
||||
|
@ -84,9 +75,9 @@ class APIParticulier(BaseResource):
|
|||
except requests.RequestException as e:
|
||||
raise APIError(
|
||||
u'API-particulier platform "%s" connection error: %s' %
|
||||
(self._platform, response.status_code),
|
||||
(self.platform, response.status_code),
|
||||
data={
|
||||
'platform': self._platform,
|
||||
'platform': self.platform,
|
||||
'error': unicode(e),
|
||||
})
|
||||
try:
|
||||
|
@ -95,11 +86,11 @@ class APIParticulier(BaseResource):
|
|||
content = repr(response.content[:1000])
|
||||
raise APIError(
|
||||
u'API-particulier platform "%s" returned non-JSON content with status %s: %s' %
|
||||
(self._platform, response.status_code, content),
|
||||
(self.platform, response.status_code, content),
|
||||
data={
|
||||
'status_code': response.status_code,
|
||||
'exception': unicode(e),
|
||||
'platform': self._platform,
|
||||
'platform': self.platform,
|
||||
'content': content,
|
||||
})
|
||||
if response.status_code != 200:
|
||||
|
@ -110,10 +101,10 @@ class APIParticulier(BaseResource):
|
|||
}
|
||||
raise APIError(
|
||||
u'API-particulier platform "%s" returned a non 200 status %s: %s' %
|
||||
(self._platform, response.status_code, data),
|
||||
(self.platform, response.status_code, data),
|
||||
data={
|
||||
'status_code': response.status_code,
|
||||
'platform': self._platform,
|
||||
'platform': self.platform,
|
||||
'content': data,
|
||||
})
|
||||
return {
|
||||
|
@ -126,11 +117,11 @@ class APIParticulier(BaseResource):
|
|||
parameters={
|
||||
'numero_fiscal': {
|
||||
'description': _('fiscal identifier'),
|
||||
'example_value': '12',
|
||||
'example_value': '1562456789521',
|
||||
},
|
||||
'reference_avis': {
|
||||
'description': _('tax notice number'),
|
||||
'example_value': '15',
|
||||
'example_value': '1512456789521',
|
||||
},
|
||||
'user': {
|
||||
'description': _('requesting user'),
|
||||
|
@ -148,11 +139,11 @@ class APIParticulier(BaseResource):
|
|||
parameters={
|
||||
'numero_fiscal': {
|
||||
'description': _('fiscal identifier'),
|
||||
'example_value': '12',
|
||||
'example_value': '1562456789521',
|
||||
},
|
||||
'reference_avis': {
|
||||
'description': _('tax notice number'),
|
||||
'example_value': '15',
|
||||
'example_value': '1512456789521',
|
||||
},
|
||||
'user': {
|
||||
'description': _('requesting user'),
|
||||
|
|
|
@ -180,7 +180,8 @@ def resource(db):
|
|||
slug='test',
|
||||
title='API Particulier Prod',
|
||||
description='API Particulier Prod',
|
||||
_platform='test')
|
||||
platform='test',
|
||||
api_key='83c68bf0b6013c4daf3f8213f7212aa5')
|
||||
|
||||
|
||||
def test_error(app, resource, mock_api_particulier):
|
||||
|
|
Loading…
Reference in New Issue