def test_api_structure_error(self, mocked_request): """ Raises a QuickBaseException when the API returns an invalid structure which would cause an immediate parsing failure """ with pytest.raises(QuickBaseException): _ResponseHandler(action='API_GetNumRecords', response=mocked_request)
def test_api_error(self): """ Raises a QuickBaseException when the API returns a valid status code, and a non-zero errcode indicating a problem with the request """ with pytest.raises(QuickBaseException): _ResponseHandler(action='API_GetNumRecords', response=mocked_request('QuickBaseException'))
def test_property_error(self): """Error property returns (errcode, errtext) tuple""" rh = _ResponseHandler(action='API_GetNumRecords', response=mocked_request('API_GetNumRecords')) assert rh.error == { 'errcode': 0, 'errtext': 'No error', 'errdetail': None }
def test_api_unreachable(self): """ Raises a RequestException when the API returns status code other than 200 """ with pytest.raises(RequestException): _ResponseHandler(action='API_GetNumRecords', response=mocked_request('RequestException'))
def test_property_action(self): """Action property returns the action parameter from the response""" rh = _ResponseHandler(action='API_GetNumRecords', response=mocked_request('API_GetNumRecords')) assert rh.action == 'API_GetNumRecords'
def test_repr(self): """Test object representation""" rh = _ResponseHandler(action='API_GetNumRecords', response=mocked_request('API_GetNumRecords')) assert repr(rh) == 'ResponseHandler ({0}) at {1}'.format('API_GetNumRecords', hex(id(rh)))