# Path: test/framework/abstract_api.py
# class AbstractApiJob(metaclass=abc.ABCMeta):
#     @abc.abstractmethod
#     def invoke(self, securitytoken, build_params, cause, description):
#         raise Exception("AbstractNotImplemented")
# 
#     # The following should be declare abstract, but since they are 'implemented' by proxy we can't do that (conveniently)
#     # def is_running(self):
#     # def is_queued(self):
#     # def get_last_build_or_none(self):
#     # def get_build_triggerurl(self):
#     # def update_config(self, config_xml):
#     # def poll(self):
# 
# class AbstractApiJenkins(metaclass=abc.ABCMeta):
#     @abc.abstractmethod
#     def create_job(self, job_name, config_xml):
#         raise Exception("AbstractNotImplemented")
# 
#     @abc.abstractmethod
#     def delete_job(self, job_name):
#         raise Exception("AbstractNotImplemented")
# 
#     @abc.abstractmethod
#     def get_job(self, name):
#         raise Exception("AbstractNotImplemented")
# 
#     @abc.abstractmethod
#     def poll(self):
#         raise Exception("AbstractNotImplemented")
# 
# Path: test/framework/config.py



import abc
import os
from collections import OrderedDict
from os.path import join as jp
from jenkinsflow.api_base import UnknownJobException, BuildResult, Progress
from .abstract_api import AbstractApiJob, AbstractApiJenkins
from .config import test_tmp_dir

class Jobs():
    def __init__(self, api):
        self.api = api

    def __enter__(self):
        return self

    def __exit__(self, exc_type, exc_value, traceback):
        if exc_type:
            return None

        test_jobs = self.api.test_jobs
        for job_name, job in test_jobs.items():
            if job.flow_created:
                # Patch up another job that is supposed to be created by this job - replace job_name with job reference
                for other_job in test_jobs.values():
                    if isinstance(other_job.create_job, str):
                        other_job_name = self.api.job_name_prefix + other_job.create_job
                        if other_job_name == job_name:
                            other_job.create_job = job
                            break
                else:
                    raise Exception("Job: " + repr(job_name) + " is supposed to be created by another job, but that job was not found")

        for job_name, job in test_jobs.items():
            if job.create_job and isinstance(job.create_job, str):
                raise Exception("Job: " + repr(job_name) + " is supposed to create job: " + repr(job.create_job) + " but definition for that job was not found")



# Path: test/framework/abstract_api.py
# class AbstractApiJob(metaclass=abc.ABCMeta):
#     @abc.abstractmethod
#     def invoke(self, securitytoken, build_params, cause, description):
#         raise Exception("AbstractNotImplemented")
# 
#     # The following should be declare abstract, but since they are 'implemented' by proxy we can't do that (conveniently)
#     # def is_running(self):
#     # def is_queued(self):
#     # def get_last_build_or_none(self):
#     # def get_build_triggerurl(self):
#     # def update_config(self, config_xml):
#     # def poll(self):
# 
# class AbstractApiJenkins(metaclass=abc.ABCMeta):
#     @abc.abstractmethod
#     def create_job(self, job_name, config_xml):
#         raise Exception("AbstractNotImplemented")
# 
#     @abc.abstractmethod
#     def delete_job(self, job_name):
#         raise Exception("AbstractNotImplemented")
# 
#     @abc.abstractmethod
#     def get_job(self, name):
#         raise Exception("AbstractNotImplemented")
# 
#     @abc.abstractmethod
#     def poll(self):
#         raise Exception("AbstractNotImplemented")
# 
# Path: test/framework/config.py



# Path: test/framework/base_test_api.py
import abc
import os
from collections import OrderedDict
from os.path import join as jp
from jenkinsflow.api_base import UnknownJobException, BuildResult, Progress
from .abstract_api import AbstractApiJob, AbstractApiJenkins
from .config import test_tmp_dir


class Jobs():
    def __init__(self, api):
        self.api = api

    def __enter__(self):
        return self

    def __exit__(self, exc_type, exc_value, traceback):
        if exc_type:
            return None

        test_jobs = self.api.test_jobs
        for job_name, job in test_jobs.items():
            if job.flow_created:
                # Patch up another job that is supposed to be created by this job - replace job_name with job reference
                for other_job in test_jobs.values():
                    if isinstance(other_job.create_job, str):
                        other_job_name = self.api.job_name_prefix + other_job.create_job
                        if other_job_name == job_name:
                            other_job.create_job = job
                            break
                else:
                    raise Exception("Job: " + repr(job_name) + " is supposed to be created by another job, but that job was not found")

        for job_name, job in test_jobs.items():
            if job.create_job and isinstance(job.create_job, str):
                raise Exception("Job: " + repr(job_name) + " is supposed to create job: " + repr(job.create_job) + " but definition for that job was not found")



class TestJenkins(AbstractApiJenkins, metaclass=abc.ABCMeta):