def record(self, pywbem_args, pywbem_result, http_request, http_response):
        """
        Function that records the invocation of a single
        :class:`~pywbem.WBEMConnection` method, by appending a corresponding
        test case to the file.

        Parameters: See :meth:`pywbem.BaseOperationRecorder.record`.
        """

        testcase = OrderedDict()
        testcase['name'] = pywbem_args.method
        testcase['description'] = 'Generated by TestClientRecorder'

        tc_pywbem_request = OrderedDict()
        tc_pywbem_request['url'] = TestClientRecorder.TESTCASE_URL
        tc_pywbem_request['creds'] = [TestClientRecorder.TESTCASE_USER,
                                      TestClientRecorder.TESTCASE_PASSWORD]
        tc_pywbem_request['namespace'] = 'root/cimv2'
        tc_pywbem_request['timeout'] = 10
        tc_pywbem_request['debug'] = False
        tc_operation = OrderedDict()
        tc_operation['pywbem_method'] = pywbem_args.method
        for arg_name in pywbem_args.args:
            tc_operation[arg_name] = self.toyaml(pywbem_args.args[arg_name])
        tc_pywbem_request['operation'] = tc_operation
        testcase['pywbem_request'] = tc_pywbem_request

        tc_pywbem_response = OrderedDict()
        if pywbem_result.ret is not None:
            yaml_txt = 'pullresult' if self._pull_op else 'result'
            tc_pywbem_response[yaml_txt] = self.toyaml(pywbem_result.ret)

        if pywbem_result.exc is not None:
            exc = pywbem_result.exc
            if isinstance(exc, CIMError):
                tc_pywbem_response['cim_status'] = self.toyaml(exc.status_code)
            else:
                tc_pywbem_response['exception'] = self.toyaml(
                    exc.__class__.__name__)
        testcase['pywbem_response'] = tc_pywbem_response

        tc_http_request = OrderedDict()
        if http_request is not None:
            tc_http_request['verb'] = http_request.method
            tc_http_request['url'] = TestClientRecorder.TESTCASE_URL
            if http_request.target:
                tc_http_request['url'] += http_request.target
            tc_request_headers = OrderedDict()
            if http_request.headers is not None:
                for hdr_name in http_request.headers:
                    if hdr_name.lower() not in \
                       TestClientRecorder.EXCLUDE_REQUEST_HEADERS:
                        tc_request_headers[hdr_name] = \
                            http_request.headers[hdr_name]
            tc_http_request['headers'] = tc_request_headers
            if http_request.payload is not None:
                data = http_request.payload.decode('utf-8')
                data = data.replace('><', '>\n<').strip()
            else:
                data = None
            tc_http_request['data'] = data
        testcase['http_request'] = tc_http_request

        tc_http_response = OrderedDict()
        if http_response is not None:
            tc_http_response['status'] = http_response.status
            tc_response_headers = OrderedDict()
            if http_response.headers is not None:
                for hdr_name in http_response.headers:
                    if hdr_name.lower() not in \
                       TestClientRecorder.EXCLUDE_RESPONSE_HEADERS:
                        tc_response_headers[hdr_name] = \
                            http_response.headers[hdr_name]
            tc_http_response['headers'] = tc_response_headers
            if http_response.payload is not None:
                data = http_response.payload.decode('utf-8')
                data = data.replace('><', '>\n<').strip()
            else:
                data = None
            tc_http_response['data'] = data
        else:
            tc_http_response['exception'] = "# Change this to a callback " \
                                            "function that causes this " \
                                            "condition."
        testcase['http_response'] = tc_http_response

        testcases = []
        testcases.append(testcase)

        # The file is open in text mode, so we produce a unicode string
        data = yaml.safe_dump(testcases, encoding=None, allow_unicode=True,
                              default_flow_style=False, indent=4)
        data = data.replace('\n\n', '\n')  # YAML dump duplicates newlines
        self._fp.write(data)
        self._fp.flush()
