Added 'collectivite' param to 'create_dossier()' endpoint, removed useless '*args' and '**kwargs'
This commit is contained in:
parent
98cd089254
commit
d4080dae85
|
@ -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."""
|
"""Check avaibility of the openADS.API service."""
|
||||||
url = urlparse.urljoin(self.openADS_API_url, '__api__')
|
url = urlparse.urljoin(self.openADS_API_url, '__api__')
|
||||||
response = self.requests.get(url)
|
response = self.requests.get(url)
|
||||||
|
@ -286,7 +286,11 @@ class AtrealOpenads(BaseResource, HTTPResource):
|
||||||
pattern='^(?P<type_dossier>\w+)/?$',
|
pattern='^(?P<type_dossier>\w+)/?$',
|
||||||
example_pattern='{type_dossier}/',
|
example_pattern='{type_dossier}/',
|
||||||
parameters={
|
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'"),
|
post={'description': _("Create an openADS 'dossier'"),
|
||||||
'request_body': {
|
'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
|
# loads the request body as JSON content
|
||||||
json_data = json.loads(request.body)
|
json_data = json.loads(request.body)
|
||||||
|
@ -310,7 +314,7 @@ class AtrealOpenads(BaseResource, HTTPResource):
|
||||||
self.log_json_payload(json_data, 'request')
|
self.log_json_payload(json_data, 'request')
|
||||||
|
|
||||||
# build the payload
|
# build the payload
|
||||||
payload = { "collectivite": self.collectivite }
|
payload = { "collectivite": int(collectivite) if collectivite else int(self.collectivite) }
|
||||||
|
|
||||||
payload["terrain"] = {
|
payload["terrain"] = {
|
||||||
"numero_voie": normalize(json_data['fields']['terrain_numero_voie']),
|
"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
|
# make a request to openADS.API
|
||||||
url = urlparse.urljoin(self.openADS_API_url, '/dossier/%s/%s' % (type_dossier, numero_dossier))
|
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 = []
|
payload = []
|
||||||
fwd_files = []
|
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'
|
# 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
|
# prepare the response payload
|
||||||
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
|
# make a request to openADS.API
|
||||||
url = urlparse.urljoin(
|
url = urlparse.urljoin(
|
||||||
|
|
|
@ -351,6 +351,12 @@ def test_openads_create_dossier(app, atreal_openads):
|
||||||
fake_resp_bad.status_code = 502
|
fake_resp_bad.status_code = 502
|
||||||
fake_resp_bad.reason = 'Bad gateway'
|
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 pytest.raises(APIError) as e:
|
||||||
with mock.patch('passerelle.utils.Request.post') as requests_post:
|
with mock.patch('passerelle.utils.Request.post') as requests_post:
|
||||||
requests_post.return_value = fake_resp_bad
|
requests_post.return_value = fake_resp_bad
|
||||||
|
|
Reference in New Issue