def test_traefik_extra_services_with_remove(
            self, project_loader, module_scoped_container_getter):
        project_loader("extra-services")

        setup_cfssl(module_scoped_container_getter)

        main(["configure"])

        api_toml = os.path.join(config.paths.home, "traefik", "config",
                                "sub.project.test.extra-service.api.toml")
        cert = os.path.join(config.paths.home, "certs", "sub.project.test.crt")
        key = os.path.join(config.paths.home, "certs", "sub.project.test.key")
        web_toml = os.path.join(config.paths.home, "traefik", "config",
                                "rule.project.test.extra-service.web.toml")

        assert os.path.exists(api_toml)
        assert os.path.exists(cert)
        assert os.path.exists(key)
        assert os.path.exists(web_toml)

        with open("ddb.yml", "w"):
            pass

        Config.defaults = {'defaults': {'fail_fast': True}}

        setup_cfssl(module_scoped_container_getter)

        main(["configure"])

        assert not os.path.exists(api_toml)
        assert not os.path.exists(cert)
        assert not os.path.exists(key)
        assert not os.path.exists(web_toml)
    def test_config_output_extra_filenames_some_files_option(
            self, project_loader, capsys: CaptureFixture):
        project_loader("extra-filenames")

        main(["config", "some", "--files"])

        reset()

        output = capsys.readouterr().out

        parts = [part.lstrip() for part in output.split('---') if part.strip()]
        assert len(parts) == 1

        configurations = {}

        for part in parts:
            filename, config = part.split('\n', 1)
            assert filename.startswith('# ')
            filename = filename[2:]
            filename = os.path.relpath(filename, os.getcwd())
            configurations[filename] = Dotty(yaml.safe_load(config))

        assert ('some.custom.yml',) == \
               tuple(configurations.keys())

        assert configurations['some.custom.yml']['some'] is True
        assert 'app.value' not in configurations['some.custom.yml']
    def test_templates(self, project_loader):
        project_loader("empty")

        main(["configure"])

        assert os.path.exists(os.path.join('.gitignore'))
        assert expect_gitignore('.gitignore', '/*ddb.local.*')
    def test_traefik_extra_services_without_remove(
            self, project_loader, module_scoped_container_getter):
        project_loader("extra-services")

        setup_cfssl(module_scoped_container_getter)

        main(["configure"])

        api_toml = os.path.join(config.paths.home, "traefik", "config",
                                "sub.project.test.extra-service.api.toml")
        cert = os.path.join(config.paths.home, "certs", "sub.project.test.crt")
        key = os.path.join(config.paths.home, "certs", "sub.project.test.key")
        web_toml = os.path.join(config.paths.home, "traefik", "config",
                                "rule.project.test.extra-service.web.toml")

        assert os.path.exists(api_toml)
        assert os.path.exists(cert)
        assert os.path.exists(key)
        assert os.path.exists(web_toml)

        main(["configure"])

        assert os.path.exists(api_toml)
        assert os.path.exists(cert)
        assert os.path.exists(key)
        assert os.path.exists(web_toml)
    def test_ensure_chaining_with_custom_dependencies(self, project_loader):
        project_loader("ensure-chaining-with-custom-dependencies")

        main(["configure"])

        main(["activate"])

        assert not os.path.exists("test.dev.yml.jsonnet")
        assert os.path.exists("test.dev.yml.jinja")
        with open("test.dev.yml.jinja", "r") as dockerfile:
            data = dockerfile.read().splitlines()
            assert data == ['{', '   "env": "{{ core.env.current }}"', '}']

        assert os.path.exists("test.dev.yml")
        with open("test.dev.yml", "r") as dockerfile:
            data = dockerfile.read()
            assert yaml.load(data, yaml.SafeLoader) == {"env": "dev"}

        assert os.path.exists("test.yml")
        with open("test.yml", "r") as dockerfile:
            data = dockerfile.read()
            assert yaml.load(data, yaml.SafeLoader) == {"env": "dev"}

        assert os.path.islink("test.yml")

        assert os.path.exists(".gitignore")
        assert expect_gitignore('.gitignore', '/test.dev.yml.jinja',
                                '/test.dev.yml', '/test.yml')
