def mock_get_bucket(namespace_name, bucket_name):
     return Response(
         200, {},
         Bucket(namespace="test-namespace",
                compartment_id="test-compartment-id",
                name="test-bucket-name",
                storage_tier=OBJECT_STORAGE_BUCKET_TYPE_ARCHIVE),
         Request("mock.method", "mock.url"))
예제 #2
0
    def call_api(self,
                 resource_path,
                 method,
                 path_params=None,
                 query_params=None,
                 header_params=None,
                 body=None,
                 response_type=None,
                 enforce_content_headers=True):
        """
        Makes the HTTP request and return the deserialized data.

        :param resource_path: Path to the resource (e.g. /instance)
        :param method: HTTP method
        :param path_params: (optional) Path parameters in the url.
        :param query_params: (optional) Query parameters in the url.
        :param header_params: (optional) Request header params.
        :param body: (optional) Request body.
        :param response_type: (optional) Response data type.
        :param enforce_content_headers: (optional) Whether content headers should be added for
            PUT and POST requests when not present.  Defaults to True.
        :return: A Response object, or throw in the case of an error.

        """

        if path_params is not None:
            for k, v in path_params.items():
                replacement = six.moves.urllib.parse.quote(v)
                resource_path = resource_path.\
                    replace('{' + k + '}', replacement)

        response = self.pool_manager.request(
            method,
            '{}{}{}'.format(self._endpoint, self._base_path, resource_path),
            body=json.dumps(body),
            headers=header_params)

        request = Request(method=method,
                          url=self._endpoint + self._base_path + resource_path,
                          query_params=query_params,
                          header_params=header_params,
                          body=body,
                          response_type=response_type,
                          enforce_content_headers=enforce_content_headers)
        if not 200 <= response.status <= 299:
            raise exceptions.ServiceError(response.status,
                                          None,
                                          response.headers,
                                          str(response.data),
                                          original_request=request)

        data = response.data
        try:
            data = json.loads(response.data.decode("utf-8"))
        except Exception as e:
            pass
        return Response(response.status, dict(response.getheaders()), data,
                        request)
 def mock_get_transfer_appliance_helper(ctx, from_json, id,
                                        appliance_lbl):
     if appliance_lbl == 'XA-test-1':
         return Response(
             200, {},
             TransferAppliance(
                 transfer_job_id='test-job-id',
                 label='XA-test-1',
                 serial_number='test-serial-no-1',
                 lifecycle_state='PREPARING',
                 upload_status_log_uri='fakepath/upload_summary1.txt'),
             Request("mock.method", "mock.url"))
     else:
         return Response(
             200, {},
             TransferAppliance(
                 transfer_job_id='test-job-id',
                 label='XA-test-2',
                 serial_number='test-serial-no-2',
                 lifecycle_state='PREPARING',
                 upload_status_log_uri='fakepath/upload_summary2.txt'),
             Request("mock.method", "mock.url"))
 def mock_get_transfer_job_helper(ctx, from_json, id):
     return Response(
         200, {},
         TransferJob(id='test-job-id',
                     compartment_id='test-compartment-id',
                     label='test-transfer-job',
                     device_type='APPLIANCE',
                     lifecycle_state='PREPARING',
                     attached_transfer_appliance_labels=[
                         'XA-test-1', 'XA_test-2'
                     ],
                     upload_bucket_name='test-bucket'),
         Request("mock.method", "mock.url"))
 def method_side_effect(**kwargs):
     return Response(v[0], v[1], v[2], Request("mock.method", "mock.url"))
예제 #6
0
 def mock_get_namespace():
     return Response(200, {}, "test-namespace", Request("mock.method", "mock.url"))