Add logging for response bodies (#11)
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
|
||||
import json
|
||||
import logging
|
||||
from collections import namedtuple
|
||||
import requests
|
||||
|
||||
@@ -9,6 +10,8 @@ MenuParams = namedtuple('MenuParams', ('canteen_id', 'chash'))
|
||||
URL = 'https://www.studentenwerk-potsdam.de' + \
|
||||
'/essen/unsere-mensen-cafeterien/detailinfos/'
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def _param_json(to_serialize):
|
||||
"""Obtain JSON string of an object without whitespace on delimiters.
|
||||
@@ -40,4 +43,9 @@ def download_menu(menu_params):
|
||||
}
|
||||
|
||||
request = requests.post(URL, params=params, json=body)
|
||||
|
||||
# urllib3 does not log response bodies - requests no longer supports it:
|
||||
# https://2.python-requests.org//en/master/api/#api-changes
|
||||
LOG.debug('Response:\n>>>>>\n%s\n<<<<<', request.text)
|
||||
|
||||
return request.json()
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
|
||||
import logging
|
||||
import os
|
||||
import pytest
|
||||
|
||||
@@ -12,6 +13,10 @@ from stw_potsdam.canteen_api import MenuParams
|
||||
|
||||
ENV_ENABLED = 'ENABLE_API_QUERY'
|
||||
|
||||
# Because log messages are automatically part of the Pytest report, below
|
||||
# explicitly avoids adding log handlers via logging#basicConfig, for example.
|
||||
logging.getLogger().setLevel(logging.DEBUG)
|
||||
|
||||
CANTEENS = read_canteen_config()
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user