def test_BaseAPI_get_object_raises_from_returns(mox, response, errcode, prefix): """Test the cases where get_object raises an exception based on what it receives.""" sut = BaseAPI(url='https://example.com', token='ABCDEFGH', org_key='A1B2C3D4') mox.StubOutWithMock(sut.session, 'http_request') sut.session.http_request('GET', '/path', headers={}, data=None).AndReturn(response) mox.ReplayAll() with pytest.raises(ServerError) as excinfo: sut.get_object('/path') assert excinfo.value.error_code == errcode assert excinfo.value.message.startswith(prefix) mox.VerifyAll()
def test_BaseAPI_get_object_returns(mox, expath, response, params, default, expected): """Test the cases where get_object returns a value.""" sut = BaseAPI(url='https://example.com', token='ABCDEFGH', org_key='A1B2C3D4') mox.StubOutWithMock(sut.session, 'http_request') sut.session.http_request('GET', expath, headers={}, data=None).AndReturn(response) mox.ReplayAll() rc = sut.get_object('/path', params, default) assert rc == expected mox.VerifyAll()