Added 'collectivite' param to 'create_dossier()' endpoint, removed useless '*args' and '**kwargs'

This commit is contained in:
Michael Bideau 2019-07-29 14:30:50 +02:00
parent 98cd089254
commit d4080dae85
2 changed files with 19 additions and 9 deletions

View File

@ -273,7 +273,7 @@ class AtrealOpenads(BaseResource, HTTPResource):
#~ }
#~ }
)
def check_status(self, *args, **kwargs):
def check_status(self, request=None):
"""Check avaibility of the openADS.API service."""
url = urlparse.urljoin(self.openADS_API_url, '__api__')
response = self.requests.get(url)
@ -286,7 +286,11 @@ class AtrealOpenads(BaseResource, HTTPResource):
pattern='^(?P<type_dossier>\w+)/?$',
example_pattern='{type_dossier}/',
parameters={
'type_dossier': {'description': _("Type of 'dossier'"), 'example_value': 'DIA'}
'type_dossier': {'description': _("Type of 'dossier'"), 'example_value': 'DIA'},
'collectivite': {
'description': _("Use this collectivite (instead of the default one)"),
'example_value': '3'
}
},
post={'description': _("Create an openADS 'dossier'"),
'request_body': {
@ -301,7 +305,7 @@ class AtrealOpenads(BaseResource, HTTPResource):
#~ }
}
)
def create_dossier(self, request, type_dossier, *args, **kwargs):
def create_dossier(self, request, type_dossier, collectivite=None):
# loads the request body as JSON content
json_data = json.loads(request.body)
@ -310,7 +314,7 @@ class AtrealOpenads(BaseResource, HTTPResource):
self.log_json_payload(json_data, 'request')
# build the payload
payload = { "collectivite": self.collectivite }
payload = { "collectivite": int(collectivite) if collectivite else int(self.collectivite) }
payload["terrain"] = {
"numero_voie": normalize(json_data['fields']['terrain_numero_voie']),
@ -550,7 +554,7 @@ class AtrealOpenads(BaseResource, HTTPResource):
#~ }
#~ }
)
def get_dossier(self, request, type_dossier, numero_dossier, *args, **kwargs):
def get_dossier(self, request, type_dossier, numero_dossier):
# make a request to openADS.API
url = urlparse.urljoin(self.openADS_API_url, '/dossier/%s/%s' % (type_dossier, numero_dossier))
@ -608,7 +612,7 @@ class AtrealOpenads(BaseResource, HTTPResource):
#~ }
#~ }
)
def get_fwd_files(self, request, numero_dossier, fichier_id=None, *args, **kwargs):
def get_fwd_files(self, request, numero_dossier, fichier_id=None):
payload = []
fwd_files = []
@ -663,10 +667,10 @@ class AtrealOpenads(BaseResource, HTTPResource):
#~ }
#~ }
)
def get_fwd_files_status(self, request, numero_dossier, fichier_id=None, *args, **kwargs):
def get_fwd_files_status(self, request, numero_dossier, fichier_id=None):
# get all files matching 'numero_dossier' and 'fichier_id'
fwd_files = self.get_fwd_files(request, numero_dossier, fichier_id, *args, **kwargs)
fwd_files = self.get_fwd_files(request, numero_dossier, fichier_id)
# prepare the response payload
payload = {
@ -709,7 +713,7 @@ class AtrealOpenads(BaseResource, HTTPResource):
#~ }
#~ }
)
def get_courrier(self, request, type_dossier, numero_dossier, *args, **kwargs):
def get_courrier(self, request, type_dossier, numero_dossier):
# make a request to openADS.API
url = urlparse.urljoin(

View File

@ -351,6 +351,12 @@ def test_openads_create_dossier(app, atreal_openads):
fake_resp_bad.status_code = 502
fake_resp_bad.reason = 'Bad gateway'
with pytest.raises(ValueError) as e:
with mock.patch('passerelle.utils.Request.post') as requests_post:
requests_post.return_value = fake_resp_bad
atreal_openads.create_dossier(req, 'DIA',collectivite='not an integer')
assert unicode(e.value) == "invalid literal for int() with base 10: 'not an integer'"
with pytest.raises(APIError) as e:
with mock.patch('passerelle.utils.Request.post') as requests_post:
requests_post.return_value = fake_resp_bad