Пример #1
0
    def _process_response(self, response):
        resp_xml = parseString(response.content)
        status = resp_xml.getElementsByTagName("status")
        if status:
            status = status[0].firstChild.nodeValue
        else:
            # If no status element is in the result xml, return fail and log
            # the entire SOAP envelope in the log
            self._set_status("Failed", response.text)
            return self.status
        # Only done responses should be passed so we need to handle any status
        # related to done
        if status in ["Succeeded", "SucceededPartial"]:
            self._set_status("Success", status)
        else:
            # If failed, parse out the problem text and raise appropriate exception
            messages = []

            component_failures = resp_xml.getElementsByTagName("componentFailures")
            for component_failure in component_failures:
                problems = component_failure.getElementsByTagName("problem")
                problem_types = component_failure.getElementsByTagName("problemType")
                failure_info = {
                    "component_type": None,
                    "file_name": None,
                    "line_num": None,
                    "column_num": None,
                    "problem": problems[0].firstChild.nodeValue
                    if problems
                    else "Unknown problem",
                    "problem_type": problem_types[0].firstChild.nodeValue
                    if problem_types
                    else "Error",
                }
                failure_info["component_type"] = self._get_element_value(
                    component_failure, "componentType"
                )
                full_name = self._get_element_value(component_failure, "fullName")
                file_name = self._get_element_value(component_failure, "fileName")
                failure_info["file_name"] = full_name or file_name
                failure_info["line_num"] = self._get_element_value(
                    component_failure, "lineNumber"
                )
                failure_info["column_num"] = self._get_element_value(
                    component_failure, "columnNumber"
                )

                created = (
                    component_failure.getElementsByTagName("created")[
                        0
                    ].firstChild.nodeValue
                    == "true"
                )
                deleted = (
                    component_failure.getElementsByTagName("deleted")[
                        0
                    ].firstChild.nodeValue
                    == "true"
                )
                failure_info["action"] = self._get_action(created, deleted)

                if failure_info["file_name"] and failure_info["line_num"]:
                    messages.append(
                        "{action} of {component_type} {file_name}: {problem_type} on line {line_num}, col {column_num}: {problem}".format(
                            **failure_info
                        )
                    )
                elif failure_info["file_name"]:
                    messages.append(
                        "{action} of {component_type} {file_name}: {problem_type}: {problem}".format(
                            **failure_info
                        )
                    )
                else:
                    messages.append(
                        "{action} of {component_type}: {problem_type}: {problem}".format(
                            **failure_info
                        )
                    )

            if messages:
                # Deploy failures due to a component failure should raise MetadataComponentFailure
                log = "\n\n".join(messages)
                self._set_status("Failed", log)
                raise MetadataComponentFailure(log, response)

            else:
                problems = resp_xml.getElementsByTagName("problem")
                for problem in problems:
                    messages.append(problem.firstChild.nodeValue)
                errorMessages = resp_xml.getElementsByTagName("errorMessage")
                for errorMessage in errorMessages:
                    messages.append(errorMessage.firstChild.nodeValue)
                if messages:
                    log = "\n\n".join(messages)
                    raise MetadataApiError(log, response)

            # Parse out any failure text (from test failures in production
            # deployments) and add to log
            failures = resp_xml.getElementsByTagName("failures")
            for failure in failures:
                # Get needed values from subelements
                namespace = self._get_element_value(failure, "namespace")
                stacktrace = self._get_element_value(failure, "stackTrace")
                message = ["Apex Test Failure: "]
                if namespace:
                    message.append(f"from namespace {namespace}: ")
                if stacktrace:
                    message.append(stacktrace)
                messages.append("".join(message))

            if messages:
                # Deploy failures due to a component failure should raise MetadataComponentFailure
                log = "\n\n".join(messages)
                self._set_status("Failed", log)
                raise ApexTestException(log)
            else:
                log = response.text
                self._set_status("Failed", log)
                raise MetadataApiError(log, response)

        return self.status
Пример #2
0
    def _process_response(self, response):
        status = parseString(response.content).getElementsByTagName('status')
        if status:
            status = status[0].firstChild.nodeValue
        else:
            # If no status element is in the result xml, return fail and log
            # the entire SOAP envelope in the log
            self._set_status('Failed', response.content)
            return self.status
        # Only done responses should be passed so we need to handle any status
        # related to done
        if status in ['Succeeded', 'SucceededPartial']:
            self._set_status('Success', status)
        else:
            # If failed, parse out the problem text and raise appropriate exception
            messages = []
            resp_xml = parseString(response.content)

            component_failures = resp_xml.getElementsByTagName('componentFailures')
            for component_failure in component_failures:
                failure_info = {
                    'component_type': None,
                    'file_name': None,
                    'line_num': None,
                    'column_num': None,
                    'problem': component_failure.getElementsByTagName('problem')[0].firstChild.nodeValue,
                    'problem_type': component_failure.getElementsByTagName('problemType')[0].firstChild.nodeValue,
                }
                failure_info['component_type'] = self._get_element_value(
                    component_failure, 'componentType')
                full_name = self._get_element_value(component_failure, 'fullName')
                file_name = self._get_element_value(component_failure, 'fileName')
                failure_info['file_name'] = full_name or file_name
                failure_info['line_num'] = self._get_element_value(component_failure, 'lineNumber')
                failure_info['column_num'] = self._get_element_value(component_failure, 'columnNumber')
                
                created = component_failure.getElementsByTagName('created')[0].firstChild.nodeValue == 'true'
                deleted = component_failure.getElementsByTagName('deleted')[0].firstChild.nodeValue == 'true'
                failure_info['action'] = self._get_action(created, deleted)
  
                if failure_info['file_name'] and failure_info['line_num']: 
                    messages.append('{action} of {component_type} {file_name}: {problem_type} on line {line_num}, col {column_num}: {problem}'.format(**failure_info))
                elif failure_info['file_name']:
                    messages.append('{action} of {component_type} {file_name}: {problem_type}: {problem}'.format(**failure_info))
                else:
                    messages.append('{action} of {problem_type}: {problem}'.format(**failure_info))

            if messages:
                # Deploy failures due to a component failure should raise MetadataComponentFailure
                log = '\n\n'.join(messages)
                self._set_status('Failed', log)
                raise MetadataComponentFailure(log, response)
                
            else:
                problems = parseString(
                    response.content).getElementsByTagName('problem')
                for problem in problems:
                    messages.append(problem.firstChild.nodeValue)

            # Parse out any failure text (from test failures in production
            # deployments) and add to log
            failures = parseString(
                response.content).getElementsByTagName('failures')
            for failure in failures:
                # Get needed values from subelements
                namespace = self._get_element_value(failure, 'namespace')
                stacktrace = self._get_element_value(failure, 'stackTrace')
                message = ['Apex Test Failure: ', ]
                if namespace:
                    message.append('from namespace {}: '.format(namespace))
                if stacktrace:
                    message.append(stacktrace)
                messages.append(''.join(message))

            if messages:
                # Deploy failures due to a component failure should raise MetadataComponentFailure
                log = '\n\n'.join(messages)
                self._set_status('Failed', log)
                raise ApexTestException(log)
            else:
                log = response.content
                self._set_status('Failed', log)
                raise MetadataApiError(log, response)

        return self.status