コード例 #1
0
    def init_service(self,
                     endpoint,
                     project,
                     uuid,
                     log_batch_size,
                     pool_size,
                     skipped_issue=True):
        """Initialize common reportportal client.

        :param endpoint:       Report Portal API endpoint
        :param project:        Report Portal project
        :param uuid:           API token
        :param log_batch_size: Number of logs to be sent within one batch
        :param pool_size:      HTTPAdapter max pool size
        :param skipped_issue   Mark skipped test items with 'To Investigate',
                               default value 'True'
        """
        if self.rp is None:
            logger.debug('ReportPortal - Init service: '
                         'endpoint={0}, project={1}, uuid={2}'.format(
                             endpoint, project, uuid))
            self.rp = ReportPortalService(endpoint=endpoint,
                                          project=project,
                                          token=uuid,
                                          log_batch_size=log_batch_size,
                                          max_pool_size=pool_size,
                                          is_skipped_an_issue=skipped_issue)
        else:
            raise RobotServiceException(
                'RobotFrameworkService is already initialized.')
コード例 #2
0
ファイル: test_service.py プロジェクト: doyou89/client-Python
    def test_get_system_information_docker(self):
        """Test that cpu key value is not empty.

        platform.processor() returns empty string in case it was called
        inside of the Docker container. API does not allow empty values
        for the attributes.
        """
        result = ReportPortalService.get_system_information('pytest')
        assert result['cpu'] == 'unknown'
コード例 #3
0
 def init_service(endpoint, project, uuid):
     if RobotService.rp is None:
         logging.debug("ReportPortal - Init service: "
                       "endpoint={0}, project={1}, uuid={2}".format(
                           endpoint, project, uuid))
         RobotService.rp = ReportPortalService(endpoint=endpoint,
                                               project=project,
                                               token=uuid)
     else:
         raise Exception("RobotFrameworkService is already initialized")
コード例 #4
0
    def test_get_system_information(self):
        """Test for validate get_system_information."""

        expected_result = {'agent': 'pytest-pytest 5.0',
                           'cpu': 'amd',
                           'machine': 'Windows-PC',
                           'os': 'linux'}

        cond = (ReportPortalService.get_system_information('pytest')
                == expected_result)
        assert cond
コード例 #5
0
    def test_get_system_information_without_pkg(self):
        """Test in negative form for validate get_system_information."""

        expected_result = {'agent': 'not found',
                           'cpu': 'amd',
                           'machine': 'Windows-PC',
                           'os': 'linux'}

        cond = (ReportPortalService.get_system_information('pytest')
                == expected_result)
        assert cond
コード例 #6
0
ファイル: test_service.py プロジェクト: doyou89/client-Python
 def test_get_system_information(self, distro):
     """Test for validate get_system_information."""
     distro.return_value.version = '5.0'
     expected_result = {
         'agent': 'reportportal-client-5.0',
         'cpu': 'amd',
         'machine': 'Windows-PC',
         'os': 'linux'
     }
     cond = (ReportPortalService.get_system_information(
         'reportportal-client') == expected_result)
     assert cond
コード例 #7
0
    def init_service(endpoint: str, project: str, uuid: str) -> None:
        """Initialization of the service for working with the Report Portal.

        Args:
            endpoint: Report Portal endpoint.
            project: Report Portal project name.
            uuid: Report Portal uuid.
        """
        if RobotService.rp is None:
            RobotService.rp = ReportPortalService(endpoint=endpoint, project=project, token=uuid)
        else:
            raise Exception("RobotFrameworkService is already initialized.")
