def __init__(
     self,
     fs,
     root="/home/em",
     env_name="localdev",
     machine_name="localhost",
     container_name="ad",
 ):
     self.fs = fs
     self.root = root
     self.ccadmin_client = FakeCCAdminClient(None)
     self.ccadmin_client.fake_emproject_builder = self
     self.fs.create_dir(root)
     self.emproject = EMProject(ccadmin_client=self.ccadmin_client,
                                env_vars={"EM_CORE_HOME": root})
     self.config_map = {}
Beispiel #2
0
def test_something(capsys):
    classpath = "CoreEntities/InvalidProcess.xml"
    relative_src = "opt/em/products/agent_desktop/repository/default/" + classpath
    src = create_file(relative_src, contents="hola")
    em_prj_path = "/home/dgarcia/dev/python/em_automation/devtask/test/..testfilesystem/opt/em/projects/pacificorp"
    app_project = EMProject(emprj_path=em_prj_path)
    product_path = "/home/dgarcia/dev/python/em_automation/devtask/test/.testfilesystem/opt/em/products/agent_desktop"
    app_project._config = {"product.home": product_path}
    # assert "guaje" == app_project.product_layout()['repo_modules'].path
    em_prj_path = "/home/dgarcia/dev/python/em_automation/devtask/test/.testfilesystem/opt/em/projects/pacificorp"
    devtask.extend_process.app_project = AppProject(emprj_path=em_prj_path)
    product_path = "/home/dgarcia/dev/python/em_automation/devtask/test/.testfilesystem/opt/em/products/agent_desktop"
    app_project.emproject._config = {"product.home": product_path}
    app_project._em_config = {"product.home": product_path}
    extend_process(classpath)
    assert os.path.exists(src)
    assert capsys.readouterr().out == "dd"
class FakeEMProjectBuilder:
    REPO_PATH = "repository/default"

    def __init__(
        self,
        fs,
        root="/home/em",
        env_name="localdev",
        machine_name="localhost",
        container_name="ad",
    ):
        self.fs = fs
        self.root = root
        self.ccadmin_client = FakeCCAdminClient(None)
        self.ccadmin_client.fake_emproject_builder = self
        self.fs.create_dir(root)
        self.emproject = EMProject(ccadmin_client=self.ccadmin_client,
                                   env_vars={"EM_CORE_HOME": root})
        self.config_map = {}

    def add_config_settings(self, config_id, settings_map):
        self.config_map[config_id] = settings_map

    def make_valid_em_folder_layout(self):
        self.fs.create_dir(os.path.join(self.root, "bin"))
        self.fs.create_dir(os.path.join(self.root, "config"))
        self.fs.create_dir(os.path.join(self.root, "components"))
        self.fs.create_dir(os.path.join(self.root, "repository"))

    def _config_env_machine_container(self, env_name, machine_name,
                                      container_name):
        config_content = ("emautomation.environment.name=" + env_name +
                          "\nemautomation.container.name=" + container_name +
                          "\nemautomation.machine.name=" + machine_name)

        self._create_file(EMProject.EMAUTOMATION_CONFIG_PATH, config_content)
        return self

    def add_emautomation_config(self, config_content):
        self._create_file(self.emproject.emautomation_config_path(),
                          contents=config_content)

    def add_config(self, config_id, config_content):
        self._create_file(self.emproject.config_path(config_id).path,
                          contents=config_content)
        return self

    def with_ccadmin(self, ccadmin_client):
        self.ccadmin_client = ccadmin_client
        self.ccadmin_client.fake_emproject_builder = self
        self.emproject._ccadmin_client = self.ccadmin_client
        return self

    def add_repo_module(self, module_name):
        if not self._exists(self.REPO_PATH):
            self._create_dir(self.REPO_PATH)
        if module_name:
            self._create_dir(self.REPO_PATH + "/" + module_name + "/")
        return self

    def _exists(self, prj_relative_path):
        return os.path.exists(self._abs_path(prj_relative_path))

    def _create_dir(self, prj_relative_path):
        return self.fs.create_dir(self._abs_path(prj_relative_path))

    def _create_file(self, prj_relative_path, contents):
        return self.fs.create_file(self._abs_path(prj_relative_path),
                                   contents=contents)

    def _abs_path(self, prj_relative_path):
        return os.path.join(self.root, prj_relative_path)

    def build(self):
        return self.emproject
Beispiel #4
0
 def emproject(self):
     if not self._emproject:
         self._emproject = EMProject(env_vars=self.env_vars,
                                     emprj_path=self.emprj_path)
     return self._emproject
Beispiel #5
0
def make_emproject(root):
    return EMProject(env_vars={"EM_CORE_HOME": root})
Beispiel #6
0
def test_it_uses_env_var_when_cwd_not_within_emproject(fs):
    make_valid_em_folder_layout(fs, "opt/em/project")
    os.chdir("/opt/em/")
    assert ("/opt/em/project" == EMProject(env_vars={
        "EM_CORE_HOME": "/opt/em/project"
    }).root)
Beispiel #7
0
def test_computes_root_when_cwd_is_em_subfolder(fs):
    make_valid_em_folder_layout(fs, "opt/em/project")
    os.chdir("/opt/em/project/config")
    assert "/opt/em/project" == EMProject({}).root
Beispiel #8
0
def test_emautomation_config_throws_exception_if_file_not_there(fs):
    em_project = EMProject("/home/em/my_project")
    with pytest.raises(ConfigFileNotFound) as excinfo:
        em_project._emautomation_config()
    assert "Config file" in str(excinfo.value)