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')
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_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_watch_file_created(self, project_loader, watch): project_loader("watch1") thread, main_runner = init_test_watch(watch, ["configure"]) try: assert os.path.exists("test.txt") with open("test.created.txt.jinja", "w") as template_file: template_file.write("This is {{core.project.name}} project. (created)") if not watch: main_runner() wait(lambda: os.path.exists("test.created.txt") and Path("test.created.txt").read_text() == "This is watch1 project. (created)", timeout_seconds=5) wait(lambda: os.path.exists(".gitignore") and expect_gitignore(".gitignore", "/test.txt", "/test.created.txt"), timeout_seconds=5) finally: if watch: stop_watch() if thread: thread.join()
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_copy(self, project_loader): project_loader("copy") main(["configure"]) main(["activate"]) assert os.path.exists("destination/test1") assert os.path.exists("destination/test2") assert expect_gitignore('.gitignore', '/destination/test1', '/destination/test2') os.remove("destination/test1") main(["configure"]) assert os.path.exists("destination/test1") assert os.path.exists("destination/test2") assert expect_gitignore('.gitignore', '/destination/test1', '/destination/test2')
def test_empty_project_without_core(self, project_loader): project_loader("empty") features.register(GitignoreFeature()) load_registered_features() action = UpdateGitignoreAction() action.execute(target="./to-ignore.yml") action.execute(target="./to-ignore-2.yml") assert os.path.exists('.gitignore') assert expect_gitignore('.gitignore', '/to-ignore.yml', '/to-ignore-2.yml')
def test_empty_project_global_aliases(self, project_loader): project_loader("global_aliases") 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_watch_file_delete(self, project_loader, watch): project_loader("watch1") thread, main_runner = init_test_watch(watch, ["configure"]) try: assert os.path.exists("test.txt") os.remove("test.txt.jinja") if not watch: main_runner() wait(lambda: not os.path.exists("test.txt"), timeout_seconds=5) wait(lambda: not expect_gitignore(".gitignore", "/text.txt"), timeout_seconds=5) finally: if watch: stop_watch() if thread: thread.join()
def test_eject2_with_jsonnet_disabled(self, project_loader, module_scoped_container_getter): project_loader("eject2") setup_cfssl(module_scoped_container_getter) main(["configure"]) assert os.path.exists("docker-compose.yml") assert os.path.exists("docker-compose.yml.jsonnet") assert expect_gitignore(".gitignore", "/docker-compose.yml") assert os.path.exists(os.path.join(".bin", "psql" + (".bat" if os.name == "nt" else ""))) assert expect_gitignore(".gitignore", "/.bin/psql" + (".bat" if os.name == "nt" else "")) assert os.path.exists(os.path.join(".docker", "db", "Dockerfile.jinja")) assert expect_gitignore(".gitignore", "/.docker/db/Dockerfile") os.environ['DDB_OVERRIDE_JSONNET_DOCKER_VIRTUALHOST_DISABLED'] = "1" os.environ['DDB_OVERRIDE_JSONNET_DOCKER_BINARY_DISABLED'] = "True" main(["configure", "--eject"]) assert os.path.exists("docker-compose.yml") assert not os.path.exists("docker-compose.yml.jsonnet") assert not expect_gitignore(".gitignore", "/docker-compose.yml") assert not os.path.exists(os.path.join(".bin", "psql" + (".bat" if os.name == "nt" else ""))) assert not expect_gitignore(".gitignore", "/.bin/psql" + (".bat" if os.name == "nt" else "")) assert not os.path.exists(os.path.join(".docker", "db", "Dockerfile.jinja")) assert not expect_gitignore(".gitignore", "/.docker/db/Dockerfile") with open('docker-compose.yml', 'r') as dc_file: data = yaml.load(dc_file, yaml.SafeLoader) with open('../expected/docker-compose.jsonnet.disabled.yml', 'r') as expected_dc_file: expected_data = yaml.load(expected_dc_file, yaml.SafeLoader) assert data == expected_data
def test_eject2(self, project_loader, module_scoped_container_getter): project_loader("eject2") setup_cfssl(module_scoped_container_getter) main(["configure"]) assert os.path.exists("docker-compose.yml") assert os.path.exists("docker-compose.yml.jsonnet") assert expect_gitignore(".gitignore", "/docker-compose.yml") assert os.path.exists(os.path.join(".bin", "psql" + (".bat" if os.name == "nt" else ""))) assert expect_gitignore(".gitignore", "/.bin/psql" + (".bat" if os.name == "nt" else "")) assert os.path.exists(os.path.join(".docker", "db", "Dockerfile.jinja")) assert expect_gitignore(".gitignore", "/.docker/db/Dockerfile") main(["configure", "--eject"]) assert os.path.exists("docker-compose.yml") assert not os.path.exists("docker-compose.yml.jsonnet") assert not expect_gitignore(".gitignore", "/docker-compose.yml") assert os.path.exists(os.path.join(".bin", "psql" + (".bat" if os.name == "nt" else ""))) assert expect_gitignore(".gitignore", "/.bin/psql" + (".bat" if os.name == "nt" else "")) assert not os.path.exists(os.path.join(".docker", "db", "Dockerfile.jinja")) assert not expect_gitignore(".gitignore", "/.docker/db/Dockerfile") with open('docker-compose.yml', 'r') as dc_file: data = yaml.load(dc_file, yaml.SafeLoader) with open('../expected/docker-compose.yml', 'r') as expected_dc_file: expected_data = yaml.load(expected_dc_file, yaml.SafeLoader) assert data == expected_data