utils: rename utils.LoggedRequest as utils.Request (#20789)
... because it will not only used for logging.
This commit is contained in:
parent
c190ba3985
commit
f6a14c375b
|
@ -157,7 +157,7 @@ class BaseResource(models.Model):
|
|||
|
||||
@property
|
||||
def requests(self):
|
||||
return passerelle.utils.LoggedRequest(logger=self.logger)
|
||||
return passerelle.utils.Request(logger=self.logger)
|
||||
|
||||
@classmethod
|
||||
def get_verbose_name(cls):
|
||||
|
|
|
@ -179,7 +179,7 @@ MELLON_IDENTITY_PROVIDERS = []
|
|||
# see http://docs.python-requests.org/en/latest/user/advanced/#proxies
|
||||
REQUESTS_PROXIES = None
|
||||
|
||||
# List of LoggedRequest Response Content-Type to log
|
||||
# List of passerelle.utils.Request response Content-Type to log
|
||||
LOGGED_CONTENT_TYPES_MESSAGES = (
|
||||
r'text/', r'application/(json|xml)'
|
||||
)
|
||||
|
|
|
@ -152,11 +152,11 @@ def content_type_match(ctype):
|
|||
# Wrapper around requests.Session
|
||||
# logging requests input and output data
|
||||
|
||||
class LoggedRequest(RequestSession):
|
||||
class Request(RequestSession):
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
self.logger = kwargs.pop('logger')
|
||||
super(LoggedRequest, self).__init__(*args, **kwargs)
|
||||
super(Request, self).__init__(*args, **kwargs)
|
||||
|
||||
def request(self, method, url, **kwargs):
|
||||
params = kwargs.get('params', '')
|
||||
|
@ -166,7 +166,7 @@ class LoggedRequest(RequestSession):
|
|||
|
||||
kwargs['proxies'] = kwargs.get('proxies') or settings.REQUESTS_PROXIES
|
||||
|
||||
response = super(LoggedRequest, self).request(method, url, **kwargs)
|
||||
response = super(Request, self).request(method, url, **kwargs)
|
||||
|
||||
self.logger.debug('Request Headers: {}'.format(''.join([
|
||||
'%s: %s | ' % (k,v) for k,v in response.request.headers.items()
|
||||
|
|
|
@ -32,7 +32,7 @@ def connector(db):
|
|||
sector_type='secteur_maternelle'))
|
||||
|
||||
|
||||
@mock.patch('passerelle.utils.LoggedRequest.get')
|
||||
@mock.patch('passerelle.utils.Request.get')
|
||||
def test_feature_info(mocked_get, app, connector):
|
||||
endpoint = utils.generic_endpoint_url('adict', 'feature_info', slug=connector.slug)
|
||||
assert endpoint == '/adict/test/feature_info'
|
||||
|
@ -44,7 +44,7 @@ def test_feature_info(mocked_get, app, connector):
|
|||
assert resp.json['data']['nom'] == 'NEUFELD'
|
||||
|
||||
|
||||
@mock.patch('passerelle.utils.LoggedRequest.get')
|
||||
@mock.patch('passerelle.utils.Request.get')
|
||||
def test_no_feature_info(mocked_get, app, connector):
|
||||
endpoint = utils.generic_endpoint_url('adict', 'feature_info', slug=connector.slug)
|
||||
assert endpoint == '/adict/test/feature_info'
|
||||
|
|
|
@ -47,7 +47,7 @@ def airquality(db):
|
|||
def test_airquality_details(app, airquality):
|
||||
endpoint = utils.generic_endpoint_url('airquality', 'details', slug=airquality.slug)
|
||||
assert endpoint == '/airquality/atmo/details'
|
||||
with mock.patch('passerelle.utils.LoggedRequest.get') as requests_get:
|
||||
with mock.patch('passerelle.utils.Request.get') as requests_get:
|
||||
requests_get.return_value = mock.Mock(content=SAMPLE_RESPONSE, status_code=200)
|
||||
resp = app.get(endpoint + '/fr/lyon/', status=200)
|
||||
assert resp.json['data']['latest']['value'] == '4'
|
||||
|
|
|
@ -48,7 +48,7 @@ def test_get_district_parameters_error(app, setup, url):
|
|||
assert resp.json['err_desc'] == '<lon> and <lat> must be floats'
|
||||
|
||||
|
||||
@mock.patch('passerelle.utils.LoggedRequest.get')
|
||||
@mock.patch('passerelle.utils.Request.get')
|
||||
def test_get_district(mocked_get, app, setup, url):
|
||||
mocked_get.return_value = MockedRequestsResponse(
|
||||
content=get_file_content('sigresponse.json'),
|
||||
|
@ -60,7 +60,7 @@ def test_get_district(mocked_get, app, setup, url):
|
|||
assert data['text'] == 'HAUSSONVILLE / BLANDAN / MON DESERT / SAURUPT'
|
||||
|
||||
|
||||
@mock.patch('passerelle.utils.LoggedRequest.get')
|
||||
@mock.patch('passerelle.utils.Request.get')
|
||||
def test_get_all_district(mocked_get, app, setup, url):
|
||||
mocked_get.return_value = MockedRequestsResponse(
|
||||
content=get_file_content('all_districts.json'),
|
||||
|
|
|
@ -28,7 +28,7 @@ def street(db):
|
|||
type=u'street',
|
||||
citycode=u'73001')
|
||||
|
||||
@mock.patch('passerelle.utils.LoggedRequest.get')
|
||||
@mock.patch('passerelle.utils.Request.get')
|
||||
def test_base_adresse_search(mocked_get, app, base_adresse):
|
||||
endpoint = utils.generic_endpoint_url('base-adresse', 'search', slug=base_adresse.slug)
|
||||
assert endpoint == '/base-adresse/base-adresse/search'
|
||||
|
@ -39,7 +39,7 @@ def test_base_adresse_search(mocked_get, app, base_adresse):
|
|||
assert data['lon'] == '-0.593775'
|
||||
assert data['display_name'] == 'Rue Roger Halope 49000 Angers'
|
||||
|
||||
@mock.patch('passerelle.utils.LoggedRequest.get')
|
||||
@mock.patch('passerelle.utils.Request.get')
|
||||
def test_base_adresse_search_path(mocked_get, app, base_adresse):
|
||||
base_adresse.service_url = 'http://example.net/path/'
|
||||
base_adresse.save()
|
||||
|
@ -80,7 +80,7 @@ def test_base_adresse_reverse(app, base_adresse, mock_api_adresse_data_gouv_fr_r
|
|||
resp = app.get('/base-adresse/%s/reverse?lon=-0.593775&lat=47.474633' % base_adresse.slug)
|
||||
assert 'display_name' in resp.json
|
||||
|
||||
@mock.patch('passerelle.utils.LoggedRequest.get')
|
||||
@mock.patch('passerelle.utils.Request.get')
|
||||
def test_base_adresse_reverse_path(mocked_get, app, base_adresse):
|
||||
mocked_get.return_value = utils.FakedResponse(content=json.dumps({'features': []}), status_code=200)
|
||||
base_adresse.service_url = 'http://example.net/path/'
|
||||
|
@ -112,7 +112,7 @@ def test_base_adresse_streets_unaccent(app, base_adresse, street):
|
|||
assert result['zipcode'] == street.zipcode
|
||||
assert result['id'] == street.id
|
||||
|
||||
@mock.patch('passerelle.utils.LoggedRequest.get')
|
||||
@mock.patch('passerelle.utils.Request.get')
|
||||
def test_base_adresse_command_update(mocked_get, db, base_adresse):
|
||||
filepath = os.path.join(os.path.dirname(__file__), 'data', 'update_streets_test.bz2')
|
||||
mocked_get.return_value = utils.FakedResponse(content=open(filepath).read(), status_code=200)
|
||||
|
|
|
@ -45,7 +45,7 @@ FEED_EXAMPLE = u"""<?xml version="1.0" encoding="UTF-8"?>
|
|||
def connector(db):
|
||||
return utils.setup_access_rights(Feed.objects.create( slug='test', url='http://example.net/'))
|
||||
|
||||
@mock.patch('passerelle.utils.LoggedRequest.get')
|
||||
@mock.patch('passerelle.utils.Request.get')
|
||||
def test_feed(mocked_get, app, connector):
|
||||
mocked_get.return_value = utils.FakedResponse(content=FEED_EXAMPLE, status=200)
|
||||
endpoint = utils.generic_endpoint_url('feeds', 'json', slug=connector.slug)
|
||||
|
|
|
@ -78,7 +78,7 @@ def gdema(db):
|
|||
def test_gdema_services_and_typologies(app, gdema):
|
||||
endpoint = utils.generic_endpoint_url('gdema', 'referentiel', slug=gdema.slug)
|
||||
assert endpoint == '/gdema/test/referentiel'
|
||||
with mock.patch('passerelle.utils.LoggedRequest.get') as requests_get:
|
||||
with mock.patch('passerelle.utils.Request.get') as requests_get:
|
||||
requests_get.return_value = utils.FakedResponse(content=SERVICES,
|
||||
status_code=200)
|
||||
resp = app.get(endpoint + '/service/', status=200)
|
||||
|
@ -114,7 +114,7 @@ def test_gdema_services_and_typologies(app, gdema):
|
|||
def test_gdema_referentiel(app, gdema):
|
||||
endpoint = utils.generic_endpoint_url('gdema', 'referentiel', slug=gdema.slug)
|
||||
assert endpoint == '/gdema/test/referentiel'
|
||||
with mock.patch('passerelle.utils.LoggedRequest.get') as requests_get:
|
||||
with mock.patch('passerelle.utils.Request.get') as requests_get:
|
||||
requests_get.return_value = utils.FakedResponse(content=CIVILITY,
|
||||
status_code=200)
|
||||
resp = app.get(endpoint + '/civility/', status=200)
|
||||
|
@ -126,7 +126,7 @@ def test_gdema_referentiel(app, gdema):
|
|||
assert resp.json['data'][0]['id'] == '1'
|
||||
assert resp.json['data'][0]['text'] == 'Monsieur'
|
||||
|
||||
with mock.patch('passerelle.utils.LoggedRequest.get') as requests_get:
|
||||
with mock.patch('passerelle.utils.Request.get') as requests_get:
|
||||
requests_get.return_value = utils.FakedResponse(content='404', status_code=404)
|
||||
resp = app.get(endpoint + '/nothing/', status=200)
|
||||
assert requests_get.call_count == 1
|
||||
|
@ -141,7 +141,7 @@ def test_gdema_referentiel(app, gdema):
|
|||
def test_gdema_get_request(app, gdema):
|
||||
endpoint = utils.generic_endpoint_url('gdema', 'get-request', slug=gdema.slug)
|
||||
assert endpoint == '/gdema/test/get-request'
|
||||
with mock.patch('passerelle.utils.LoggedRequest.get') as requests_get:
|
||||
with mock.patch('passerelle.utils.Request.get') as requests_get:
|
||||
requests_get.return_value = utils.FakedResponse(content=REQUEST,
|
||||
status_code=200)
|
||||
resp = app.get(endpoint + '/1/', status=200)
|
||||
|
@ -159,7 +159,7 @@ def test_gdema_get_request(app, gdema):
|
|||
|
||||
endpoint = utils.generic_endpoint_url('gdema', 'get-request-state', slug=gdema.slug)
|
||||
assert endpoint == '/gdema/test/get-request-state'
|
||||
with mock.patch('passerelle.utils.LoggedRequest.get') as requests_get:
|
||||
with mock.patch('passerelle.utils.Request.get') as requests_get:
|
||||
requests_get.return_value = utils.FakedResponse(content=REQUEST_STATE,
|
||||
status_code=200)
|
||||
resp = app.get(endpoint + '/1/', status=200)
|
||||
|
@ -173,7 +173,7 @@ def test_gdema_get_request(app, gdema):
|
|||
def test_gdema_create_request(app, gdema):
|
||||
endpoint = utils.generic_endpoint_url('gdema', 'create-request', slug=gdema.slug)
|
||||
assert endpoint == '/gdema/test/create-request'
|
||||
with mock.patch('passerelle.utils.LoggedRequest.post') as requests_post:
|
||||
with mock.patch('passerelle.utils.Request.post') as requests_post:
|
||||
requests_post.return_value = utils.FakedResponse(content=REQUEST,
|
||||
status_code=200)
|
||||
resp = app.post_json(endpoint + '?raise=1', params=CREATE_INPUT, status=200)
|
||||
|
|
|
@ -77,7 +77,7 @@ def test_generic_payload_logging(caplog, app, mdel):
|
|||
assert record.connector_endpoint_url == '/mdel/test/status?demand_id=1-14-ILE-LA'
|
||||
|
||||
|
||||
@mock.patch('passerelle.utils.LoggedRequest.get')
|
||||
@mock.patch('passerelle.utils.Request.get')
|
||||
def test_proxy_logger(mocked_get, caplog, app, arcgis):
|
||||
payload = file(os.path.join(os.path.dirname(__file__), 'data', 'nancy_arcgis', 'sigresponse.json')).read()
|
||||
mocked_get.return_value = utils.FakedResponse(content=payload, status_code=200)
|
||||
|
|
|
@ -74,8 +74,8 @@ def test_call_ping_connectionerror(soap_client, app, conn):
|
|||
assert resp.json['data'] == None
|
||||
assert 'mocked error' in resp.json['err_desc']
|
||||
|
||||
@mock.patch('passerelle.utils.LoggedRequest.get')
|
||||
@mock.patch('passerelle.utils.LoggedRequest.post')
|
||||
@mock.patch('passerelle.utils.Request.get')
|
||||
@mock.patch('passerelle.utils.Request.post')
|
||||
@mock.patch('passerelle.contrib.iparapheur.soap.HttpAuthenticated.open')
|
||||
def test_create_file(http_open, mocked_post, mocked_get, app, conn, xmlmime, wsdl_file):
|
||||
file_id = str(uuid.uuid4())
|
||||
|
@ -117,8 +117,8 @@ def test_create_file(http_open, mocked_post, mocked_get, app, conn, xmlmime, wsd
|
|||
assert resp.json['data']['RecordId'] == file_id
|
||||
|
||||
|
||||
@mock.patch('passerelle.utils.LoggedRequest.get')
|
||||
@mock.patch('passerelle.utils.LoggedRequest.post')
|
||||
@mock.patch('passerelle.utils.Request.get')
|
||||
@mock.patch('passerelle.utils.Request.post')
|
||||
@mock.patch('passerelle.contrib.iparapheur.soap.HttpAuthenticated.open')
|
||||
def get_get_files(http_open, mocked_post, mocked_get, app, conn, xmlmime, wsdl_file):
|
||||
soap_response = """
|
||||
|
@ -140,8 +140,8 @@ def get_get_files(http_open, mocked_post, mocked_get, app, conn, xmlmime, wsdl_f
|
|||
assert item['timestamp']
|
||||
|
||||
|
||||
@mock.patch('passerelle.utils.LoggedRequest.get')
|
||||
@mock.patch('passerelle.utils.LoggedRequest.post')
|
||||
@mock.patch('passerelle.utils.Request.get')
|
||||
@mock.patch('passerelle.utils.Request.post')
|
||||
@mock.patch('passerelle.contrib.iparapheur.soap.HttpAuthenticated.open')
|
||||
def test_get_file_status(http_open, mocked_post, mocked_get, app, conn, xmlmime, wsdl_file):
|
||||
file_id = str(uuid.uuid4())
|
||||
|
@ -171,8 +171,8 @@ def test_get_file_status(http_open, mocked_post, mocked_get, app, conn, xmlmime,
|
|||
'2016-04-05T17:58:46.727+02:00', # suds 0.7
|
||||
)
|
||||
|
||||
@mock.patch('passerelle.utils.LoggedRequest.get')
|
||||
@mock.patch('passerelle.utils.LoggedRequest.post')
|
||||
@mock.patch('passerelle.utils.Request.get')
|
||||
@mock.patch('passerelle.utils.Request.post')
|
||||
@mock.patch('passerelle.contrib.iparapheur.soap.HttpAuthenticated.open')
|
||||
def test_get_file(http_open, mocked_post, mocked_get, app, conn, xmlmime, wsdl_file):
|
||||
file_id = str(uuid.uuid4())
|
||||
|
@ -195,8 +195,8 @@ def test_get_file(http_open, mocked_post, mocked_get, app, conn, xmlmime, wsdl_f
|
|||
assert 'filename=test.pdf' in resp.headers['Content-Disposition']
|
||||
assert resp.body == 'Test Document'
|
||||
|
||||
@mock.patch('passerelle.utils.LoggedRequest.get')
|
||||
@mock.patch('passerelle.utils.LoggedRequest.post')
|
||||
@mock.patch('passerelle.utils.Request.get')
|
||||
@mock.patch('passerelle.utils.Request.post')
|
||||
@mock.patch('passerelle.contrib.iparapheur.soap.HttpAuthenticated.open')
|
||||
def test_get_file_invalid_appendix(http_open, mocked_post, mocked_get, app, conn, xmlmime, wsdl_file):
|
||||
file_id = str(uuid.uuid4())
|
||||
|
@ -217,8 +217,8 @@ def test_get_file_invalid_appendix(http_open, mocked_post, mocked_get, app, conn
|
|||
assert resp.json['err'] == 1
|
||||
assert resp.json['err_desc'] == 'invalid appendix index'
|
||||
|
||||
@mock.patch('passerelle.utils.LoggedRequest.get')
|
||||
@mock.patch('passerelle.utils.LoggedRequest.post')
|
||||
@mock.patch('passerelle.utils.Request.get')
|
||||
@mock.patch('passerelle.utils.Request.post')
|
||||
@mock.patch('passerelle.contrib.iparapheur.soap.HttpAuthenticated.open')
|
||||
def test_get_file_not_found_appendix(http_open, mocked_post, mocked_get, app, conn, xmlmime, wsdl_file):
|
||||
file_id = str(uuid.uuid4())
|
||||
|
@ -239,8 +239,8 @@ def test_get_file_not_found_appendix(http_open, mocked_post, mocked_get, app, co
|
|||
assert resp.json['err'] == 1
|
||||
assert resp.json['err_desc'] == 'unknown appendix'
|
||||
|
||||
@mock.patch('passerelle.utils.LoggedRequest.get')
|
||||
@mock.patch('passerelle.utils.LoggedRequest.post')
|
||||
@mock.patch('passerelle.utils.Request.get')
|
||||
@mock.patch('passerelle.utils.Request.post')
|
||||
@mock.patch('passerelle.contrib.iparapheur.soap.HttpAuthenticated.open')
|
||||
def test_get_file_appendix(http_open, mocked_post, mocked_get, app, conn, xmlmime, wsdl_file):
|
||||
file_id = str(uuid.uuid4())
|
||||
|
@ -264,8 +264,8 @@ def test_get_file_appendix(http_open, mocked_post, mocked_get, app, conn, xmlmim
|
|||
assert resp.body == 'Test Document Appendix'
|
||||
|
||||
|
||||
@mock.patch('passerelle.utils.LoggedRequest.get')
|
||||
@mock.patch('passerelle.utils.LoggedRequest.post')
|
||||
@mock.patch('passerelle.utils.Request.get')
|
||||
@mock.patch('passerelle.utils.Request.post')
|
||||
@mock.patch('passerelle.contrib.iparapheur.soap.HttpAuthenticated.open')
|
||||
def test_invalid_response(http_open, mocked_post, mocked_get, app, conn, xmlmime, wsdl_file):
|
||||
file_id = str(uuid.uuid4())
|
||||
|
@ -282,8 +282,8 @@ def test_invalid_response(http_open, mocked_post, mocked_get, app, conn, xmlmime
|
|||
assert resp.json['err_desc'] == "Transport Error: (502, u'Bad Gateway')"
|
||||
|
||||
|
||||
@mock.patch('passerelle.utils.LoggedRequest.get')
|
||||
@mock.patch('passerelle.utils.LoggedRequest.post')
|
||||
@mock.patch('passerelle.utils.Request.get')
|
||||
@mock.patch('passerelle.utils.Request.post')
|
||||
@mock.patch('passerelle.contrib.iparapheur.soap.HttpAuthenticated.open')
|
||||
def test_webfault_response(http_open, mocked_post, mocked_get, app, conn, xmlmime, wsdl_file):
|
||||
file_id = str(uuid.uuid4())
|
||||
|
|
|
@ -6,7 +6,7 @@ from httmock import urlmatch, HTTMock, response
|
|||
|
||||
from django.test import override_settings
|
||||
|
||||
from passerelle.utils import LoggedRequest
|
||||
from passerelle.utils import Request
|
||||
import utils
|
||||
from utils import FakedResponse
|
||||
|
||||
|
@ -24,14 +24,14 @@ def httpbin_mock(url, request):
|
|||
def test_log_level(caplog, log_level):
|
||||
url = 'https://httpbin.org/post'
|
||||
|
||||
logger = logging.getLogger('logged_requests')
|
||||
logger = logging.getLogger('requests')
|
||||
logger.setLevel(getattr(logging, log_level))
|
||||
|
||||
with HTTMock(httpbin_mock):
|
||||
requests = LoggedRequest(logger=logger)
|
||||
requests = Request(logger=logger)
|
||||
response = requests.post(url, json={'name':'josh'})
|
||||
|
||||
records = [ record for record in caplog.records if record.name == 'logged_requests' ]
|
||||
records = [record for record in caplog.records if record.name == 'requests']
|
||||
|
||||
records_length = len(records)
|
||||
|
||||
|
@ -90,11 +90,11 @@ def endpoint_response(request):
|
|||
@mock.patch('passerelle.utils.RequestSession.request')
|
||||
def test_skip_content_type(mocked_get, caplog, endpoint_response):
|
||||
mocked_get.return_value = endpoint_response
|
||||
logger = logging.getLogger('logged_requests')
|
||||
logger = logging.getLogger('requests')
|
||||
logger.setLevel(logging.DEBUG)
|
||||
requests = LoggedRequest(logger=logger)
|
||||
requests = Request(logger=logger)
|
||||
requests.get('http://example.net/whatever')
|
||||
records = [record for record in caplog.records if record.name == 'logged_requests']
|
||||
records = [record for record in caplog.records if record.name == 'requests']
|
||||
|
||||
if 'xml' in endpoint_response.headers.get('Content-Type'):
|
||||
assert len(records) == 5
|
||||
|
@ -108,16 +108,16 @@ def test_skip_content_type(mocked_get, caplog, endpoint_response):
|
|||
@mock.patch('passerelle.utils.RequestSession.request')
|
||||
def test_proxies(mocked_get, caplog, endpoint_response):
|
||||
mocked_get.return_value = endpoint_response
|
||||
logger = logging.getLogger('logged_requests')
|
||||
LoggedRequest(logger=logger).get('http://example.net/whatever')
|
||||
logger = logging.getLogger('requests')
|
||||
Request(logger=logger).get('http://example.net/whatever')
|
||||
assert mocked_get.call_args[1].get('proxies') is None
|
||||
LoggedRequest(logger=logger).get('http://example.net/whatever',
|
||||
Request(logger=logger).get('http://example.net/whatever',
|
||||
proxies={'http': 'http://proxy'})
|
||||
assert mocked_get.call_args[1].get('proxies') == {'http': 'http://proxy'}
|
||||
|
||||
with override_settings(REQUESTS_PROXIES={'http': 'http://globalproxy'}):
|
||||
LoggedRequest(logger=logger).get('http://example.net/whatever')
|
||||
Request(logger=logger).get('http://example.net/whatever')
|
||||
assert mocked_get.call_args[1].get('proxies') == {'http': 'http://globalproxy'}
|
||||
LoggedRequest(logger=logger).get('http://example.net/whatever',
|
||||
Request(logger=logger).get('http://example.net/whatever',
|
||||
proxies={'http': 'http://proxy'})
|
||||
assert mocked_get.call_args[1].get('proxies') == {'http': 'http://proxy'}
|
||||
|
|
|
@ -1342,7 +1342,7 @@ def okina(db):
|
|||
def test_okina_cities(app, okina):
|
||||
endpoint = utils.generic_endpoint_url('okina', 'cities', slug=okina.slug)
|
||||
assert endpoint == '/okina/test/cities'
|
||||
with mock.patch('passerelle.utils.LoggedRequest.get') as requests_get:
|
||||
with mock.patch('passerelle.utils.Request.get') as requests_get:
|
||||
requests_get.return_value = utils.FakedResponse(content=CITIES,
|
||||
status_code=200)
|
||||
resp = app.get(endpoint, status=200)
|
||||
|
@ -1359,7 +1359,7 @@ def test_okina_cities(app, okina):
|
|||
def test_okina_classes(app, okina):
|
||||
endpoint = utils.generic_endpoint_url('okina', 'classes', slug=okina.slug)
|
||||
assert endpoint == '/okina/test/classes'
|
||||
with mock.patch('passerelle.utils.LoggedRequest.get') as requests_get:
|
||||
with mock.patch('passerelle.utils.Request.get') as requests_get:
|
||||
requests_get.return_value = utils.FakedResponse(content=CLASSES,
|
||||
status_code=200)
|
||||
resp = app.get(endpoint, status=200)
|
||||
|
@ -1373,7 +1373,7 @@ def test_okina_classes(app, okina):
|
|||
def test_okina_institutions(app, okina):
|
||||
endpoint = utils.generic_endpoint_url('okina', 'institutions', slug=okina.slug)
|
||||
assert endpoint == '/okina/test/institutions'
|
||||
with mock.patch('passerelle.utils.LoggedRequest.get') as requests_get:
|
||||
with mock.patch('passerelle.utils.Request.get') as requests_get:
|
||||
requests_get.return_value = utils.FakedResponse(content=INSTITUTIONS,
|
||||
status_code=200)
|
||||
resp = app.get(endpoint, status=200)
|
||||
|
@ -1393,7 +1393,7 @@ def test_okina_institutions(app, okina):
|
|||
def test_okina_stops_area(app, okina):
|
||||
endpoint = utils.generic_endpoint_url('okina', 'stop-areas', slug=okina.slug)
|
||||
assert endpoint == '/okina/test/stop-areas'
|
||||
with mock.patch('passerelle.utils.LoggedRequest.get') as requests_get:
|
||||
with mock.patch('passerelle.utils.Request.get') as requests_get:
|
||||
requests_get.return_value = utils.FakedResponse(content=STOPS,
|
||||
status_code=200)
|
||||
resp = app.get(endpoint + '/from-city/36005/to-institution/276/', status=200)
|
||||
|
@ -1406,7 +1406,7 @@ def test_okina_stops_area(app, okina):
|
|||
def test_okina_ods(app, okina):
|
||||
endpoint = utils.generic_endpoint_url('okina', 'origin-destinations', slug=okina.slug)
|
||||
assert endpoint == '/okina/test/origin-destinations'
|
||||
with mock.patch('passerelle.utils.LoggedRequest.get') as requests_get:
|
||||
with mock.patch('passerelle.utils.Request.get') as requests_get:
|
||||
requests_get.return_value = utils.FakedResponse(content=ODS, status_code=200)
|
||||
resp = app.get(endpoint, status=200)
|
||||
assert requests_get.call_count == 1
|
||||
|
@ -1474,7 +1474,7 @@ def test_okina_ods(app, okina):
|
|||
def test_okina_topology(app, okina):
|
||||
endpoint = utils.generic_endpoint_url('okina', 'topology', slug=okina.slug)
|
||||
assert endpoint == '/okina/test/topology'
|
||||
with mock.patch('passerelle.utils.LoggedRequest.get') as requests_get:
|
||||
with mock.patch('passerelle.utils.Request.get') as requests_get:
|
||||
requests_get.return_value = utils.FakedResponse(content=LINES, status_code=200)
|
||||
resp = app.get(endpoint + '/lines/', status=200)
|
||||
assert requests_get.call_args[0][0] == 'https://okina.example.net/b2b/topology/lines'
|
||||
|
@ -1500,7 +1500,7 @@ def test_okina_topology(app, okina):
|
|||
assert resp.json['data'][0]['text'] == u'019 02 - VELLES LYCEES DE CHATEAUROUX'
|
||||
|
||||
def test_okina_errors(app, okina):
|
||||
with mock.patch('passerelle.utils.LoggedRequest.get') as requests_get:
|
||||
with mock.patch('passerelle.utils.Request.get') as requests_get:
|
||||
for response in ((200, '{"foo": "bar"}'), # not a list
|
||||
(200, '{["foo": "bar"]}'), # list of malformatted dict
|
||||
(200, '<h1>Welcome</h1>'), # bad json
|
||||
|
@ -1519,7 +1519,7 @@ def test_okina_suscribe(app, okina):
|
|||
for service in ('subscriber', 'subscription'):
|
||||
endpoint = utils.generic_endpoint_url('okina', service, slug=okina.slug)
|
||||
assert endpoint == '/okina/test/%s' % service
|
||||
with mock.patch('passerelle.utils.LoggedRequest.get') as requests_get:
|
||||
with mock.patch('passerelle.utils.Request.get') as requests_get:
|
||||
resp = app.post(endpoint, status=403)
|
||||
assert requests_get.call_count == 0
|
||||
assert resp.json['err'] == 1
|
||||
|
@ -1532,7 +1532,7 @@ def test_okina_suscribe(app, okina):
|
|||
for service in ('subscriber', 'subscription'):
|
||||
endpoint = utils.generic_endpoint_url('okina', service, slug=okina.slug)
|
||||
assert endpoint == '/okina/test/%s' % service
|
||||
with mock.patch('passerelle.utils.LoggedRequest.post') as requests_get:
|
||||
with mock.patch('passerelle.utils.Request.post') as requests_get:
|
||||
resp = app.post(endpoint, status=400) # no payload
|
||||
assert requests_get.call_count == 0
|
||||
assert resp.json['err'] == 1
|
||||
|
@ -1553,7 +1553,7 @@ def test_okina_suscribe(app, okina):
|
|||
|
||||
# qrcode
|
||||
endpoint = '/okina/test/subscriber/123/qrcode'
|
||||
with mock.patch('passerelle.utils.LoggedRequest.get') as requests_get:
|
||||
with mock.patch('passerelle.utils.Request.get') as requests_get:
|
||||
requests_get.return_value = utils.FakedResponse(content='PNGfoo',
|
||||
headers={'Content-Type': 'image/png'},
|
||||
status_code=200)
|
||||
|
|
|
@ -112,7 +112,7 @@ def geoserver_responses(url, **kwargs):
|
|||
return utils.FakedResponse(status_code=200, content=FAKE_SERVICE_CAPABILITIES)
|
||||
return utils.FakedResponse(status_code=200, content=FAKE_FEATURES_JSON)
|
||||
|
||||
@mock.patch('passerelle.utils.LoggedRequest.get')
|
||||
@mock.patch('passerelle.utils.Request.get')
|
||||
def test_feature_info(mocked_get, app, connector):
|
||||
endpoint = utils.generic_endpoint_url('opengis', 'feature_info', slug=connector.slug)
|
||||
assert endpoint == '/opengis/test/feature_info'
|
||||
|
@ -120,7 +120,7 @@ def test_feature_info(mocked_get, app, connector):
|
|||
resp = app.get(endpoint, params={'lat': '45.796890', 'lon': '4.784140'})
|
||||
assert resp.json['data']['cad_cadastrecadparcelle_layer']['cad_cadastrecadparcelle_feature']['natureproprietaire'] == 'Particulier'
|
||||
|
||||
@mock.patch('passerelle.utils.LoggedRequest.get')
|
||||
@mock.patch('passerelle.utils.Request.get')
|
||||
def test_tile(mocked_get, app, connector):
|
||||
endpoint = utils.generic_endpoint_url('opengis', 'tile', slug=connector.slug)
|
||||
assert endpoint == '/opengis/test/tile'
|
||||
|
@ -129,7 +129,7 @@ def test_tile(mocked_get, app, connector):
|
|||
assert resp.content == '\x89PNG\r\n\x1a\n\x00\x00...'
|
||||
|
||||
|
||||
@mock.patch('passerelle.utils.LoggedRequest.get')
|
||||
@mock.patch('passerelle.utils.Request.get')
|
||||
def test_get_feature_with_no_wfs_url(mocked_get, app, connector):
|
||||
connector.wfs_service_url = ''
|
||||
connector.save()
|
||||
|
@ -142,7 +142,7 @@ def test_get_feature_with_no_wfs_url(mocked_get, app, connector):
|
|||
assert resp.json['err'] == 1
|
||||
assert resp.json['err_desc'] == 'no wfs URL declared'
|
||||
|
||||
@mock.patch('passerelle.utils.LoggedRequest.get')
|
||||
@mock.patch('passerelle.utils.Request.get')
|
||||
def test_get_feature(mocked_get, app, connector):
|
||||
endpoint = utils.generic_endpoint_url('opengis', 'features', slug=connector.slug)
|
||||
assert endpoint == '/opengis/test/features'
|
||||
|
@ -158,7 +158,7 @@ def test_get_feature(mocked_get, app, connector):
|
|||
for item in resp.json['data']:
|
||||
assert 'text' in item
|
||||
|
||||
@mock.patch('passerelle.utils.LoggedRequest.get')
|
||||
@mock.patch('passerelle.utils.Request.get')
|
||||
def test_get_filtered_feature(mocked_get, app, connector):
|
||||
endpoint = utils.generic_endpoint_url('opengis', 'features', slug=connector.slug)
|
||||
mocked_get.side_effect = geoserver_responses
|
||||
|
@ -166,7 +166,7 @@ def test_get_filtered_feature(mocked_get, app, connector):
|
|||
'property_name': 'nom', 'cql_filter': 'nom=\'Fontaine\''})
|
||||
assert mocked_get.call_args[1]['params']['CQL_FILTER'] == 'nom=\'Fontaine\''
|
||||
|
||||
@mock.patch('passerelle.utils.LoggedRequest.get')
|
||||
@mock.patch('passerelle.utils.Request.get')
|
||||
def test_get_filtered_by_property_feature(mocked_get, app, connector):
|
||||
endpoint = utils.generic_endpoint_url('opengis', 'features', slug=connector.slug)
|
||||
mocked_get.side_effect = geoserver_responses
|
||||
|
|
|
@ -30,8 +30,8 @@ def test_solis_restricted_access(app, solis):
|
|||
for service in ('apa-link', 'apa-unlink'):
|
||||
endpoint = utils.generic_endpoint_url('solis', service, slug=solis.slug)
|
||||
assert endpoint == '/solis/test/%s' % service
|
||||
with mock.patch('passerelle.utils.LoggedRequest.post') as requests_post:
|
||||
with mock.patch('passerelle.utils.LoggedRequest.get') as requests_get:
|
||||
with mock.patch('passerelle.utils.Request.post') as requests_post:
|
||||
with mock.patch('passerelle.utils.Request.get') as requests_get:
|
||||
resp = app.post(endpoint, status=403)
|
||||
assert requests_post.call_count == 0
|
||||
assert resp.json['err'] == 1
|
||||
|
@ -41,8 +41,8 @@ def test_solis_restricted_access(app, solis):
|
|||
for service in ('apa-links', 'apa-user-info', 'apa-users'):
|
||||
endpoint = utils.generic_endpoint_url('solis', service, slug=solis.slug)
|
||||
assert endpoint == '/solis/test/%s' % service
|
||||
with mock.patch('passerelle.utils.LoggedRequest.get') as requests_get:
|
||||
with mock.patch('passerelle.utils.LoggedRequest.post') as requests_post:
|
||||
with mock.patch('passerelle.utils.Request.get') as requests_get:
|
||||
with mock.patch('passerelle.utils.Request.post') as requests_post:
|
||||
resp = app.get(endpoint, status=403)
|
||||
assert requests_get.call_count == 0
|
||||
assert resp.json['err'] == 1
|
||||
|
@ -59,8 +59,8 @@ def test_solis_link_infos_unlink(app, solis):
|
|||
resource_pk=solis.pk)
|
||||
|
||||
# link
|
||||
with mock.patch('passerelle.utils.LoggedRequest.post') as requests_post: # get solis token
|
||||
with mock.patch('passerelle.utils.LoggedRequest.get') as requests_get: # get solis informations
|
||||
with mock.patch('passerelle.utils.Request.post') as requests_post: # get solis token
|
||||
with mock.patch('passerelle.utils.Request.get') as requests_get: # get solis informations
|
||||
endpoint = utils.generic_endpoint_url('solis', 'apa-link', slug=solis.slug)
|
||||
for params in (None, '', []):
|
||||
resp = app.post_json(endpoint, params=params, status=200)
|
||||
|
@ -151,8 +151,8 @@ def test_solis_link_infos_unlink(app, solis):
|
|||
|
||||
# get base informations from a linked user (exportDonneesIndividu)
|
||||
changed_name = APAINFOS['exportDonneesIndividu'].replace('PYPPENNE', 'PEPONE')
|
||||
with mock.patch('passerelle.utils.LoggedRequest.get') as requests_get:
|
||||
with mock.patch('passerelle.utils.LoggedRequest.post') as requests_post:
|
||||
with mock.patch('passerelle.utils.Request.get') as requests_get:
|
||||
with mock.patch('passerelle.utils.Request.post') as requests_post:
|
||||
requests_post.return_value = utils.FakedResponse(content=APATOKEN, status_code=200)
|
||||
requests_get.return_value = utils.FakedResponse(content=changed_name, status_code=200)
|
||||
endpoint = utils.generic_endpoint_url('solis', 'apa-user-info', slug=solis.slug)
|
||||
|
@ -166,8 +166,8 @@ def test_solis_link_infos_unlink(app, solis):
|
|||
|
||||
# get all kind of informations
|
||||
for apa_endpoint in APAINFOS:
|
||||
with mock.patch('passerelle.utils.LoggedRequest.get') as requests_get:
|
||||
with mock.patch('passerelle.utils.LoggedRequest.post') as requests_post:
|
||||
with mock.patch('passerelle.utils.Request.get') as requests_get:
|
||||
with mock.patch('passerelle.utils.Request.post') as requests_post:
|
||||
requests_post.return_value = utils.FakedResponse(content=APATOKEN, status_code=200)
|
||||
|
||||
endpoint_base = utils.generic_endpoint_url('solis', 'apa-user-info', slug=solis.slug)
|
||||
|
@ -203,8 +203,8 @@ def test_solis_link_infos_unlink(app, solis):
|
|||
|
||||
# get informations for all users (exportDonneesIndividu)
|
||||
change_info = APAINFOS['exportDonneesIndividu'].replace('PYPPENNE', 'PEPPYNE')
|
||||
with mock.patch('passerelle.utils.LoggedRequest.get') as requests_get:
|
||||
with mock.patch('passerelle.utils.LoggedRequest.post') as requests_post:
|
||||
with mock.patch('passerelle.utils.Request.get') as requests_get:
|
||||
with mock.patch('passerelle.utils.Request.post') as requests_post:
|
||||
requests_post.return_value = utils.FakedResponse(content=APATOKEN, status_code=200)
|
||||
requests_get.return_value = utils.FakedResponse(content=change_info, status_code=200)
|
||||
endpoint = utils.generic_endpoint_url('solis', 'apa-users', slug=solis.slug)
|
||||
|
|
|
@ -46,7 +46,7 @@ def formdata(request):
|
|||
return request.param
|
||||
|
||||
|
||||
@mock.patch('passerelle.utils.LoggedRequest.post')
|
||||
@mock.patch('passerelle.utils.Request.post')
|
||||
def test_instegration_demande_apa_domicile(mocked_post, setup, app, url):
|
||||
fake_response = '{"ImportIdResults":{"Items":[{"key":"indexDossier","value":359043},{"key":"indexBeneficiaire","value":458238},{"key":"indexDemande","value":221155}]}}'
|
||||
|
||||
|
@ -61,7 +61,7 @@ def test_instegration_demande_apa_domicile(mocked_post, setup, app, url):
|
|||
resp.json['data']['indexDemande'] == 221155
|
||||
|
||||
|
||||
@mock.patch('passerelle.utils.LoggedRequest.post')
|
||||
@mock.patch('passerelle.utils.Request.post')
|
||||
def test_integration_demande_apa_etablissement(mocked_post, setup, app, url):
|
||||
fake_response = '{"ImportIdResults":{"Items":[{"key":"indexDossier","value":359043},{"key":"indexBeneficiaire","value":458238},{"key":"indexDemande","value":221155}]}}'
|
||||
|
||||
|
|
|
@ -132,7 +132,7 @@ def tcl_responses(url, **kwargs):
|
|||
}.get(urlparse.urlparse(url).path)
|
||||
return utils.FakedResponse(json=lambda: copy.deepcopy(content), status_code=200)
|
||||
|
||||
@mock.patch('passerelle.utils.LoggedRequest.get')
|
||||
@mock.patch('passerelle.utils.Request.get')
|
||||
def test_cron(mocked_get, app, connector):
|
||||
mocked_get.side_effect = tcl_responses
|
||||
connector.daily()
|
||||
|
@ -150,7 +150,7 @@ def test_cron(mocked_get, app, connector):
|
|||
assert Stop.objects.get(id_data='46026').ascenseur is False
|
||||
|
||||
|
||||
@mock.patch('passerelle.utils.LoggedRequest.get')
|
||||
@mock.patch('passerelle.utils.Request.get')
|
||||
def test_stop_info(mocked_get, app, connector):
|
||||
mocked_get.side_effect = tcl_responses
|
||||
connector.daily()
|
||||
|
|
Loading…
Reference in New Issue