# Path: test/framework/api_select.py
# def api(file_name, api_type, login=None, fixed_prefix=None, url_or_dir=None, fake_public_uri=None, invocation_class=None,
#         username=None, password=None):
# 
# Path: test/cfg.py
# class ApiType(Enum):
#     JENKINS = 0
#     SCRIPT = 1
#     MOCK = 2


import sys, os
import subprocess
import pytest
from os.path import join as jp
from pytest import raises
from jenkinsflow.flow import serial
from jenkinsflow.utils.set_build_description import set_build_description
from jenkinsflow.cli.cli import cli
from .framework import api_select
from .framework.cfg import jenkins_security
from . import cfg as test_cfg
from .cfg import ApiType
        _, _, build_num = job.job_status()

        assert _get_description(api, job, build_num) == 'BBB3#BBB4!!BBB5'


@pytest.mark.not_apis(ApiType.MOCK)
def test_set_build_description_utils_from_inside_job_using_build_url(api_type):
    pytest.xfail('TODO')
    with api_select.api(__file__, api_type, login=True) as api:
        api.flow_job()
        job_name = 'job-1'
        api.job(job_name, max_fails=0, expect_invocations=1, expect_order=1,
                set_build_descriptions=(('BBB3', True, '\\n'), ('BBB4', False, '#'), ('BBB5', False, '!!')))

        # Need to read the build number
        if api.api_type == ApiType.SCRIPT:
            # TODO: This can't be called here for Jenkins API. Why?
            job = api.get_job(api.job_name_prefix + job_name)
            _clear_description(api, job)

        with serial(api, timeout=70, job_name_prefix=api.job_name_prefix, report_interval=1, description="AAA") as ctrl1:
            ctrl1.invoke(job_name, password='a', s1='b')

        if api.api_type != ApiType.SCRIPT:
            job = api.get_job(api.job_name_prefix + job_name)
        _, _, build_num = job.job_status()

        assert _get_description(api, job, build_num) == 'BBB3#BBB4!!BBB5'



# Path: test/framework/api_select.py
# def api(file_name, api_type, login=None, fixed_prefix=None, url_or_dir=None, fake_public_uri=None, invocation_class=None,
#         username=None, password=None):
# 
# Path: test/cfg.py
# class ApiType(Enum):
#     JENKINS = 0
#     SCRIPT = 1
#     MOCK = 2


# Path: test/set_build_description_test.py
import sys, os
import subprocess
import pytest
from os.path import join as jp
from pytest import raises
from jenkinsflow.flow import serial
from jenkinsflow.utils.set_build_description import set_build_description
from jenkinsflow.cli.cli import cli
from .framework import api_select
from .framework.cfg import jenkins_security
from . import cfg as test_cfg
from .cfg import ApiType

        _, _, build_num = job.job_status()

        assert _get_description(api, job, build_num) == 'BBB3#BBB4!!BBB5'


@pytest.mark.not_apis(ApiType.MOCK)
def test_set_build_description_utils_from_inside_job_using_build_url(api_type):
    pytest.xfail('TODO')
    with api_select.api(__file__, api_type, login=True) as api:
        api.flow_job()
        job_name = 'job-1'
        api.job(job_name, max_fails=0, expect_invocations=1, expect_order=1,
                set_build_descriptions=(('BBB3', True, '\\n'), ('BBB4', False, '#'), ('BBB5', False, '!!')))

        # Need to read the build number
        if api.api_type == ApiType.SCRIPT:
            # TODO: This can't be called here for Jenkins API. Why?
            job = api.get_job(api.job_name_prefix + job_name)
            _clear_description(api, job)

        with serial(api, timeout=70, job_name_prefix=api.job_name_prefix, report_interval=1, description="AAA") as ctrl1:
            ctrl1.invoke(job_name, password='a', s1='b')

        if api.api_type != ApiType.SCRIPT:
            job = api.get_job(api.job_name_prefix + job_name)
        _, _, build_num = job.job_status()

        assert _get_description(api, job, build_num) == 'BBB3#BBB4!!BBB5'



@pytest.mark.not_apis(ApiType.MOCK, ApiType.SCRIPT)