Add logging for response bodies (#11)

This commit is contained in:
f4lco
2019-12-28 17:34:58 +01:00
parent ad5b79ec64
commit 342157e465
2 changed files with 13 additions and 0 deletions
+8
View File
@@ -1,6 +1,7 @@
# -*- encoding: utf-8 -*- # -*- encoding: utf-8 -*-
import json import json
import logging
from collections import namedtuple from collections import namedtuple
import requests import requests
@@ -9,6 +10,8 @@ MenuParams = namedtuple('MenuParams', ('canteen_id', 'chash'))
URL = 'https://www.studentenwerk-potsdam.de' + \ URL = 'https://www.studentenwerk-potsdam.de' + \
'/essen/unsere-mensen-cafeterien/detailinfos/' '/essen/unsere-mensen-cafeterien/detailinfos/'
LOG = logging.getLogger(__name__)
def _param_json(to_serialize): def _param_json(to_serialize):
"""Obtain JSON string of an object without whitespace on delimiters. """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) 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() return request.json()
+5
View File
@@ -1,5 +1,6 @@
# -*- encoding: utf-8 -*- # -*- encoding: utf-8 -*-
import logging
import os import os
import pytest import pytest
@@ -12,6 +13,10 @@ from stw_potsdam.canteen_api import MenuParams
ENV_ENABLED = 'ENABLE_API_QUERY' 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() CANTEENS = read_canteen_config()