def test_describe( mocker ): header_map = {} cinp = CInP( 'http://localhost:8080', '/api/v1/', None ) mocked_open = mocker.patch( 'urllib.request.OpenerDirector.open' ) mocked_open.return_value = MockResponse( 200, header_map, '' ) with pytest.raises( InvalidRequest ): cinp.describe( '/api/v1/model:sdf:' ) header_map[ 'Type' ] = 'Namespace' mocked_open.reset_mock() data, type = cinp.describe( '/api/v1/' ) assert type == 'Namespace' req = mocked_open.call_args[0][0] assert req.full_url == 'http://localhost:8080/api/v1/' assert req.data == b'' assert req.headers == { 'Content-type': 'application/json;charset=utf-8' } assert req.get_method() == 'DESCRIBE' assert data is None header_map[ 'Type' ] = 'Model' mocked_open.reset_mock() data, type = cinp.describe( '/api/v1/model' ) assert type == 'Model' req = mocked_open.call_args[0][0] assert req.full_url == 'http://localhost:8080/api/v1/model' assert req.data == b'' assert req.headers == { 'Content-type': 'application/json;charset=utf-8' } assert req.get_method() == 'DESCRIBE' assert data is None header_map[ 'Type' ] = 'Action' mocked_open.reset_mock() data, type = cinp.describe( '/api/v1/model(sdf)' ) assert type == 'Action' req = mocked_open.call_args[0][0] assert req.full_url == 'http://localhost:8080/api/v1/model(sdf)' assert req.data == b'' assert req.headers == { 'Content-type': 'application/json;charset=utf-8' } assert req.get_method() == 'DESCRIBE' assert data is None mocked_open.reset_mock() mocked_open.return_value = MockResponse( 201, {}, '' ) with pytest.raises( ResponseError ): cinp.describe( '/api/v1/model' )
import http.client as httplib from cinp.client import CInP, NotFound, NotAuthorized client = CInP(host='http://127.0.0.1', root_path='/api/v1/', port=8888) print('First we will get OPTIONS on a few things to see what that looks like') conn = httplib.HTTPConnection('127.0.0.1', '8888') conn.request('OPTIONS', '/api/v1/User/') conn.getresponse().getheader('allow') conn.request('OPTIONS', '/api/v1/User/User') conn.getresponse().getheader('allow') conn.request('OPTIONS', '/api/v1/User/User(setPassword)') conn.getresponse().getheader('allow') print('Now We will DESCRIBE, see what it is we are going to play with') print(client.describe('/api/v1/')) print(client.describe('/api/v1/User/')) print(client.describe('/api/v1/User/User')) print(client.describe('/api/v1/User/User(setPassword)')) print(client.describe('/api/v1/User/Session(login)')) print(client.describe('/api/v1/User/Session(logout)')) print(client.describe('/api/v1/User/Session(hearbeat)')) print(client.describe('/api/v1/Car/')) print(client.describe('/api/v1/Car/PartType')) print(client.describe('/api/v1/Car/Part')) print(client.describe('/api/v1/Car/Car')) print('List is not allowed on Users') try: print(client.list('/api/v1/User/User')) except NotAuthorized: