use json_loads() instead of json.loads() (#38781)
json.loads expects str in python >= 3, < 3.6.
This commit is contained in:
parent
5fe94ee3e6
commit
ae09ae97b6
|
@ -15,7 +15,6 @@
|
|||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import json
|
||||
import os
|
||||
import stat
|
||||
import tempfile
|
||||
|
@ -29,6 +28,7 @@ from django.utils.timezone import now
|
|||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from passerelle.base.models import BaseResource
|
||||
from passerelle.compat import json_loads
|
||||
from passerelle.utils.api import endpoint
|
||||
from passerelle.utils.jsonresponse import APIError
|
||||
from passerelle.utils.conversion import ensure_encoding
|
||||
|
@ -52,7 +52,7 @@ class ActesWeb(BaseResource):
|
|||
@endpoint(perm='can_access', methods=['post'], description=_('Create demand'))
|
||||
def create(self, request, *args, **kwargs):
|
||||
try:
|
||||
payload = json.loads(request.body)
|
||||
payload = json_loads(request.body)
|
||||
except (ValueError,):
|
||||
raise APIError('Invalid payload format: json expected')
|
||||
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import bz2
|
||||
import json
|
||||
import unicodedata
|
||||
|
||||
from requests import RequestException
|
||||
|
@ -13,6 +12,7 @@ from django.utils import six
|
|||
from django.utils.six.moves.urllib import parse as urlparse
|
||||
|
||||
from passerelle.base.models import BaseResource
|
||||
from passerelle.compat import json_loads
|
||||
from passerelle.utils.api import endpoint
|
||||
from passerelle.utils.conversion import simplify
|
||||
from passerelle.utils.jsonresponse import APIError
|
||||
|
@ -288,7 +288,7 @@ class BaseAdresse(BaseResource):
|
|||
|
||||
line = _not_found = object()
|
||||
for line in bz2.decompress(ban_file.content).splitlines():
|
||||
street_info = json.loads(line)
|
||||
street_info = json_loads(line)
|
||||
if street_info['type'] == 'street' and street_info['postcode'].startswith(zipcodes):
|
||||
if type(street_info['citycode']) is list:
|
||||
street_info['citycode'] = six.text_type(street_info['citycode'][0])
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
import json
|
||||
|
||||
from django.http import Http404
|
||||
from django.views.generic.base import View
|
||||
from django.views.generic.detail import SingleObjectMixin, DetailView
|
||||
|
||||
from passerelle.compat import json_loads
|
||||
import passerelle.utils as utils
|
||||
|
||||
from .models import Bdp
|
||||
|
@ -41,7 +40,7 @@ class PostAdherentView(View, SingleObjectMixin):
|
|||
@utils.protected_api('can_access')
|
||||
@utils.to_json()
|
||||
def post(self, request, *args, **kwargs):
|
||||
data = json.loads(request.body) # JSON w.c.s. formdata
|
||||
data = json_loads(request.body) # JSON w.c.s. formdata
|
||||
date_de_naissance = data['fields'].get('date_de_naissance')
|
||||
# force 1973-04-18T00:00:00Z
|
||||
date_de_naissance = date_de_naissance[:10] + 'T00:00:00Z'
|
||||
|
|
|
@ -15,12 +15,12 @@
|
|||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import os
|
||||
import json
|
||||
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.core.files.storage import default_storage
|
||||
|
||||
from passerelle.base.models import BaseResource
|
||||
from passerelle.compat import json_loads
|
||||
from passerelle.utils.api import endpoint
|
||||
from passerelle.utils.jsonresponse import APIError
|
||||
|
||||
|
@ -40,7 +40,7 @@ class CityWeb(BaseResource):
|
|||
|
||||
@endpoint(perm='can_access', methods=['post'], description=_('Create a demand'))
|
||||
def create(self, request, *args, **kwargs):
|
||||
payload = json.loads(request.body)
|
||||
payload = json_loads(request.body)
|
||||
# check mandatory keys
|
||||
for key in ('application_id', 'application_time', 'certificate_type'):
|
||||
if key not in payload:
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
import json
|
||||
|
||||
from django.views.generic.base import View
|
||||
from django.views.generic.detail import SingleObjectMixin, DetailView
|
||||
|
||||
from passerelle.compat import json_loads
|
||||
import passerelle.utils as utils
|
||||
|
||||
from passerelle.apps.clicrdv.models import ClicRdv
|
||||
|
@ -85,7 +84,7 @@ class CreateAppointmentView(View, SingleObjectMixin):
|
|||
def post(self, request, intervention_id=None, *args, **kwargs):
|
||||
if intervention_id is None:
|
||||
intervention_id = self.request.GET.get('intervention')
|
||||
data = json.loads(request.body)
|
||||
data = json_loads(request.body)
|
||||
return {'data': self.get_object().create_appointment(
|
||||
intervention_id,
|
||||
self.request.GET.get('websource'),
|
||||
|
|
|
@ -18,7 +18,6 @@ import base64
|
|||
import binascii
|
||||
import functools
|
||||
import httplib2
|
||||
import json
|
||||
import re
|
||||
|
||||
from cmislib import CmisClient
|
||||
|
@ -32,6 +31,7 @@ from django.utils.six import StringIO, text_type
|
|||
from django.utils.six.moves.urllib import error as urllib2
|
||||
|
||||
from passerelle.base.models import BaseResource
|
||||
from passerelle.compat import json_loads
|
||||
from passerelle.utils.api import endpoint
|
||||
from passerelle.utils.jsonresponse import APIError
|
||||
|
||||
|
@ -78,7 +78,7 @@ class CmisConnector(BaseResource):
|
|||
return a tuple (error, error_msg, data)
|
||||
"""
|
||||
try:
|
||||
data = json.loads(body)
|
||||
data = json_loads(body)
|
||||
except ValueError as e:
|
||||
return True, "could not decode body to json: %s" % e, None
|
||||
if 'file' not in data:
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from datetime import date, time
|
||||
import json
|
||||
import os
|
||||
import shutil
|
||||
import sys
|
||||
|
@ -34,6 +33,7 @@ from django.db import models, transaction
|
|||
from django.utils.timezone import make_aware, datetime, get_current_timezone, now, is_naive
|
||||
|
||||
from passerelle.base.models import BaseResource
|
||||
from passerelle.compat import json_loads
|
||||
from passerelle.utils.api import endpoint
|
||||
|
||||
SEXES = (
|
||||
|
@ -187,7 +187,7 @@ class GenericFamily(BaseResource):
|
|||
adults = []
|
||||
|
||||
for f in family_files:
|
||||
family_data = json.loads(archive.read(f))
|
||||
family_data = json_loads(archive.read(f))
|
||||
families.append(family_data['id'])
|
||||
address = family_data.get('address') or {}
|
||||
family_data.update(address)
|
||||
|
@ -366,7 +366,7 @@ class GenericFamily(BaseResource):
|
|||
@endpoint(name='regie', methods=['post'],
|
||||
perm='can_access', pattern='^invoice/(?P<invoice_id>\w+)/pay/$')
|
||||
def pay_invoice(self, request, invoice_id, **kwargs):
|
||||
data = json.loads(request.body)
|
||||
data = json_loads(request.body)
|
||||
invoice = self.get_invoice(invoice_id)
|
||||
if not invoice:
|
||||
return {'data': False}
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
import json
|
||||
import unicodedata
|
||||
|
||||
from django.http import Http404
|
||||
from django.views.generic.base import View
|
||||
from django.views.generic.detail import SingleObjectMixin, DetailView
|
||||
|
||||
from passerelle.compat import json_loads
|
||||
import passerelle.utils as utils
|
||||
|
||||
from .models import Gdc, phpserialize, phpserialize_loads, SOAPpy
|
||||
|
@ -125,7 +125,7 @@ class PostDemandeView(View, SingleObjectMixin):
|
|||
# </wsdl:message>
|
||||
if SOAPpy is None:
|
||||
raise Http404
|
||||
data = json.loads(request.body)
|
||||
data = json_loads(request.body)
|
||||
server = SOAPpy.SOAPProxy(self.get_object().service_url)
|
||||
voie_id = data['fields'].get('voie_raw')
|
||||
voie_str = data['fields'].get('voie')
|
||||
|
|
|
@ -14,7 +14,6 @@
|
|||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import json
|
||||
import uuid
|
||||
|
||||
from django.db import models
|
||||
|
@ -24,6 +23,7 @@ from django.utils.translation import ugettext_lazy as _
|
|||
from jsonfield import JSONField
|
||||
|
||||
from passerelle.base.models import BaseResource
|
||||
from passerelle.compat import json_loads
|
||||
from passerelle.utils.api import endpoint, APIError
|
||||
from passerelle.utils.conversion import simplify
|
||||
|
||||
|
@ -34,7 +34,7 @@ def get_hex_uuid():
|
|||
|
||||
def clean_json_data(data):
|
||||
try:
|
||||
payload = json.loads(data)
|
||||
payload = json_loads(data)
|
||||
if not isinstance(payload, dict):
|
||||
raise APIError('payload must be a dict')
|
||||
return payload
|
||||
|
|
|
@ -16,13 +16,13 @@
|
|||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import os
|
||||
import json
|
||||
|
||||
from django.db import models
|
||||
from django.utils import six
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from passerelle.base.models import BaseResource
|
||||
from passerelle.compat import json_loads
|
||||
from passerelle.utils.api import endpoint
|
||||
from passerelle.utils.jsonresponse import APIError
|
||||
|
||||
|
@ -87,7 +87,7 @@ class MDEL(BaseResource):
|
|||
def create(self, request, *args, **kwargs):
|
||||
"""Create a demand
|
||||
"""
|
||||
formdata = json.loads(request.body)
|
||||
formdata = json_loads(request.body)
|
||||
extra = formdata.pop('extra', {})
|
||||
fields = formdata.pop('fields', {})
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@ from django.http import HttpResponse
|
|||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from passerelle.base.models import BaseResource
|
||||
from passerelle.compat import json_loads
|
||||
from passerelle.utils.api import endpoint
|
||||
from passerelle.utils.jsonresponse import APIError
|
||||
|
||||
|
@ -190,7 +191,7 @@ class Okina(BaseResource):
|
|||
@endpoint(name='subscriber', methods=['post'], perm='can_access')
|
||||
def create_subscriber(self, request):
|
||||
try:
|
||||
payload = json.loads(request.body)
|
||||
payload = json_loads(request.body)
|
||||
except ValueError:
|
||||
raise APIError('payload must be a JSON object', http_status=400)
|
||||
if not isinstance(payload, dict):
|
||||
|
@ -208,7 +209,7 @@ class Okina(BaseResource):
|
|||
qrcode = self.request('subscribers/%s/qrcode' % subscriber_id, result_is_json=False)
|
||||
content_type = qrcode.headers.get('Content-Type')
|
||||
if not (content_type and content_type.startswith('image/')):
|
||||
response = json.loads(qrcode.content)
|
||||
response = json_loads(qrcode.content)
|
||||
raise APIError(response['message'],
|
||||
http_status=response['status'],
|
||||
err=response['code'])
|
||||
|
@ -217,7 +218,7 @@ class Okina(BaseResource):
|
|||
@endpoint(name='subscription', methods=['post'], perm='can_access')
|
||||
def create_subscription(self, request):
|
||||
try:
|
||||
payload = json.loads(request.body)
|
||||
payload = json_loads(request.body)
|
||||
except ValueError:
|
||||
raise APIError('payload must be a JSON object', http_status=400)
|
||||
if not isinstance(payload, dict):
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
import json
|
||||
|
||||
from django.views.generic.base import View
|
||||
from django.views.generic.detail import SingleObjectMixin, DetailView
|
||||
from django.views.generic.edit import UpdateView
|
||||
|
||||
from passerelle.compat import json_loads
|
||||
import passerelle.utils as utils
|
||||
|
||||
from .models import Pastell
|
||||
|
@ -14,7 +13,7 @@ class PostView(View, SingleObjectMixin):
|
|||
|
||||
@utils.protected_api('can_post_document')
|
||||
def post(self, request, *args, **kwargs):
|
||||
data = json.loads(request.body)
|
||||
data = json_loads(request.body)
|
||||
self.get_object().create_document(data)
|
||||
result = {'result': 'ok'}
|
||||
return utils.response_for_json(request, result)
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
|
||||
import base64
|
||||
import copy
|
||||
import json
|
||||
import re
|
||||
import unicodedata
|
||||
|
||||
|
@ -27,6 +26,7 @@ from django.utils.translation import ugettext_lazy as _
|
|||
from django.utils.http import urlencode
|
||||
|
||||
from passerelle.base.models import BaseResource
|
||||
from passerelle.compat import json_loads
|
||||
from passerelle.utils.api import endpoint
|
||||
from passerelle.utils.jsonresponse import APIError
|
||||
from passerelle.utils.conversion import to_pdf
|
||||
|
@ -264,7 +264,7 @@ class Solis(BaseResource):
|
|||
'Solis APA. Payload: name_id, user_id, code'))
|
||||
def apa_link(self, request):
|
||||
try:
|
||||
data = json.loads(request.body)
|
||||
data = json_loads(request.body)
|
||||
except ValueError:
|
||||
raise APIError('payload is not a JSON dict')
|
||||
if not isinstance(data, dict):
|
||||
|
@ -289,7 +289,7 @@ class Solis(BaseResource):
|
|||
description=_('Delete a Solis APA link. Payload: name_id, user_id'))
|
||||
def apa_unlink(self, request):
|
||||
try:
|
||||
data = json.loads(request.body)
|
||||
data = json_loads(request.body)
|
||||
except ValueError:
|
||||
raise APIError('payload is not a JSON dict')
|
||||
if not isinstance(data, dict):
|
||||
|
@ -391,7 +391,7 @@ class Solis(BaseResource):
|
|||
description=_('Send data to "integrationDemandeApa"'))
|
||||
def apa_integration(self, request):
|
||||
try:
|
||||
payload = json.loads(request.body)
|
||||
payload = json_loads(request.body)
|
||||
except ValueError:
|
||||
raise APIError('payload is not a JSON object', http_status=400)
|
||||
if not isinstance(payload, dict):
|
||||
|
@ -533,7 +533,7 @@ class Solis(BaseResource):
|
|||
'Solis RSA. Payload: name_id, user_id, code, dob (optionnal)'))
|
||||
def rsa_link(self, request):
|
||||
try:
|
||||
data = json.loads(request.body)
|
||||
data = json_loads(request.body)
|
||||
except ValueError:
|
||||
raise APIError('payload is not a JSON dict')
|
||||
if not isinstance(data, dict):
|
||||
|
@ -561,7 +561,7 @@ class Solis(BaseResource):
|
|||
description=_('Delete a Solis RSA link. Payload: name_id, user_id'))
|
||||
def rsa_unlink(self, request):
|
||||
try:
|
||||
data = json.loads(request.body)
|
||||
data = json_loads(request.body)
|
||||
except ValueError:
|
||||
raise APIError('payload is not a JSON dict')
|
||||
if not isinstance(data, dict):
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
import json
|
||||
|
||||
from django.utils import six
|
||||
from django.utils.encoding import force_text
|
||||
|
||||
|
||||
def json_loads(value):
|
||||
if six.PY3:
|
||||
value = force_text(value)
|
||||
return json.loads(value)
|
|
@ -14,7 +14,6 @@
|
|||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import json
|
||||
import unicodedata
|
||||
import logging
|
||||
|
||||
|
@ -26,6 +25,7 @@ from django.http import HttpResponse, HttpResponseBadRequest, Http404, HttpRespo
|
|||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.utils.http import urlencode
|
||||
|
||||
from passerelle.compat import json_loads
|
||||
import passerelle.utils as utils
|
||||
|
||||
from .models import AgoraPlus, AgoraPlusLink, AgoraAPIError
|
||||
|
@ -356,7 +356,7 @@ class SasView(DetailView):
|
|||
def post(self, request, *args, **kwargs):
|
||||
self.object = self.get_object()
|
||||
self.set_user_from_request(request)
|
||||
data = json.loads(request.body)
|
||||
data = json_loads(request.body)
|
||||
formdata = Formdata(data)
|
||||
name_id = formdata.get('NameID')
|
||||
if not name_id:
|
||||
|
@ -469,7 +469,7 @@ class PostFormdataView(DetailView):
|
|||
def post(self, request, *args, **kwargs):
|
||||
self.object = self.get_object()
|
||||
self.set_user_from_request(request)
|
||||
data = json.loads(request.body)
|
||||
data = json_loads(request.body)
|
||||
formdata = Formdata(data)
|
||||
return {'data': self.post_data(formdata)}
|
||||
|
||||
|
@ -538,7 +538,7 @@ class PeriscolAddReservationView(DetailView):
|
|||
def post(self, request, *args, **kwargs):
|
||||
self.object = self.get_object()
|
||||
try:
|
||||
data = json.loads(request.body)
|
||||
data = json_loads(request.body)
|
||||
enrollment_id = int(data['enrollment_id'])
|
||||
dates = data['dates']
|
||||
tarif_id = int(data['tarif_id'])
|
||||
|
@ -557,7 +557,7 @@ class PeriscolDeleteReservationsView(DetailView):
|
|||
@utils.protected_api('can_access')
|
||||
def post(self, request, *args, **kwargs):
|
||||
self.object = self.get_object()
|
||||
data = json.loads(request.body)
|
||||
data = json_loads(request.body)
|
||||
return self.object.delete_periscol_enrollment_reservations(data['activity_id'], data['dates'])
|
||||
|
||||
|
||||
|
@ -584,7 +584,7 @@ class InvoicePayView(DetailView):
|
|||
@utils.protected_api('can_access')
|
||||
def post(self, request, *args, **kwargs):
|
||||
self.object = self.get_object()
|
||||
data = json.loads(request.body)
|
||||
data = json_loads(request.body)
|
||||
return {'data': self.object.pay_invoice(kwargs['invoice_id'], data['transaction_id'],
|
||||
data['transaction_date'])}
|
||||
|
||||
|
@ -614,7 +614,7 @@ class DocumentView(DetailView):
|
|||
def post(self, request, *args, **kwargs):
|
||||
self.object = self.get_object()
|
||||
try:
|
||||
data = json.loads(request.body)
|
||||
data = json_loads(request.body)
|
||||
uri = data['uri']
|
||||
content_type = data['content_type']
|
||||
except (ValueError, TypeError, KeyError) as e:
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import base64
|
||||
import json
|
||||
|
||||
from django.conf import settings
|
||||
from django.db import models
|
||||
|
@ -29,6 +28,7 @@ from zeep.exceptions import Fault as WebFault
|
|||
from zeep.helpers import serialize_object
|
||||
|
||||
from passerelle.base.models import BaseResource
|
||||
from passerelle.compat import json_loads
|
||||
from passerelle.utils.api import endpoint
|
||||
from passerelle.utils.jsonresponse import APIError
|
||||
from passerelle.utils.conversion import to_pdf
|
||||
|
@ -262,7 +262,7 @@ class DPark(BaseResource):
|
|||
|
||||
@endpoint(perm='can_access', methods=['post'], description=_('Register a subscription application'))
|
||||
def register(self, request, *args, **kwargs):
|
||||
data = json.loads(request.body)
|
||||
data = json_loads(request.body)
|
||||
is_erroneous(
|
||||
data, (
|
||||
'application_id', 'applicant_title', 'applicant_lastname', 'applicant_firstnames',
|
||||
|
@ -312,7 +312,7 @@ class DPark(BaseResource):
|
|||
|
||||
@endpoint(perm='can_access', methods=['post'], description=_('Link user to a subscription'))
|
||||
def link(self, request, *args, **kwargs):
|
||||
data = json.loads(request.body)
|
||||
data = json_loads(request.body)
|
||||
if 'nameid' not in data:
|
||||
raise WrongParameter(['nameid'], [])
|
||||
result = self.check_file_exists(data)
|
||||
|
@ -326,7 +326,7 @@ class DPark(BaseResource):
|
|||
|
||||
@endpoint(perm='can_access', methods=['post'], description=_('Unlink user to subscription'))
|
||||
def unlink(self, request, *args, **kwargs):
|
||||
data = json.loads(request.body)
|
||||
data = json_loads(request.body)
|
||||
is_erroneous(data, ('nameid',))
|
||||
pairings = Pairing.objects.filter(**data)
|
||||
if pairings.exists() is False:
|
||||
|
@ -406,7 +406,7 @@ class DPark(BaseResource):
|
|||
|
||||
@endpoint(name='notify-payment', perm='can_access', methods=['post'], description=_('Notify a payment'))
|
||||
def payment_notification(self, request, *args, **kwargs):
|
||||
data = json.loads(request.body)
|
||||
data = json_loads(request.body)
|
||||
is_erroneous(
|
||||
data,
|
||||
('nameid', 'filenumber',
|
||||
|
@ -436,7 +436,7 @@ class DPark(BaseResource):
|
|||
@endpoint(name='send-files', perm='can_access', methods=['post'], description=_('Send supporting documents'))
|
||||
def send_files(self, request, *args, **kwargs):
|
||||
try:
|
||||
data = json.loads(request.body)
|
||||
data = json_loads(request.body)
|
||||
except ValueError as exc:
|
||||
raise APIError(str(exc), http_status=400)
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@ from django.utils.six import string_types
|
|||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from passerelle.base.models import BaseResource
|
||||
from passerelle.compat import json_loads
|
||||
from passerelle.utils.api import endpoint
|
||||
from passerelle.utils.jsonresponse import APIError
|
||||
|
||||
|
@ -235,7 +236,7 @@ class Gdema(BaseResource):
|
|||
methods=['post'], perm='can_access')
|
||||
def create_request(self, request):
|
||||
try:
|
||||
payload = json.loads(request.body)
|
||||
payload = json_loads(request.body)
|
||||
except ValueError:
|
||||
raise APIError('payload must be a JSON object', http_status=400)
|
||||
if not isinstance(payload, dict):
|
||||
|
|
|
@ -14,7 +14,6 @@
|
|||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import json
|
||||
import re
|
||||
|
||||
from django.db import models
|
||||
|
@ -23,6 +22,7 @@ from django.utils.text import slugify
|
|||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from passerelle.base.models import BaseResource
|
||||
from passerelle.compat import json_loads
|
||||
from passerelle.utils.api import endpoint
|
||||
|
||||
COMMUNE_EXTRA_MAPPING = {
|
||||
|
@ -85,7 +85,7 @@ class GrandLyonStreetSections(BaseResource):
|
|||
update_start = timezone.now()
|
||||
sections = self.requests.get(
|
||||
'https://download.data.grandlyon.com/ws/grandlyon/adr_voie_lieu.adraxevoie/all.json?maxfeatures=1000000').content
|
||||
for value in json.loads(sections).get('values'):
|
||||
for value in json_loads(sections).get('values'):
|
||||
section, created = StreetSection.objects.get_or_create(
|
||||
codefuv=value.get('codefuv'),
|
||||
codetroncon=value.get('codetroncon'))
|
||||
|
|
|
@ -14,7 +14,6 @@
|
|||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import base64
|
||||
import json
|
||||
import re
|
||||
|
||||
from email import encoders
|
||||
|
@ -35,6 +34,7 @@ from django.utils.translation import ugettext_lazy as _
|
|||
from django.core.cache import cache
|
||||
|
||||
from passerelle.base.models import BaseResource
|
||||
from passerelle.compat import json_loads
|
||||
from passerelle.utils.api import endpoint, APIError
|
||||
from passerelle.soap import sudsobject_to_dict
|
||||
|
||||
|
@ -198,7 +198,7 @@ class Greco(BaseResource):
|
|||
def create(self, request):
|
||||
# get creation fields from payload
|
||||
try:
|
||||
formdata = FormData(json.loads(request.body), CREATION_SCHEMA)
|
||||
formdata = FormData(json_loads(request.body), CREATION_SCHEMA)
|
||||
except ValueError as e:
|
||||
raise ParameterTypeError(str(e))
|
||||
# create suds object from formdata
|
||||
|
@ -244,7 +244,7 @@ class Greco(BaseResource):
|
|||
methods=['get', 'post', 'put', 'patch'])
|
||||
def add_information(self, request, iddemande=None, idgreco=None, information=None):
|
||||
if request.body:
|
||||
payload = json.loads(request.body)
|
||||
payload = json_loads(request.body)
|
||||
if not isinstance(payload, dict):
|
||||
raise ParameterTypeError('payload must be a dict')
|
||||
idgreco = payload.get('idgreco') or idgreco
|
||||
|
@ -263,7 +263,7 @@ class Greco(BaseResource):
|
|||
methods=['get', 'post', 'put', 'patch'])
|
||||
def update(self, request, iddemande=None, idgreco=None, comment=None):
|
||||
if request.body:
|
||||
payload = json.loads(request.body)
|
||||
payload = json_loads(request.body)
|
||||
if not isinstance(payload, dict):
|
||||
raise ParameterTypeError('payload must be a dict')
|
||||
idgreco = payload.get('idgreco') or idgreco
|
||||
|
|
|
@ -14,8 +14,6 @@
|
|||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import json
|
||||
|
||||
from lxml import etree
|
||||
|
||||
from django.core.cache import cache
|
||||
|
@ -26,6 +24,7 @@ from django.utils.http import urlencode
|
|||
from django.utils.six.moves.urllib import parse as urlparse
|
||||
|
||||
from passerelle.base.models import BaseResource
|
||||
from passerelle.compat import json_loads
|
||||
from passerelle.utils.api import endpoint
|
||||
from passerelle.utils.jsonresponse import APIError
|
||||
from passerelle.views import WrongParameter
|
||||
|
@ -184,7 +183,7 @@ class GrenobleGRU(BaseResource):
|
|||
@endpoint(name='create-demand', perm='can_access', methods=['post'], description=_('Create a demand'))
|
||||
def create_demand(self, request, *args, **kwargs):
|
||||
try:
|
||||
payload = self.build_gru_params(json.loads(request.body))
|
||||
payload = self.build_gru_params(json_loads(request.body))
|
||||
except (KeyError, ValueError) as e:
|
||||
raise APIError(e)
|
||||
response = self.request('ws_creation_demande.php', payload)
|
||||
|
@ -195,7 +194,7 @@ class GrenobleGRU(BaseResource):
|
|||
@endpoint(name='demand', perm='can_access', methods=['post'], description=_('Add attachment to a demand'),
|
||||
pattern=r'(?P<demand_id>[\w-]+)/add-attachment/$',)
|
||||
def add_attachment_to_demand(self, request, demand_id, **kwargs):
|
||||
data = json.loads(request.body)
|
||||
data = json_loads(request.body)
|
||||
if 'file' not in data:
|
||||
raise WrongParameter(['file'], [])
|
||||
file_data = data['file']
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import json
|
||||
import re
|
||||
|
||||
from django.db import models
|
||||
|
@ -24,6 +23,7 @@ from django.utils.six.moves.urllib_parse import urljoin
|
|||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from passerelle.base.models import BaseResource
|
||||
from passerelle.compat import json_loads
|
||||
from passerelle.utils.api import endpoint
|
||||
from passerelle.utils.http_authenticators import HttpBearerAuth
|
||||
from passerelle.utils.jsonresponse import APIError
|
||||
|
@ -82,7 +82,7 @@ class LilleUrbanCard(BaseResource):
|
|||
|
||||
@endpoint(perm='can_access', description=_('Card Request'), methods=['post'])
|
||||
def card_request(self, request, *args, **kwargs):
|
||||
data = json.loads(request.body)
|
||||
data = json_loads(request.body)
|
||||
for kind_of_optional_field in ('nom_naissance', 'telephone', 'complement_numero_voie'):
|
||||
if not data.get(kind_of_optional_field):
|
||||
data[kind_of_optional_field] = ''
|
||||
|
|
|
@ -14,7 +14,6 @@
|
|||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import json
|
||||
import requests
|
||||
from datetime import datetime
|
||||
import logging
|
||||
|
@ -24,6 +23,7 @@ from django.utils.decorators import method_decorator
|
|||
from django.utils.six.moves.urllib import parse as urlparse
|
||||
from django.views.decorators.csrf import csrf_exempt
|
||||
|
||||
from passerelle.compat import json_loads
|
||||
import passerelle.utils as utils
|
||||
from passerelle.soap import sudsobject_to_dict, client_to_jsondict
|
||||
|
||||
|
@ -72,7 +72,7 @@ class ResourceView(DetailView):
|
|||
@utils.protected_api('can_access')
|
||||
def post(self, request, *args, **kwargs):
|
||||
client = self.get_client()
|
||||
formdata = json.loads(request.body)
|
||||
formdata = json_loads(request.body)
|
||||
extras = formdata.get('extra', {})
|
||||
|
||||
debug = 'debug' in request.GET
|
||||
|
|
|
@ -14,11 +14,10 @@
|
|||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import json
|
||||
|
||||
from django.views.generic import DetailView as GenericDetailView, View
|
||||
from django.views.decorators.csrf import csrf_exempt
|
||||
|
||||
from passerelle.compat import json_loads
|
||||
import passerelle.utils as utils
|
||||
|
||||
from .models import MeyzieuNewsletters
|
||||
|
@ -69,7 +68,7 @@ class NewslettersSubscriptionsView(DetailView):
|
|||
def post(self, request, *args, **kwargs):
|
||||
email = request.GET.get('email')
|
||||
assert email, 'missing email parameter'
|
||||
data = json.loads(request.body)
|
||||
data = json_loads(request.body)
|
||||
return {'data': self.get_object().set_subscriptions(email, data)}
|
||||
|
||||
def get_data(self, request, *args, **kwargs):
|
||||
|
|
|
@ -14,12 +14,11 @@
|
|||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import json
|
||||
|
||||
from django.views.generic import DetailView as GenericDetailView
|
||||
from django.utils.decorators import method_decorator
|
||||
from django.views.decorators.csrf import csrf_exempt
|
||||
|
||||
from passerelle.compat import json_loads
|
||||
import passerelle.utils as utils
|
||||
from passerelle.soap import sudsobject_to_dict, client_to_jsondict
|
||||
|
||||
|
@ -64,7 +63,7 @@ class ResourceView(DetailView):
|
|||
@utils.protected_api('can_access')
|
||||
def post(self, request, *args, **kwargs):
|
||||
client = self.get_client()
|
||||
formdata = json.loads(request.body)
|
||||
formdata = json_loads(request.body)
|
||||
fields = formdata.get('fields', {})
|
||||
extras = formdata.get('extra', {})
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@ from django.utils.translation import ugettext_lazy as _
|
|||
from django.http import HttpResponse
|
||||
|
||||
from passerelle.base.models import BaseResource
|
||||
from passerelle.compat import json_loads
|
||||
from passerelle.contrib.solis_apa import conciliation, suivi, integration
|
||||
|
||||
HEADERS = {
|
||||
|
@ -315,7 +316,7 @@ class SolisAPA(BaseResource):
|
|||
uri = 'importFlow?flow=ImportIntegrationDemande&application=%s' %APPLICATION
|
||||
url = self.get_resource_url(uri)
|
||||
|
||||
data = {'ImportInputWSDemandeApa': integration.build_message(json.loads(data))}
|
||||
data = {'ImportInputWSDemandeApa': integration.build_message(json_loads(data))}
|
||||
data = json.dumps(data)
|
||||
self.logger.debug('Demande APA: %s' % data, extra={'solis_apa_demande': data})
|
||||
response = self.requests.post(url, data=data, headers=HEADERS)
|
||||
|
|
|
@ -15,7 +15,6 @@
|
|||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import datetime
|
||||
import json
|
||||
|
||||
from django.db import models
|
||||
from django.utils.encoding import force_text
|
||||
|
@ -23,6 +22,7 @@ from django.utils.six.moves.urllib import parse as urlparse
|
|||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from passerelle.base.models import BaseResource
|
||||
from passerelle.compat import json_loads
|
||||
from passerelle.utils.api import endpoint, APIError
|
||||
|
||||
|
||||
|
@ -49,7 +49,7 @@ class StrasbourgEu(BaseResource):
|
|||
if name_id is None:
|
||||
raise APIError('missing name_id')
|
||||
# expected content: {"interests": ["123", "456"]}
|
||||
response = json.loads(request.body)
|
||||
response = json_loads(request.body)
|
||||
if 'error ' in response:
|
||||
return {'err': 1, 'err_desc': response.get('error')}
|
||||
interests = response.get('interests')
|
||||
|
@ -102,7 +102,7 @@ class StrasbourgEu(BaseResource):
|
|||
else:
|
||||
# expected content: {"title": ..., "description": ..., "url": ...,
|
||||
# ...}, cf https://strasbourgeurometropole.github.io/slate/#ajout-d-39-une-notification
|
||||
notification = json.loads(request.body)
|
||||
notification = json_loads(request.body)
|
||||
notification['userId'] = name_id
|
||||
url = urlparse.urljoin(self.liferay_api_url, 'jsonws/notification.notification/add-notification')
|
||||
response = self.requests.post(url, data=notification).json()
|
||||
|
@ -128,7 +128,7 @@ class StrasbourgEu(BaseResource):
|
|||
else:
|
||||
# expected content: {"title": ..., "url": ..., ...},
|
||||
# cf https://strasbourgeurometropole.github.io/slate/?shell#ajout-d-39-un-favori
|
||||
favorite = json.loads(request.body)
|
||||
favorite = json_loads(request.body)
|
||||
# change type to typeId
|
||||
types_url = urlparse.urljoin(self.liferay_api_url, 'jsonws/favorite.favorite/get-types')
|
||||
types = self.requests.get(types_url).json()
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
|
||||
import base64
|
||||
from datetime import datetime
|
||||
import json
|
||||
import logging
|
||||
import xml.etree.ElementTree as ET
|
||||
|
||||
|
@ -29,6 +28,7 @@ from django.utils.encoding import smart_text
|
|||
from jsonfield import JSONField
|
||||
|
||||
from passerelle.base.models import BaseResource
|
||||
from passerelle.compat import json_loads
|
||||
from passerelle.soap import client_to_jsondict
|
||||
from passerelle.utils.api import endpoint
|
||||
from passerelle.utils.jsonresponse import APIError
|
||||
|
@ -316,7 +316,7 @@ class TeamnetAxel(BaseResource):
|
|||
@endpoint(name='regie', methods=['post'],
|
||||
perm='can_access', pattern='^(?P<regie_id>\w+)/invoice/(?P<invoice_id>[\w,-]+)/pay/$')
|
||||
def pay_invoice(self, request, regie_id, invoice_id, **kwargs):
|
||||
data = json.loads(request.body)
|
||||
data = json_loads(request.body)
|
||||
transaction_id = data.get('transaction_id')
|
||||
transaction_date = data.get('transaction_date')
|
||||
email = data.get('email')
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
import base64
|
||||
import copy
|
||||
import datetime
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
import re
|
||||
|
@ -33,6 +32,7 @@ from django.utils.translation import ugettext_lazy as _
|
|||
import xmlschema
|
||||
|
||||
from passerelle.base.models import BaseResource
|
||||
from passerelle.compat import json_loads
|
||||
from passerelle.utils.api import endpoint
|
||||
from passerelle.utils.jsonresponse import APIError
|
||||
from passerelle.utils.xml import JSONSchemaFromXMLSchema
|
||||
|
@ -959,7 +959,7 @@ class ToulouseAxel(BaseResource):
|
|||
}
|
||||
})
|
||||
def pay_invoice(self, request, regie_id, invoice_id, **kwargs):
|
||||
data = json.loads(request.body)
|
||||
data = json_loads(request.body)
|
||||
dui, invoice_id = invoice_id.split('-')
|
||||
|
||||
invoice = self.get_invoice(regie_id=regie_id, dui=dui, invoice_id=invoice_id)
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
import json
|
||||
import logging
|
||||
import re
|
||||
|
||||
from django.utils import six
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from passerelle.compat import json_loads
|
||||
from passerelle.utils.api import endpoint
|
||||
from passerelle.utils.jsonresponse import APIError
|
||||
|
||||
|
@ -40,7 +40,7 @@ class SMSGatewayMixin(object):
|
|||
@endpoint(perm='can_send_messages', methods=['post'])
|
||||
def send(self, request, *args, **kwargs):
|
||||
try:
|
||||
data = json.loads(request.body)
|
||||
data = json_loads(request.body)
|
||||
assert isinstance(data, dict), 'JSON payload is not a dict'
|
||||
assert 'message' in data, 'missing "message" in JSON payload'
|
||||
assert 'from' in data, 'missing "from" in JSON payload'
|
||||
|
|
|
@ -46,6 +46,7 @@ from dateutil import parser as date_parser
|
|||
from jsonschema import validate, ValidationError
|
||||
|
||||
from passerelle.base.models import BaseResource, ResourceLog
|
||||
from passerelle.compat import json_loads
|
||||
from passerelle.utils.jsonresponse import APIError
|
||||
from passerelle.utils.json import unflatten
|
||||
|
||||
|
@ -350,7 +351,7 @@ class GenericEndpointView(GenericConnectorMixin, SingleObjectMixin, View):
|
|||
merge_extra = hasattr(json_schema, 'items') and json_schema.get('merge_extra', False)
|
||||
pre_process = hasattr(json_schema, 'items') and json_schema.get('pre_process')
|
||||
try:
|
||||
data = json.loads(request.body)
|
||||
data = json_loads(request.body)
|
||||
except ValueError as e:
|
||||
raise APIError("could not decode body to json: %s" % e, http_status=400)
|
||||
if must_unflatten:
|
||||
|
|
|
@ -36,7 +36,7 @@ def get_test_base_dir(name):
|
|||
|
||||
def get_file_from_test_base_dir(filename):
|
||||
path = os.path.join(get_test_base_dir('actesweb'), filename)
|
||||
with open(path, 'rb') as fd:
|
||||
with open(path, 'r') as fd:
|
||||
return fd.read()
|
||||
|
||||
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import os
|
||||
import json
|
||||
|
||||
import pytest
|
||||
import mock
|
||||
|
@ -9,6 +8,7 @@ from django.core.urlresolvers import reverse
|
|||
from django.contrib.contenttypes.models import ContentType
|
||||
|
||||
from passerelle.apps.arcgis.models import ArcGIS
|
||||
from passerelle.compat import json_loads
|
||||
from passerelle.base.models import ApiUser, AccessRight
|
||||
|
||||
|
||||
|
@ -23,7 +23,7 @@ def get_file_content(filename):
|
|||
class MockedRequestsResponse(mock.Mock):
|
||||
|
||||
def json(self):
|
||||
return json.loads(self.content)
|
||||
return json_loads(self.content)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
|
|
@ -13,6 +13,7 @@ from django.core.files.storage import default_storage
|
|||
from django.test import override_settings
|
||||
|
||||
from passerelle.apps.cartads_cs.models import CartaDSCS, CartaDSFile, CartaDSDossier
|
||||
from passerelle.compat import json_loads
|
||||
from passerelle.base.models import Job
|
||||
|
||||
import utils
|
||||
|
@ -655,11 +656,11 @@ def test_role_sync(connector, app, cached_data):
|
|||
assert url.netloc == 'idp.example.org'
|
||||
if url.path == '/api/roles/':
|
||||
dossier = CartaDSDossier.objects.all().first()
|
||||
assert json.loads(request.body) == json.loads(
|
||||
assert json_loads(request.body) == json.loads(
|
||||
'{"name": "Suivi Cart@DS (%s)", "slug": "_cartads_%s"}' % (dossier.id, dossier.id))
|
||||
return {'content': json.dumps({'uuid': 'role-uuid'}), 'status_code': 200}
|
||||
elif url.path == '/api/roles/role-uuid/relationships/members/':
|
||||
body = json.loads(request.body)
|
||||
body = json_loads(request.body)
|
||||
idp_mock.subscribed_roles = set([x['uuid'] for x in body['data']])
|
||||
return {'content': json.dumps({'err': 0}), 'status_code': 200}
|
||||
raise Exception('unhandled http call (%s)' % url)
|
||||
|
|
|
@ -41,7 +41,7 @@ def get_test_base_dir(name):
|
|||
|
||||
def get_file_from_test_base_dir(filename):
|
||||
path = os.path.join(get_test_base_dir('cityweb'), filename)
|
||||
with open(path, 'rb') as fd:
|
||||
with open(path, 'r') as fd:
|
||||
return fd.read()
|
||||
|
||||
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import json
|
||||
import os
|
||||
import time
|
||||
import pytest
|
||||
|
@ -34,6 +33,7 @@ from django.utils.six import StringIO
|
|||
from django.utils.six.moves.urllib.parse import urlencode
|
||||
|
||||
from passerelle.base.models import ApiUser, AccessRight
|
||||
from passerelle.compat import json_loads
|
||||
from passerelle.apps.csvdatasource.models import CsvDataSource, Query, TableRow
|
||||
|
||||
from test_manager import login, admin_user
|
||||
|
@ -107,7 +107,7 @@ def setup():
|
|||
|
||||
|
||||
def parse_response(response):
|
||||
return json.loads(response.content)['data']
|
||||
return json_loads(response.content)['data']
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
@ -327,7 +327,7 @@ def test_on_the_fly_dialect_detection(client, setup):
|
|||
csvdata, url = setup(data=StringIO(data))
|
||||
CsvDataSource.objects.all().update(_dialect_options=None)
|
||||
resp = client.get(url)
|
||||
result = json.loads(resp.content)
|
||||
result = json_loads(resp.content)
|
||||
assert result['err'] == 0
|
||||
assert len(result['data']) == 20
|
||||
|
||||
|
@ -335,7 +335,7 @@ def test_on_the_fly_dialect_detection(client, setup):
|
|||
def test_missing_columns(client, setup):
|
||||
csvdata, url = setup(data=StringIO(data + 'A;B;C\n'))
|
||||
resp = client.get(url)
|
||||
result = json.loads(resp.content)
|
||||
result = json_loads(resp.content)
|
||||
assert result['err'] == 0
|
||||
assert len(result['data']) == 21
|
||||
assert result['data'][-1] == {'lname': 'C', 'sex': None, 'id': 'B', 'fname': None, 'fam': 'A'}
|
||||
|
@ -346,20 +346,20 @@ def test_unknown_sheet_name(client, setup):
|
|||
csvdata.sheet_name = 'unknown'
|
||||
csvdata.save()
|
||||
resp = client.get(url)
|
||||
result = json.loads(resp.content)
|
||||
result = json_loads(resp.content)
|
||||
assert len(result['data']) == 20
|
||||
|
||||
|
||||
def test_cache_new_shorter_file(client, setup):
|
||||
csvdata, url = setup(data=StringIO(data + 'A;B;C\n'))
|
||||
resp = client.get(url)
|
||||
result = json.loads(resp.content)
|
||||
result = json_loads(resp.content)
|
||||
assert result['err'] == 0
|
||||
assert len(result['data']) == 21
|
||||
csvdata.csv_file = File(StringIO(data), 'data.csv')
|
||||
csvdata.save()
|
||||
resp = client.get(url)
|
||||
result = json.loads(resp.content)
|
||||
result = json_loads(resp.content)
|
||||
assert len(result['data']) == 20
|
||||
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@ from django.utils.encoding import force_bytes, force_text
|
|||
from django.utils.six import BytesIO, StringIO
|
||||
|
||||
from passerelle.base.models import ApiUser, AccessRight
|
||||
from passerelle.compat import json_loads
|
||||
from passerelle.utils import import_site, export_site
|
||||
|
||||
data = """121;69981;DELANOUE;Eliot;H
|
||||
|
@ -76,7 +77,7 @@ def setup():
|
|||
|
||||
|
||||
def parse_response(response):
|
||||
return json.loads(response.content)['data']
|
||||
return json_loads(response.content)['data']
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
@ -122,7 +123,7 @@ def test_export_csvdatasource(app, setup, filetype):
|
|||
assert first == second
|
||||
|
||||
output = get_output_of_command('export_site')
|
||||
third = json.loads(output)
|
||||
third = json_loads(output)
|
||||
third['resources'][0]['csv_file']['name'] = 'whocares'
|
||||
assert first == third
|
||||
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
import logging
|
||||
import pytest
|
||||
import json
|
||||
|
||||
from django.test.client import RequestFactory
|
||||
from django.http import Http404
|
||||
from django.core.exceptions import ObjectDoesNotExist, PermissionDenied
|
||||
|
||||
|
||||
from passerelle.compat import json_loads
|
||||
from passerelle.utils import to_json
|
||||
|
||||
|
||||
class WrappedException(Exception):
|
||||
pass
|
||||
|
||||
|
@ -96,7 +96,7 @@ def test_jsonresponse_log_as_warning_exception(caplog):
|
|||
assert record.method == 'GET'
|
||||
assert "Error occurred while processing request" in record.message
|
||||
assert response.status_code == 488
|
||||
data = json.loads(response.content)
|
||||
data = json_loads(response.content)
|
||||
assert data['err'] == 'logaswarningexception'
|
||||
assert data['err_desc'] == 'log as warning exception'
|
||||
|
||||
|
@ -110,7 +110,7 @@ def test_jsonresponse_error_header():
|
|||
|
||||
result = test_func(req)
|
||||
assert result.status_code == 200
|
||||
data = json.loads(result.content)
|
||||
data = json_loads(result.content)
|
||||
assert data == {'test': 'un test', 'err': 0}
|
||||
@to_json()
|
||||
def test_func(req):
|
||||
|
@ -119,7 +119,7 @@ def test_jsonresponse_error_header():
|
|||
raise CustomException
|
||||
|
||||
result = test_func(req)
|
||||
data = json.loads(result.content)
|
||||
data = json_loads(result.content)
|
||||
assert 'err_class' in data
|
||||
assert 'err' in data
|
||||
assert data['err'] == 1
|
||||
|
@ -141,7 +141,7 @@ def test_jsonresponse_with_callback():
|
|||
content_type = result.get('Content-Type')
|
||||
assert 'application/javascript' in content_type
|
||||
assert result.content.startswith(b'myfunc(')
|
||||
args = json.loads(result.content[7:-2])
|
||||
args = json_loads(result.content[7:-2])
|
||||
assert args == {'foo': 'bar', 'err': 0}
|
||||
|
||||
def test_jsonresponse_with_wrong_callback():
|
||||
|
|
|
@ -5,6 +5,7 @@ import json
|
|||
import mock
|
||||
import pytest
|
||||
|
||||
from passerelle.compat import json_loads
|
||||
from passerelle.contrib.lille_urban_card.models import LilleUrbanCard
|
||||
from passerelle.utils.jsonresponse import APIError
|
||||
|
||||
|
@ -29,7 +30,7 @@ def mocked_http(url, request):
|
|||
if url.path == '/clu/ws/demanderCarte':
|
||||
content = {
|
||||
'n_demande_clu': 10000005,
|
||||
'request': json.loads(request.body), # for tests
|
||||
'request': json_loads(request.body), # for tests
|
||||
}
|
||||
return {'content': json.dumps(content), 'status_code': 200}
|
||||
if url.path.startswith('/clu/ws/consulterDemande/'):
|
||||
|
|
|
@ -18,7 +18,6 @@ from __future__ import unicode_literals
|
|||
|
||||
import shutil
|
||||
import os
|
||||
import json
|
||||
import base64
|
||||
import copy
|
||||
import zipfile
|
||||
|
@ -31,6 +30,7 @@ import pytest
|
|||
from passerelle.apps.mdel.models import MDEL, Demand
|
||||
from passerelle.apps.mdel.mdel import Message, Description, AttachedFile, get_resource_base_dir
|
||||
from passerelle.apps.mdel.utils import parse_date
|
||||
from passerelle.compat import json_loads
|
||||
|
||||
import utils
|
||||
|
||||
|
@ -69,15 +69,15 @@ def setup(db):
|
|||
|
||||
|
||||
@pytest.fixture(params=[
|
||||
json.loads(get_file_from_test_base_dir('formdata_aec_naiss.json')),
|
||||
json.loads(get_file_from_test_base_dir('formdata_aec_mariage.json')),
|
||||
json.loads(get_file_from_test_base_dir('formdata_aec_deces.json')),
|
||||
json_loads(get_file_from_test_base_dir('formdata_aec_naiss.json')),
|
||||
json_loads(get_file_from_test_base_dir('formdata_aec_mariage.json')),
|
||||
json_loads(get_file_from_test_base_dir('formdata_aec_deces.json')),
|
||||
], ids=['naissance', 'mariage', 'deces'])
|
||||
def aec_payload(request):
|
||||
return request.param
|
||||
|
||||
|
||||
ILE_PAYLOAD = json.loads(get_file_from_test_base_dir('formdata.json'))
|
||||
ILE_PAYLOAD = json_loads(get_file_from_test_base_dir('formdata.json'))
|
||||
|
||||
|
||||
def test_message():
|
||||
|
@ -306,7 +306,7 @@ def test_create_aec_demand_type(app, setup, aec_payload):
|
|||
|
||||
|
||||
def test_create_aec_demand_type_without_date_acte(app, setup):
|
||||
payload = json.loads(get_file_from_test_base_dir('formdata_aec_deces.json'))
|
||||
payload = json_loads(get_file_from_test_base_dir('formdata_aec_deces.json'))
|
||||
payload['fields'].pop('date_acte')
|
||||
resp = app.post_json('/mdel/test/create', params=payload, status=200)
|
||||
assert resp.json['err_desc'] == '<date_acte> is required'
|
||||
|
@ -391,13 +391,13 @@ def test_create_ile_demand_type(app, setup):
|
|||
|
||||
def test_create_ile_demand_type_invalid_document_proof(app, setup):
|
||||
# test with missing key
|
||||
payload = json.loads(get_file_from_test_base_dir('formdata.json'))
|
||||
payload = json_loads(get_file_from_test_base_dir('formdata.json'))
|
||||
payload['fields'].pop('justificatif_domicile_hebergeur')
|
||||
resp = app.post_json('/mdel/test/create', params=payload, status=200)
|
||||
assert resp.json['err_desc'] == 'justificatif_domicile and all its attributes are required'
|
||||
|
||||
# test with invalid content
|
||||
payload = json.loads(get_file_from_test_base_dir('formdata.json'))
|
||||
payload = json_loads(get_file_from_test_base_dir('formdata.json'))
|
||||
payload['fields']['justificatif_identite'] = None
|
||||
payload['fields']['justificatif_identite_verso'] = None
|
||||
resp = app.post_json('/mdel/test/create', params=payload, status=200)
|
||||
|
@ -534,7 +534,7 @@ def test_date_parsing():
|
|||
|
||||
|
||||
def test_aec_filenames_and_routing(app, setup):
|
||||
aec_payload = json.loads(get_file_from_test_base_dir('formdata_aec_naiss.json'))
|
||||
aec_payload = json_loads(get_file_from_test_base_dir('formdata_aec_naiss.json'))
|
||||
resp = app.post_json('/mdel/test/create', params=aec_payload, status=200)
|
||||
|
||||
assert resp.json['data']['demand_id'] == '15-4-AEC-LA'
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
import json
|
||||
|
||||
import pytest
|
||||
|
||||
from django.core.files import File
|
||||
|
@ -10,6 +8,7 @@ from django.utils.six import StringIO
|
|||
|
||||
from passerelle.base.models import ApiUser, AccessRight
|
||||
|
||||
from passerelle.compat import json_loads
|
||||
from passerelle.contrib.nancypoll.models import NancyPoll
|
||||
|
||||
data = """
|
||||
|
@ -33,7 +32,7 @@ data = """
|
|||
|
||||
|
||||
def parse_response(response):
|
||||
return json.loads(response.content)['data']
|
||||
return json_loads(response.content)['data']
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
@ -53,7 +52,7 @@ def setup(db):
|
|||
def test_failure(setup):
|
||||
url, client = setup
|
||||
qs = {'street_no': '37000', 'street_name': 'Rue du Marechal Juin'}
|
||||
resp = json.loads(client.get(url, qs).content)
|
||||
resp = json_loads(client.get(url, qs).content)
|
||||
assert resp['err_desc'] == 'Polling Station Not Found'
|
||||
assert int(resp['err']) != 0
|
||||
|
||||
|
@ -63,8 +62,8 @@ def test_no_params(setup):
|
|||
qs = {}
|
||||
resp = client.get(url, qs)
|
||||
assert resp.status_code == 200
|
||||
assert json.loads(resp.content)['err_desc'] == 'All parameters are required'
|
||||
assert int(json.loads(resp.content)['err']) != 0
|
||||
assert json_loads(resp.content)['err_desc'] == 'All parameters are required'
|
||||
assert int(json_loads(resp.content)['err']) != 0
|
||||
|
||||
|
||||
def test_invalid_street_no(setup):
|
||||
|
@ -72,8 +71,8 @@ def test_invalid_street_no(setup):
|
|||
qs = {'street_no': 'lol', 'street_name': 'whatever'}
|
||||
resp = client.get(url, qs)
|
||||
assert resp.status_code == 200
|
||||
assert json.loads(resp.content)['err_desc'] == 'Invalid street no value'
|
||||
assert int(json.loads(resp.content)['err']) != 0
|
||||
assert json_loads(resp.content)['err_desc'] == 'Invalid street no value'
|
||||
assert int(json_loads(resp.content)['err']) != 0
|
||||
|
||||
|
||||
def test_success_i_side(setup):
|
||||
|
|
|
@ -8,6 +8,7 @@ from django.core.urlresolvers import reverse
|
|||
from django.utils.six.moves.urllib import parse as urlparse
|
||||
|
||||
from passerelle.base.models import ApiUser, AccessRight
|
||||
from passerelle.compat import json_loads
|
||||
|
||||
|
||||
def generic_endpoint_url(connector, endpoint, slug='test'):
|
||||
|
@ -27,7 +28,7 @@ def setup_access_rights(obj):
|
|||
class FakedResponse(mock.Mock):
|
||||
|
||||
def json(self):
|
||||
return json.loads(self.content)
|
||||
return json_loads(self.content)
|
||||
|
||||
|
||||
def mock_url(url=None, response='', status_code=200, headers=None):
|
||||
|
|
Loading…
Reference in New Issue