def test_should_install_dependency_securely_when_property_is_not_set_to_dependency(
            self, *_):
        dependency = Dependency("spam")
        self.project.set_property("install_dependencies_insecure_installation",
                                  ["some-other-dependency"])

        install_dependencies(self.logger,
                             self.project,
                             dependency,
                             self.pyb_env,
                             "install_batch",
                             constraints_file_name="constraint_file")

        self.pyb_env.execute_command.assert_called_with(
            self.pyb_env.executable + PIP_MODULE_STANZA + [
                "install", "-c", ANY, "--allow-unverified",
                "some-other-dependency", "--allow-external",
                "some-other-dependency", "spam"
            ],
            cwd=ANY,
            env=ANY,
            error_file_name=ANY,
            outfile_name=ANY,
            shell=False,
            no_path_search=True)
def _run_tavern_tests_in_dir(test_dir: str,
                             logger: Logger,
                             project: Project,
                             reactor: Reactor,
                             role=None):
    logger.info("Running tavern tests: {}".format(test_dir))
    if not os.path.exists(test_dir):
        logger.info("Skipping tavern run: no tests")
        return False
    logger.info(
        f"Found {len(os.listdir(test_dir))} files in tavern test directory")
    # todo is this unique enough for each run?
    output_file, run_name = get_test_report_file(project, test_dir)
    from sys import path as syspath
    syspath.insert(0, test_dir)
    # install any requirements that my exist
    requirements_file = os.path.join(test_dir, "requirements.txt")
    if os.path.exists(requirements_file):
        dependency = RequirementsFile(requirements_file)
        install_dependencies(
            logger, project, dependency, reactor.pybuilder_venv,
            f"{prepare_logs_directory(project)}/install_tavern_pip_dependencies.log"
        )
    extra_args = [
        project.expand(prop)
        for prop in project.get_property(TAVERN_ADDITIONAL_ARGS, [])
    ]
    args = ["--junit-xml", f"{output_file}", test_dir] + extra_args
    if project.get_property("verbose"):
        args.append("-s")
        args.append("-v")
    os.environ['TARGET'] = project.get_property(INTEGRATION_TARGET_URL)
    os.environ[ENVIRONMENT] = project.get_property(ENVIRONMENT)
    logger.info(
        f"Running against: {project.get_property(INTEGRATION_TARGET_URL)} ")
    cache_wd = os.getcwd()
    try:
        os.chdir(test_dir)
        ret = pytest.main(args)
    finally:
        os.chdir(cache_wd)
    if role:
        CloudwatchLogs(project.get_property(ENVIRONMENT),
                       project.get_property(APPLICATION), role,
                       logger).print_latest()
    if ret != 0:
        raise BuildFailedException(
            f"Tavern tests failed see complete output here - {output_file}")
    return True
    def test_should_install_dependency_without_version_on_windows_derivate(
            self, *_):
        dependency = Dependency("spam")

        install_dependencies(self.logger, self.project, dependency,
                             self.pyb_env, "install_batch")

        self.pyb_env.execute_command.assert_called_with(
            self.pyb_env.executable + PIP_MODULE_STANZA + ["install", "spam"],
            cwd=ANY,
            env=ANY,
            error_file_name=ANY,
            outfile_name=ANY,
            shell=False,
            no_path_search=True)
    def test_should_install_requirements_file_dependency(self, *_):
        dependency = RequirementsFile("requirements.txt")

        install_dependencies(self.logger, self.project, dependency,
                             self.pyb_env, "install_batch")

        self.pyb_env.execute_command.assert_called_with(
            self.pyb_env.executable + PIP_MODULE_STANZA +
            ["install", "-r", "requirements.txt"],
            cwd=ANY,
            env=ANY,
            error_file_name=ANY,
            outfile_name=ANY,
            shell=False,
            no_path_search=True)
    def test_should_install_dependency_with_url(self, *_):
        dependency = Dependency("spam", url="some_url")

        install_dependencies(self.logger, self.project, dependency,
                             self.pyb_env, "install_batch")

        self.pyb_env.execute_command.assert_called_with(
            self.pyb_env.executable + PIP_MODULE_STANZA +
            ["install", "--force-reinstall", "some_url"],
            cwd=ANY,
            env=ANY,
            error_file_name=ANY,
            outfile_name=ANY,
            shell=False,
            no_path_search=True)
    def test_should_use_extra_index_url_when_index_url_is_not_set(self, *_):
        self.project.set_property("install_dependencies_extra_index_url",
                                  "some_extra_index_url")
        dependency = Dependency("spam")

        install_dependencies(self.logger, self.project, dependency,
                             self.pyb_env, "install_batch")

        self.pyb_env.execute_command.assert_called_with(
            self.pyb_env.executable + PIP_MODULE_STANZA +
            ["install", "--extra-index-url", "some_extra_index_url", "spam"],
            cwd=ANY,
            env=ANY,
            error_file_name=ANY,
            outfile_name=ANY,
            shell=False,
            no_path_search=True)
    def test_should_install_dependency_without_version(self, *_):
        dependency = Dependency("spam")

        install_dependencies(self.logger,
                             self.project,
                             dependency,
                             self.pyb_env,
                             "install_batch",
                             constraints_file_name="constraint_file")

        self.pyb_env.execute_command.assert_called_with(
            self.pyb_env.executable + PIP_MODULE_STANZA + [
                "install", "-c",
                nc(jp(self.pyb_env.env_dir, "constraint_file")), "spam"
            ],
            cwd=ANY,
            env=ANY,
            error_file_name=ANY,
            outfile_name=ANY,
            shell=False,
            no_path_search=True)
Beispiel #8
0
    def install_dependencies(
        self,
        pip_batch,
        install_log_path=None,
        local_mapping=None,
        constraints_file_name=None,
        log_file_mode="ab",
        package_type="dependency",
        target_dir=None,
        ignore_installed=False,
    ):

        install_dependencies(self.logger,
                             self.project,
                             pip_batch,
                             self,
                             install_log_path or self.install_log_path,
                             local_mapping=local_mapping,
                             constraints_file_name=constraints_file_name,
                             log_file_mode=log_file_mode,
                             package_type=package_type,
                             target_dir=target_dir,
                             ignore_installed=ignore_installed)