Open
Description
=================================== FAILURES ===================================
_______________________ TestThermostat.test_get_data_401 _______________________
self = <tests.test_thermostat.TestThermostat testMethod=test_get_data_401>
@responses.activate
def test_get_data_401(self):
# First request (when initializing the thermostat) is successful
response_data = load_fixture("thermostat.json")
responses.add(
responses.GET,
config.THERMOSTAT_URL,
status=200,
body=json.dumps(response_data),
content_type="application/json"
)
# A later, second request throws 401 Unauthorized
responses.add(
responses.GET,
config.THERMOSTAT_URL,
status=401
)
# Attempt to reauthenticate
auth_data = load_fixture("auth_success.json")
responses.add(
responses.POST,
config.AUTH_URL,
status=200,
body=json.dumps(auth_data),
content_type="application/json"
)
# Third request is successful
responses.add(
responses.GET,
config.THERMOSTAT_URL,
status=200,
body=json.dumps(response_data),
content_type="application/json"
)
bad_session_id = "my-bad-session"
good_session_id = auth_data.get("SessionId")
api = NuHeat(None, None, session_id=bad_session_id)
serial_number = response_data.get("SerialNumber")
thermostat = NuHeatThermostat(api, serial_number)
> thermostat.get_data()
tests/test_thermostat.py:206:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
nuheat/thermostat.py:140: in get_data
data = self._session.request(config.THERMOSTAT_URL, params=params)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <NuHeat username='None'>, url = 'https://www.mynuheat.com/api/thermostat'
method = 'GET', data = None
params = {'serialnumber': '12345', 'sessionid': 'my-bad-session'}, retry = True
def request(self, url, method="GET", data=None, params=None, retry=True):
"""
Make a request to the NuHeat API
:param url: The URL to request
:param method: The type of request to make (GET, POST)
:param data: Data to be sent along with POST requests
:param params: Querystring parameters
:param retry: Attempt to re-authenticate and retry request if necessary
"""
headers = config.REQUEST_HEADERS
if params and self._session_id:
params['sessionid'] = self._session_id
if method == "GET":
response = requests.get(url, headers=headers, params=params)
elif method == "POST":
response = requests.post(url, headers=headers, params=params, data=data)
# Handle expired sessions
if response.status_code == 401 and retry:
> _LOGGER.warn("NuHeat APIrequest unauthorized [401]. Try to re-authenticate.")
E AttributeError: 'Logger' object has no attribute 'warn'
nuheat/api.py:78: AttributeError
=========================== short test summary info ============================
FAILED tests/test_thermostat.py::TestThermostat::test_get_data_401 - Attribut...
========================= 1 failed, 35 passed in 0.18s =========================
See also https://bugzilla.redhat.com/show_bug.cgi?id=2252059
Metadata
Metadata
Assignees
Labels
No labels