def test_log_cleanup_step_based(mock_timestamp, scope, item_type, item_id):
    cfg = Config(endpoint="E", token="T", project="P", step_based=True)
    mock_timestamp.return_value = 123
    mock_rps = mock.create_autospec(ReportPortalService)
    mock_context, mock_func1, mock_func2 = mock.Mock(), mock.Mock, mock.Mock()
    mock_func1.__name__ = "cleanup_func1"
    mock_func2.__name__ = "cleanup_func2"
    mock_context._stack = [
        {"@layer": scope, "@cleanups": [mock_func1, mock_func2]}
    ]
    ba = BehaveAgent(cfg, mock_rps)
    ba._feature_id = "feature_id"
    ba._scenario_id = "scenario_id"
    ba._log_cleanups(mock_context, scope)
    calls = [
        mock.call(
            name="Execution of '{}' cleanup function".format(f_name),
            start_time=123,
            item_type=item_type,
            parent_item_id=item_id,
        )
        for f_name in ("cleanup_func1", "cleanup_func2")
    ]
    mock_rps.start_test_item.assert_has_calls(calls)
    assert mock_rps.finish_test_item.call_count == 2
def test_start_launch_with_rerun(mock_timestamp):
    mock_timestamp.return_value = 123
    mock_rps = mock.create_autospec(ReportPortalService)
    mock_rps.launch_id = None
    mock_context = mock.Mock()
    cfg = Config(
        endpoint="endpoint",
        token="token",
        project="project",
        launch_name="launch_name",
        launch_description="launch_description",
        retun=True,
        rerun_of="launch_id",
    )
    ba = BehaveAgent(cfg, mock_rps)
    ba.start_launch(mock_context, some_key="some_value")
    mock_rps.start_launch.assert_called_once_with(
        name=cfg.launch_name,
        start_time=123,
        attributes=ba._get_launch_attributes(),
        description=cfg.launch_description,
        some_key="some_value",
        rerun=cfg.rerun,
        rerunOf=cfg.rerun_of,
    )
def config():
    return Config(
        endpoint="endpoint",
        token="token",
        project="project",
        launch_id=None,
        launch_name="launch_name",
        launch_description="launch_description",
    )
def test_log_fixtures(mock_timestamp):
    mock_timestamp.return_value = 123
    cfg = Config(
        endpoint="endpoint",
        token="token",
        project="project",
        step_based="False",
    )
    mock_rps = mock.create_autospec(ReportPortalService)
    mock_item = mock.Mock()
    mock_item.tags = ["fixture.A", "fixture.B"]
    BehaveAgent(cfg, mock_rps)._log_fixtures(mock_item, "type", "item_id")
    mock_rps.log.assert_has_calls(
        [
            mock.call(
                123,
                "Using of '{}' fixture".format(t),
                level="INFO",
                item_id="item_id",
            )
            for t in ("A", "B")
        ],
        any_order=True,
    )
    cfg.step_based = True
    BehaveAgent(cfg, mock_rps)._log_fixtures(mock_item, "type", "item_id")
    mock_rps.start_test_item.assert_has_calls(
        [
            mock.call(
                start_time=123,
                name="Using of '{}' fixture".format(t),
                item_type="type",
                parent_item_id="item_id",
            )
            for t in ("A", "B")
        ],
        any_order=True,
    )
    assert mock_rps.finish_test_item.call_count == 2
def test_create_rp_service_init(mock_rps):
    create_rp_service(Config(endpoint="A", token="B", project="C"))
    mock_rps.assert_has_calls(
        [
            mock.call(
                endpoint="A",
                launch_id=None,
                token="B",
                project="C",
                is_skipped_an_issue=False,
                retries=None,
            )
        ],
        any_order=True,
    )
def test_rp_is_none():
    ba = BehaveAgent(Config(), None)
    ba.start_step(mock.Mock(), mock.Mock)
    assert ba._step_id is None
def test_init_invalid_config():
    ba = BehaveAgent(Config())
    assert ba._rp is None, "Incorrect initialization of agent"
def test_create_rp_service_disabled_rp():
    assert (
        create_rp_service(Config()) is None
    ), "Service is not None for disabled integration with RP in config"