コード例 #8
0
ファイル: paec.py プロジェクト: WandyYing/selenium
def run__tests_with_report_portal(args):
    """Run tests with report portal integration.

    This function creates a new launch in Report Portal and
    passes it into the test runner method.

    Args:
        args: parsed arguments using argparse.

    Returns:
        Exit code as an execution result of test run script.
    """
    # init report portal service to create new launch
    rp_service = ReportPortalService(endpoint=args.rp_endpoint, project=args.rp_project, token=args.rp_uuid)
    # register new launch to serve test results
    launch_name = args.rp_launch_name or " TEST REPORT"
    launch_id = _rp_register_launch(rp_service_instance=rp_service, rp_launch_name=launch_name,
                                    rp_launch_doc=args.rp_launch_doc, rp_launch_tags=args.rp_launch_tags)
    print("**"*60)
    print("launch_id: %r" % launch_id)
    # register params to pass
    rp_params = [
        '--listener', 'reportportal_listener:{launch_id}'.format(launch_id=launch_id),
        '--variable', 'RP_ENDPOINT:{rp_endpoint}'.format(rp_endpoint=args.rp_endpoint),
        '--variable', 'RP_UUID:{rp_uuid}'.format(rp_uuid=args.rp_uuid),
        '--variable', 'RP_LAUNCH:\'{rp_launch_name}\''.format(rp_launch_name=launch_name),
        '--variable', 'RP_PROJECT:{rp_project}'.format(rp_project=args.rp_project),
        '--variable', 'RP_LAUNCH_TAGS:{rp_launch_tags}'.format(rp_launch_tags=args.rp_launch_tags),
        '--variable', 'RP_LAUNCH_DOC:\'{rp_launch_doc}\''.format(rp_launch_doc=args.rp_launch_doc),
        args.tests_folder_name,
    ]  # yapf: disable
    # run pabot execution with parameters of report portal integration
    rt_code = run__tests(rp_params)
    # close report portal launch after script ends up with running tests
    print("**"*60)
    print("_rp_close_launch: %r" % launch_id)
    _rp_close_launch(rp_service_instance=rp_service)
    return rt_code
コード例 #9
0
def rp_service():
    """Prepare instance of the ReportPortalService for testing."""
    service = ReportPortalService('http://endpoint', 'project', 'token')
    service.session = mock.Mock()
    return service