Exemple #6
0
    def test_global_aliases_projects_in_home(self, project_loader, data_dir):
        def project_in_home_config_provider(root_dir):
            paths = ConfigPaths(ddb_home=os.path.join(root_dir, 'ddb_home'),
                                home=os.path.join(root_dir, 'home'),
                                project_home=os.path.join(
                                    root_dir, 'home', 'project'))

            if not [path for path in paths if os.path.isdir(path)]:
                paths = ConfigPaths(ddb_home=None,
                                    home=None,
                                    project_home=root_dir)

            config.paths = paths
            config.load()

            return config

        project_loader("global_aliases_projects_in_home",
                       config_provider=project_in_home_config_provider)

        main(["configure"])

        alias = "dc.bat" if os.name == 'nt' else "dc"

        assert not os.path.exists(os.path.join(".bin", alias))
        assert os.path.exists(os.path.join(config.paths.home, ".bin", alias))
        assert not expect_gitignore('.gitignore', '../home/.bin/dc')

        with open(os.path.join(config.paths.home, ".bin", alias), 'r') as f:
            content = f.read()
            if os.name != 'nt':
                assert 'docker-compose "$@"' in content
    def test_activate(self, project_loader):
        project_loader("symfony-vuejs")

        main(["configure"])

        main(["activate"])

        assert os.path.exists("docker-compose.override.yml")

        assert sorted(os.listdir(".docker/php/.ca-certificates")) == \
               sorted(("GFI_Informatique_Orléans_Root_CA.crt",
                       "some-cert.crt",
                       "fwca.annuaire.groupe.local.crt"))

        assert os.path.exists(os.path.join(".docker", "db", "Dockerfile"))
        assert os.path.exists(os.path.join(".docker", "php", "Dockerfile"))
        assert os.path.exists(os.path.join(".docker", "php", "fixuid.tar.gz"))
        with open(os.path.join(".docker", "php", "Dockerfile"), "r") as dockerfile:
            data = dockerfile.read()
            assert "COPY .ca-certificates/* /usr/local/share/ca-certificates/" in data
            assert "ADD fixuid.tar.gz /usr/local/bin" in data

        assert os.path.exists(".gitignore")
        with open(".gitignore", "r") as gitignore_file:
            gitignore_lines = gitignore_file.read().splitlines()
            assert gitignore_lines
    def test_ensure_chaining(self, project_loader):
        project_loader("ensure-chaining")

        main(["configure"])

        main(["activate"])

        assert os.path.exists("test.dev.yml.jsonnet")
        assert not os.path.exists("test.dev.yml.jinja")
        with open("test.dev.yml.jsonnet", "r") as dockerfile:
            data = dockerfile.read()
            assert data == '{["e" + "n" + "v"]: "dev"}\n'

        assert os.path.exists("test.dev.yml")
        with open("test.dev.yml", "r") as dockerfile:
            data = dockerfile.read()
            assert yaml.load(data, yaml.SafeLoader) == {"env": "dev"}

        assert os.path.exists("test.yml")
        with open("test.yml", "r") as dockerfile:
            data = dockerfile.read()
            assert yaml.load(data, yaml.SafeLoader) == {"env": "dev"}

        assert os.path.islink("test.yml")

        assert os.path.exists(".gitignore")
        assert expect_gitignore('.gitignore', '/test.dev.yml.jsonnet',
                                '/test.dev.yml', '/test.yml')
    def test_config_local_falsy(self, project_loader):
        project_loader("local-falsy")

        main(["configure"], reset_disabled=True)

        assert config.data.get('app.disabled_services') == []

        reset()
def test_main_config_should_display_error(project_loader,
                                          capsys: CaptureFixture):
    project_loader("no-config")
    main(["configure"])

    outerr = capsys.readouterr()
    assert not outerr.out
    assert "No project configuration file found." in outerr.err
    def test_config_env_ddb(self, project_loader):
        project_loader("env-ddb")

        main(["configure"], reset_disabled=True)

        assert not config.data.get('app.test')

        reset()
    def test_config_extra_filenames(self, project_loader):
        project_loader("extra-filenames")

        main(["configure"], reset_disabled=True)

        assert config.data.get('another') is True
        assert config.data.get('some') is True
        assert config.data.get('app.value') == 'local'

        reset()
    def test_config_override_shell(self, project_loader):
        project_loader("override-shell")

        os.environ['DDB_OVERRIDE_SHELL_SHELL'] = 'fish'

        main(["config"], reset_disabled=True)

        assert config.data.get('shell.shell') == 'fish'

        reset()
Exemple #14
0
    def test_docker_binaries_with_clear_cache(self, project_loader,
                                              capsys: CaptureFixture):
        project_loader("docker")

        main(["--clear-cache", "configure"])

        exceptions = main(["run", "psql"])
        assert not exceptions

        assert os.path.exists(os.path.join(os.getcwd(), '.bin', 'psql'))
