def setUp(self): self.cfg = Configuration("https://my_endpoint.com") self.cfg.headers = {'Test': 'true'} self.creds = mock.create_autospec(OAuthTokenAuthentication) return super(TestServiceClient, self).setUp()
def search_extensions(search_query): """ Search extensions from marketplace """ from msrest.universal_http import ClientRequest from msrest.service_client import ServiceClient from msrest import Configuration from azext_devops.version import VERSION config = Configuration(base_url=None) config.add_user_agent('devOpsCli/{}'.format(VERSION)) client = ServiceClient(creds=None, config=config) request = ClientRequest(method='POST', url='https://marketplace.visualstudio.com/_apis/public/gallery/extensionquery') search_request = { 'assetTypes': [ 'Microsoft.VisualStudio.Services.Icons.Default', 'Microsoft.VisualStudio.Services.Icons.Branding', 'Microsoft.VisualStudio.Services.Icons.Small' ], 'filters': [ { 'criteria': [ { 'filterType': 8, 'value': 'Microsoft.VisualStudio.Services' }, { 'filterType': 8, 'value': 'Microsoft.VisualStudio.Services.Integration' }, { 'filterType': 8, 'value': 'Microsoft.VisualStudio.Services.Cloud' }, { 'filterType': 8, 'value': 'Microsoft.TeamFoundation.Server' }, { 'filterType': 8, 'value': 'Microsoft.TeamFoundation.Server.Integration' }, { 'filterType': 8, 'value': 'Microsoft.VisualStudio.Services.Cloud.Integration' }, { 'filterType': 8, 'value': 'Microsoft.VisualStudio.Services.Resource.Cloud' }, { 'filterType': 10, 'value': search_query }, { 'filterType': 12, 'value': '37888' } ], 'direction': 2, 'pageSize': 50, 'pageNumber': 1, 'sortBy': 0, 'sortOrder': 0, 'pagingToken': None } ], 'flags': 870 } headers = {'Content-Type': 'application/json' + '; charset=utf-8', 'Accept': 'application/json' + ';api-version=' + '5.0-preview.1'} response = client.send(request=request, headers=headers, content=search_request) response_json = response.json() return response_json['results'][0]['extensions']
def setUp(self): self.cfg = Configuration("https://my_endpoint.com") self._d = Deserializer() self._d.dependencies = {'CloudErrorData': CloudErrorData} return super(TestCloudException, self).setUp()
class BadEndpointError(Exception): pass TEST_NAME = 'foo' RESPONSE_BODY = {'properties': {'provisioningState': 'InProgress'}} ASYNC_BODY = json.dumps({'status': 'Succeeded'}) ASYNC_URL = 'http://dummyurlFromAzureAsyncOPHeader_Return200' LOCATION_BODY = json.dumps({'name': TEST_NAME}) LOCATION_URL = 'http://dummyurlurlFromLocationHeader_Return200' RESOURCE_BODY = json.dumps({'name': TEST_NAME}) RESOURCE_URL = 'http://subscriptions/sub1/resourcegroups/g1/resourcetype1/resource1' ERROR = 'http://dummyurl_ReturnError' POLLING_STATUS = 200 CLIENT = ServiceClient(None, Configuration("http://example.org")) async def mock_send(client_self, request, *, stream): return TestArmPolling.mock_update(request.url) CLIENT.async_send = types.MethodType(mock_send, CLIENT) class TestArmPolling(object): convert = re.compile('([a-z0-9])([A-Z])') @staticmethod def mock_send(method, status, headers, body=None):