Skip to content

Commit

Permalink
Refactor to use pathlib's read_test() and write_test()
Browse files Browse the repository at this point in the history
  • Loading branch information
epicserve committed Nov 3, 2024
1 parent bb7c572 commit 4c96f4d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
9 changes: 3 additions & 6 deletions src/dj_beat_drop/new.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,25 +96,22 @@ def create_dot_envfile(project_dir, context: dict[str, str]):
sqlite_url += "?" + urllib.parse.urlencode(EXTRA_SQLITE_PARAMS)
env_content = f"DEBUG=True\nSECRET_KEY=\"{context['secret_key']}\"\nALLOWED_HOSTS=\nDATABASE_URL={sqlite_url}\n"

with open(env_file_path, "w") as f:
f.write(env_content)
env_file_path.write_text(env_content)


def replace_variables(project_dir, context: dict[str, str], initialize_env):
for file in project_dir.rglob("*"):
if file.is_file() is False:
continue
with file.open() as f:
content = f.read()
content = file.read_text()
for variable, value in context.items():
content = content.replace(f"{{{{ {variable} }}}}", value)
if str(file.relative_to(project_dir)) == "config/settings.py" and initialize_env is True:
content = replace_settings_with_environs(content)
create_dot_envfile(project_dir, context)
if str(file.relative_to(project_dir)) == "config/settings.py" and initialize_env is False:
content = replace_sqlite_config(content, context["django_version"])
with file.open("w") as f:
f.write(content)
file.write_text(content)


def create_new_project(
Expand Down
3 changes: 1 addition & 2 deletions tests/test_new_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,7 @@ def assert_files_are_correct(
assertions.extend(env_assertions)
else:
assertions.extend(NO_ENV_ASSERTIONS.get(relative_path, []))
with open(file) as f:
content = f.read()
content = file.read_text()
for assertion_pattern in assertions:
version_str = None
if isinstance(assertion_pattern, list | tuple) is True:
Expand Down

0 comments on commit 4c96f4d

Please sign in to comment.