def test_get_webdata_json_error(self): """Test 200 non-JSON repsonse exits.""" session = requests.Session() text = 'response text is not json' with patch.object(session, 'get', return_value=MockResponse200(text)): with pytest.raises(SystemExit): wc.get_webdata(WASAPI_URL, session)
def test_get_webdata_ConnectionError(self): """Test host connection isn't made.""" session = requests.Session() error = requests.exceptions.ConnectionError with patch.object(session, 'get', side_effect=error): with pytest.raises(SystemExit): wc.get_webdata(WASAPI_URL, session)
def test_get_webdata(self): """Test a successful response.""" session = requests.Session() with patch.object(session, 'get', return_value=MockResponse200()): response = wc.get_webdata(WASAPI_URL, session) # Compare with whitespace stripped. response_text = "".join(json.dumps(response, sort_keys=True).split()) assert response_text == WASAPI_TEXT
def test_get_webdata_403_forbidden(self): """Test bad authentication handling.""" session = requests.Session() with patch.object(session, 'get', return_value=MockResponse403()): with pytest.raises(SystemExit): wc.get_webdata(WASAPI_URL, session)