コード例 #10
0
class RobotService(object):
    """Class represents service that sends Robot items to Report Portal."""
    def __init__(self):
        """Initialize service attributes."""
        self.agent_name = 'robotframework-reportportal'
        self.agent_version = get_package_version(self.agent_name)
        self.rp = None

    def _get_launch_attributes(self, cmd_attrs):
        """Generate launch attributes including both system and user ones.

        :param list cmd_attrs: List for attributes from the command line
        """
        attributes = cmd_attrs or []
        system_attributes = get_launch_sys_attrs()
        system_attributes['agent'] = ('{}-{}'.format(self.agent_name,
                                                     self.agent_version))
        return attributes + _dict_to_payload(system_attributes)

    def init_service(self,
                     endpoint,
                     project,
                     uuid,
                     log_batch_size,
                     pool_size,
                     skipped_issue=True):
        """Initialize common reportportal client.

        :param endpoint:       Report Portal API endpoint
        :param project:        Report Portal project
        :param uuid:           API token
        :param log_batch_size: Number of logs to be sent within one batch
        :param pool_size:      HTTPAdapter max pool size
        :param skipped_issue   Mark skipped test items with 'To Investigate',
                               default value 'True'
        """
        if self.rp is None:
            logger.debug('ReportPortal - Init service: '
                         'endpoint={0}, project={1}, uuid={2}'.format(
                             endpoint, project, uuid))
            self.rp = ReportPortalService(endpoint=endpoint,
                                          project=project,
                                          token=uuid,
                                          log_batch_size=log_batch_size,
                                          max_pool_size=pool_size,
                                          is_skipped_an_issue=skipped_issue)
        else:
            raise RobotServiceException(
                'RobotFrameworkService is already initialized.')

    def terminate_service(self):
        """Terminate common reportportal client."""
        if self.rp is not None:
            self.rp.terminate()

    def start_launch(self, launch, mode=None, ts=None, skip_analytics=False):
        """Call start_launch method of the common client.

        :param launch:         Instance of the Launch class
        :param mode:           Launch mode
        :param ts:             Start time
        :param skip_analytics: Skip reporting of agent name and version to GA?
        :return:               launch UUID
        """
        sl_pt = {
            'attributes': self._get_launch_attributes(launch.attributes),
            'description': launch.doc,
            'name': launch.name,
            'mode': mode,
            'start_time': ts or to_epoch(launch.start_time) or timestamp()
        }
        logger.debug(
            'ReportPortal - Start launch: request_body={0}'.format(sl_pt))
        if not skip_analytics:
            send_event(self.agent_name, self.agent_version)
        return self.rp.start_launch(**sl_pt)

    def finish_launch(self, launch, ts=None):
        """Finish started launch.

        :param launch: Launch name
        :param ts:     End time
        """
        fl_rq = {
            'end_time': ts or to_epoch(launch.end_time) or timestamp(),
            'status': STATUS_MAPPING[launch.status]
        }
        logger.debug(
            'ReportPortal - Finish launch: request_body={0}'.format(fl_rq))
        self.rp.finish_launch(**fl_rq)

    def start_suite(self, suite, ts=None):
        """Call start_test method of the common client.

        :param suite: model.Suite object
        :param ts:    Start time
        :return:      Suite UUID
        """
        start_rq = {
            'attributes': None,
            'description': suite.doc,
            'item_type': suite.type,
            'name': suite.name,
            'parent_item_id': suite.rp_parent_item_id,
            'start_time': ts or to_epoch(suite.start_time) or timestamp()
        }
        logger.debug(
            'ReportPortal - Start suite: request_body={0}'.format(start_rq))
        return self.rp.start_test_item(**start_rq)

    def finish_suite(self, suite, issue=None, ts=None):
        """Finish started suite.

        :param suite: Instance of the started suite item
        :param issue: Corresponding issue if it exists
        :param ts:    End time
        """
        fta_rq = {
            'end_time': ts or to_epoch(suite.end_time) or timestamp(),
            'issue': issue,
            'item_id': suite.rp_item_id,
            'status': STATUS_MAPPING[suite.status]
        }
        logger.debug(
            'ReportPortal - Finish suite: request_body={0}'.format(fta_rq))
        self.rp.finish_test_item(**fta_rq)

    def start_test(self, test, ts=None):
        """Call start_test method of the common client.

        :param test: model.Test object
        :param ts:   Start time
        """
        # Item type should be sent as "STEP" until we upgrade to RPv6.
        # Details at:
        # https://github.com/reportportal/agent-Python-RobotFramework/issues/56
        start_rq = {
            'attributes': test.attributes,
            'code_ref': test.code_ref,
            'description': test.doc,
            'item_type': 'STEP',
            'name': test.name,
            'parent_item_id': test.rp_parent_item_id,
            'start_time': ts or to_epoch(test.start_time) or timestamp(),
            'test_case_id': test.test_case_id
        }
        logger.debug(
            'ReportPortal - Start test: request_body={0}'.format(start_rq))
        return self.rp.start_test_item(**start_rq)

    def finish_test(self, test, issue=None, ts=None):
        """Finish started test case.

        :param test:  Instance of started test item
        :param issue: Corresponding issue if it exists
        :param ts:    End time
        """
        fta_rq = {
            'attributes': test.attributes,
            'end_time': ts or to_epoch(test.end_time) or timestamp(),
            'issue': issue,
            'item_id': test.rp_item_id,
            'status': STATUS_MAPPING[test.status]
        }
        logger.debug(
            'ReportPortal - Finish test: request_body={0}'.format(fta_rq))
        self.rp.finish_test_item(**fta_rq)

    def start_keyword(self, keyword, ts=None):
        """Call start_test method of the common client.

        :param keyword: model.Keyword object
        :param ts:      Start time
        """
        start_rq = {
            'description': keyword.doc,
            'has_stats': False,
            'item_type': keyword.get_type(),
            'name': keyword.get_name(),
            'parent_item_id': keyword.rp_parent_item_id,
            'start_time': ts or to_epoch(keyword.start_time) or timestamp()
        }
        logger.debug(
            'ReportPortal - Start keyword: request_body={0}'.format(start_rq))
        return self.rp.start_test_item(**start_rq)

    def finish_keyword(self, keyword, issue=None, ts=None):
        """Finish started keyword item.

        :param keyword: Instance of started keyword item
        :param issue:   Corresponding issue if it exists
        :param ts:      End time
        """
        fta_rq = {
            'end_time': ts or to_epoch(keyword.end_time) or timestamp(),
            'issue': issue,
            'item_id': keyword.rp_item_id,
            'status': STATUS_MAPPING[keyword.status]
        }
        logger.debug(
            'ReportPortal - Finish keyword: request_body={0}'.format(fta_rq))
        self.rp.finish_test_item(**fta_rq)

    def log(self, message, ts=None):
        """Send log message to Report Portal.

        :param message: model.LogMessage object
        :param ts:      Timestamp
        """
        sl_rq = {
            'attachment': message.attachment,
            'item_id': message.item_id,
            'level': LOG_LEVEL_MAPPING[message.level],
            'message': message.message,
            'time': ts or timestamp()
        }
        self.rp.log(**sl_rq)