Beispiel #1
0
 def setUpClass(cls):
     session = requests.session()
     session.verify = False
     cls.rest_connector = get_requests_connector(session=session,
                                                 msg_protocol='rest',
                                                 url='https://some-url')
     cls.stub_config = StubConfiguration(cls.rest_connector)
Beispiel #2
0
    def test_invoke_echo_long_running_false_method(self):
        connector = get_local_connector(MockupApiProvider())
        self.assertTrue(isinstance(connector, Connector))

        iface = MockIface(StubConfiguration(connector))
        self.assertTrue(isinstance(iface, VapiInterface))

        self.assertEqual(iface.echo_long_running(message='hello'), 'hello')
Beispiel #3
0
    def test_invoke_echo_long_running_method(self):
        connector = get_local_connector(MockupApiProvider())
        self.assertTrue(isinstance(connector, Connector))

        iface = MockIface(StubConfiguration(connector))
        self.assertTrue(isinstance(iface, VapiInterface))

        result = iface.echo_long_running_task(message='hello')
        self.assertNotEqual(result, 'hello')
        try:
            uuid.UUID(result, version=4)
        except ValueError:
            # There's no assertNotRaises so explicitly fail assert
            # in case a ValueError is thrown for invalid uuid.
            self.assertTrue(False)
Beispiel #4
0
    def new_configuration(connector, *errorTypes):
        """
        Return a stub configuration using the specified connection, with no
        registered errors.

        :type  connector:
            :class:`vmware.vapi.protocol.client.connector.Connector`
        :param connector: Connection to be used to talk to the remote
                          ApiProvider
        :type  error_types: :class:`list` of
            :class:`vmware.vapi.bindings.type.ErrorType`
        :param error_types: error types to be registered in the configuration
        """
        config = StubConfiguration(connector, *errorTypes)
        return config
Beispiel #5
0
 def test_report_success(self):
     config = StubConfiguration(get_local_connector(MockupApiProvider()))
     operations = {
         report_vapi_success: {
             'input_type': StructType(report_vapi_success, {}),
             'output_type': BooleanType(),
             'errors': {},
             'input_value_validator_list': [],
             'output_validator_list': [],
             'task_type': TaskType.NONE,
         }
     }
     stub = ApiInterfaceStub('mockup_interface',
                             config=config,
                             operations=operations)
     self.assertEqual(
         stub.native_invoke(ctx=config.connector.new_context(),
                            method_name=report_vapi_success,
                            kwargs={}), True)
Beispiel #6
0
 def test_report_unexpected_error(self):
     config = StubConfiguration(get_local_connector(MockupApiProvider()))
     operations = {
         nonexistent_method: {
             'input_type': StructType(nonexistent_method, {}),
             'output_type': BooleanType(),
             'errors': {
                 not_found: not_found_error_type
             },
             'input_value_validator_list': [],
             'output_validator_list': [],
             'task_type': TaskType.NONE,
         }
     }
     stub = ApiInterfaceStub('mockup_interface',
                             config=config,
                             operations=operations)
     self.assertRaises(VapiError, stub.native_invoke,
                       config.connector.new_context(), nonexistent_method,
                       {})
Beispiel #7
0
    def new_runtime_configuration(connector, *errorTypes, **kwargs):
        """
        Return a stub configuration using the specified connection, with the
        errors reported by the vAPI runtime registered.

        :type  connector:
            :class:`vmware.vapi.protocol.client.connector.Connector`
        :param connector: Connection to be used to talk to the remote
                          ApiProvider
        :type  error_types: :class:`list` of
            :class:`vmware.vapi.bindings.type.ErrorType`
        :type kwargs: :class: `vmware.vapi.bindings.http_helper.ResponseExtractor`    # pylint: disable=line-too-long
        :param kwargs: Extract rest http response status
        :param error_types: additional error types to be registered in the
                            configuration
        """
        extractor = kwargs.get('response_extractor', None)
        return StubConfiguration(
            connector,
            errors_client.InternalServerError.get_binding_type(),
            errors_client.InvalidArgument.get_binding_type(),
            errors_client.OperationNotFound.get_binding_type(),
            *errorTypes,
            response_extractor=extractor)
Beispiel #8
0
 def test_json_client_provider_for_swagger_services(self):
     connector = get_local_connector(MockupApiProvider())
     iface = MockRestIface(StubConfiguration(connector))
     self.assertRaises(CoreException, iface.echo, message='hello')
Beispiel #9
0
 def test_invoke_invalid_method(self):
     connector = get_local_connector(MockupApiProvider())
     iface = MockIface(StubConfiguration(connector))
     self.assertRaises(Exception, iface.invalid)