Exemple #15
0
    def test_empty_project_main_no_smartcd(self, project_loader,
                                           mocker: MockerFixture):
        mocker.patch('ddb.feature.smartcd.actions.is_smartcd_installed',
                     lambda: False)

        project_loader("empty")

        main(["configure"])

        assert not os.path.exists(".bash_enter")
        assert not os.path.exists(".bash_leave")
    def test_directories_overriden(self, project_loader):
        project_loader("directories-overriden")

        assert os.path.isdir("test")

        main(["configure"])

        main(["activate"])

        assert not os.path.isdir("test")
        assert os.path.isfile("test")
    def test_config_env_ddb2(self, project_loader):
        project_loader("env-ddb")

        os.rename('ddb.dev.tmp.yml', 'ddb.dev.yml')

        main(["configure"], reset_disabled=True)

        assert config.data.get('app.test')
        assert not os.path.islink("ddb.yml")

        reset()
    def test_config_merge_default(self, project_loader):
        project_loader("merge-default")

        main(["configure"], reset_disabled=True)

        assert config.data.get('core.env.current') == 'dev-services'
        assert config.data.get('core.env.available') == [
            'prod', 'stage', 'ci', 'dev', 'dev-services'
        ]

        reset()
    def test_config_merge_insert_strategy3(self, project_loader):
        project_loader("merge-insert-strategy3")

        main(["configure"], reset_disabled=True)

        assert config.data.get('core.env.current') == 'dev'
        assert config.data.get('core.env.available') == [
            'prod', 'prod', 'stage', 'stage', 'ci', 'dev'
        ]

        reset()
    def test_djp(self, project_loader):
        project_loader("djp")

        with zipfile.ZipFile('template.zip', 'r') as zip_ref:
            zip_ref.extractall('expected')

        main(["download"])

        assert os.path.exists('.docker/djp/Dockerfile.jinja')
        assert os.path.exists('.docker/djp/djp.libjsonnet')

        with open('.docker/djp/djp.libjsonnet') as djp_libjsonnet:
            assert not '// Edited\n' in djp_libjsonnet.readlines()
    def test_config_deep_custom_strategy(self, project_loader):
        project_loader("deep-local-custom-strategy")

        main(["configure"], reset_disabled=True)

        assert config.data.get('app.deep.disabled_services') == [
            'python', 'gunicorn', 'another'
        ]
        assert config.data.get('app.deep.another_strategy') == [
            'another', 'python', 'gunicorn'
        ]

        reset()
    def test_resolve_ports_conflicts(self, project_loader):
        project_loader("jsonnet-resolve-ports-conflicts")

        main(["configure"])

        assert os.path.exists('docker-compose.yml')
        with open('docker-compose.yml', 'r') as f:
            docker_compose = yaml.safe_load(f)

        with open('docker-compose.expected.yml', 'r') as f:
            docker_compose_expected = yaml.safe_load(f)

        assert docker_compose == docker_compose_expected
    def test_binary(self, project_loader):
        project_loader("jsonnet-binary")

        main(["configure"])

        assert os.path.exists('docker-compose.yml')
        with open('docker-compose.yml', 'r') as f:
            docker_compose = yaml.load(f, yaml.SafeLoader)

        with open('docker-compose.expected.yml', 'r') as f:
            docker_compose_expected = yaml.load(f, yaml.SafeLoader)

        assert docker_compose == docker_compose_expected
    def test_jsonnet_ext_var(self, project_loader):
        project_loader("jsonnet-extvar")

        main(["configure"])

        assert os.path.exists('config.yml')
        with open('config.yml', 'r') as f:
            variables = f.read()

        with open('config.expected.yml', 'r') as f:
            variables_expected = f.read()

        assert variables == variables_expected
Exemple #25
0
    def test_empty_project_main(self, project_loader):
        project_loader("empty")

        main(["configure"])

        assert os.path.exists("ddb_activate.bat")
        assert os.path.exists("ddb_deactivate.bat")

        with open("ddb_activate.bat") as f:
            assert "set command=(ddb activate)" in f.read()

        with open("ddb_deactivate.bat") as f:
            assert "set command=(ddb deactivate)" in f.read()
    def test_no_repo(self, project_loader, mocker: MockerFixture):
        mocker.patch('ddb.feature.version.is_git_repository',
                     is_git_repository)

        project_loader("no_repo")

        main(["configure"], reset_disabled=True)

        assert config.data.get('version.hash') is None
        assert config.data.get('version.short_hash') is None
        assert config.data.get('version.branch') is None
        assert config.data.get('version.version') is None
        assert config.data.get('version.tag') is None
    def test_config_more_properties_docker_ip_value(self, project_loader,
                                                    capsys: CaptureFixture):
        project_loader("more-properties")

        main(["config", "docker.ip", "--value"], reset_disabled=True)

        out = capsys.readouterr().out

        docker_ip = config.data.get('docker.ip')

        assert out == f"{docker_ip}\n"

        reset()
    def test_config_more_properties_core_env_available_value(
            self, project_loader, capsys: CaptureFixture):
        project_loader("more-properties")

        main(["config", "core.env.available", "--value"], reset_disabled=True)

        out = capsys.readouterr().out

        available = config.data.get('core.env.available')

        assert out == f"{available}\n"

        reset()
    def test_djp_patch(self, project_loader):
        project_loader("djp_patch")

        main(["download"])

        assert os.path.exists('.docker/djp/Dockerfile.jinja')
        assert os.path.exists('.docker/djp/djp.libjsonnet')

        with open('.docker/djp/Dockerfile.jinja') as djp_libjsonnet:
            assert 'replaced' not in djp_libjsonnet.read()

        with open('.docker/djp/djp.libjsonnet') as djp_libjsonnet:
            assert '// Edited\n' in djp_libjsonnet.readlines()
Exemple #30
0
    def test_docker_binaries_exe(self, project_loader, capsys: CaptureFixture):
        project_loader("docker_exe")

        exceptions = main(["configure"])
        assert not exceptions

        exceptions = main(["run", "psql"])
        assert not exceptions

        assert os.path.exists(os.path.join(os.getcwd(), '.bin', 'psql'))

        output = capsys.readouterr()
        assert output.out.strip(
        ) == docker_compose_bin + " exec --workdir=/workdir/. db psql"