def record ( self , pywbem_args , pywbem_result , http_request , http_response ) : testcase = OrderedDict ( ) testcase [ 'name' ] = pywbem_args . method testcase [ 'description' ] = 'Generated by TestClientRecorder' tc_pywbem_request = OrderedDict ( ) tc_pywbem_request [ 'url' ] = TestClientRecorder . TESTCASE_URL tc_pywbem_request [ 'creds' ] = [ TestClientRecorder . TESTCASE_USER , TestClientRecorder . TESTCASE_PASSWORD ] tc_pywbem_request [ 'namespace' ] = 'root/cimv2' tc_pywbem_request [ 'timeout' ] = 10 tc_pywbem_request [ 'debug' ] = False tc_operation = OrderedDict ( ) tc_operation [ 'pywbem_method' ] = pywbem_args . method for arg_name in pywbem_args . args : tc_operation [ arg_name ] = self . toyaml ( pywbem_args . args [ arg_name ] ) tc_pywbem_request [ 'operation' ] = tc_operation testcase [ 'pywbem_request' ] = tc_pywbem_request tc_pywbem_response = OrderedDict ( ) if pywbem_result . ret is not None : yaml_txt = 'pullresult' if self . _pull_op else 'result' tc_pywbem_response [ yaml_txt ] = self . toyaml ( pywbem_result . ret ) if pywbem_result . exc is not None : exc = pywbem_result . exc if isinstance ( exc , CIMError ) : tc_pywbem_response [ 'cim_status' ] = self . toyaml ( exc . status_code ) else : tc_pywbem_response [ 'exception' ] = self . toyaml ( exc . __class__ . __name__ ) testcase [ 'pywbem_response' ] = tc_pywbem_response tc_http_request = OrderedDict ( ) if http_request is not None : tc_http_request [ 'verb' ] = http_request . method tc_http_request [ 'url' ] = TestClientRecorder . TESTCASE_URL if http_request . target : tc_http_request [ 'url' ] += http_request . target tc_request_headers = OrderedDict ( ) if http_request . headers is not None : for hdr_name in http_request . headers : if hdr_name . lower ( ) not in TestClientRecorder . EXCLUDE_REQUEST_HEADERS : tc_request_headers [ hdr_name ] = http_request . headers [ hdr_name ] tc_http_request [ 'headers' ] = tc_request_headers if http_request . payload is not None : data = http_request . payload . decode ( 'utf-8' ) data = data . replace ( '><' , '>\n<' ) . strip ( ) else : data = None tc_http_request [ 'data' ] = data testcase [ 'http_request' ] = tc_http_request tc_http_response = OrderedDict ( ) if http_response is not None : tc_http_response [ 'status' ] = http_response . status tc_response_headers = OrderedDict ( ) if http_response . headers is not None : for hdr_name in http_response . headers : if hdr_name . lower ( ) not in TestClientRecorder . EXCLUDE_RESPONSE_HEADERS : tc_response_headers [ hdr_name ] = http_response . headers [ hdr_name ] tc_http_response [ 'headers' ] = tc_response_headers if http_response . payload is not None : data = http_response . payload . decode ( 'utf-8' ) data = data . replace ( '><' , '>\n<' ) . strip ( ) else : data = None tc_http_response [ 'data' ] = data else : tc_http_response [ 'exception' ] = "# Change this to a callback " "function that causes this " "condition." testcase [ 'http_response' ] = tc_http_response testcases = [ ] testcases . append ( testcase ) data = yaml . safe_dump ( testcases , encoding = None , allow_unicode = True , default_flow_style = False , indent = 4 ) data = data . replace ( '\n\n' , '\n' ) self . _fp . write ( data ) self . _fp . flush ( )
Function that records the invocation of a single
        :class:`~pywbem.WBEMConnection` method, by appending a corresponding
        test case to the file.

        Parameters: See :meth:`pywbem.BaseOperationRecorder.record`.