Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add .env.example file on project creation #3

Open
mfonism opened this issue Oct 5, 2020 · 0 comments
Open

Add .env.example file on project creation #3

mfonism opened this issue Oct 5, 2020 · 0 comments
Labels

Comments

@mfonism
Copy link
Owner

mfonism commented Oct 5, 2020

classy-start project <project-name> already creates a .env file. But this file's pattern has been rightfully added to .gitignore and probably never leaves the developer's PC.

It would be nice to have a .env.example which starts out containing the variables in the .env file, but without their values. For now its content could be:

SECRET_KEY = ""
DEBUG = True

# space delimited string of allowed hosts
ALLOWED_HOSTS = ""

This one will at least get sent to remote on push, so other developers can have an idea what environment variables they are to set for the project to work well.

Working on this issue, you'll only have to update the following function:

def follow_up_start_project(name: str, directory: Optional[str] = None):
if directory is None:
manage_dir = pathlib.Path(".") / name
else:
manage_dir = pathlib.Path(directory)
manage_dir.resolve(strict=True)
name_change_map = {
"secrets.py": ".env",
"gitignore.py": ".gitignore",
"requirements.py": "requirements.txt",
}
for (old_name, new_name) in name_change_map.items():
rename_file(old_name, new_name, base_dir=manage_dir)
create_accounts_app(manage_dir)

And its associated test function:

@mock.patch("pathlib.Path.resolve")
@mock.patch("classy_start.start.rename_file")
@mock.patch("classy_start.start.create_accounts_app")
def test_follow_up_start_project(
mock_create_accounts_app, mock_rename_file, _mock_resolve
):
"""
Assert that ~.follow_up_start_project() calls ~.rename_file() the correct number of
times and with the correct arguments. And that it also calls
~.create_accounts_app() with the correct arguments.
"""
follow_up_start_project("projectible")
assert mock_rename_file.call_count == 3
mock_rename_file.assert_has_calls(
[
mock.call("secrets.py", ".env", base_dir=pathlib.Path("projectible")),
mock.call(
"gitignore.py", ".gitignore", base_dir=pathlib.Path("projectible")
),
mock.call(
"requirements.py",
"requirements.txt",
base_dir=pathlib.Path("projectible"),
),
]
)
mock_create_accounts_app.assert_called_once_with(pathlib.Path("projectible"))
# reset the **all used** mocks
mock_rename_file.reset_mock()
mock_create_accounts_app.reset_mock()
follow_up_start_project("projectible", pathlib.Path("."))
assert mock_rename_file.call_count == 3
mock_rename_file.assert_has_calls(
[
mock.call("secrets.py", ".env", base_dir=pathlib.Path(".")),
mock.call("gitignore.py", ".gitignore", base_dir=pathlib.Path(".")),
mock.call(
"requirements.py", "requirements.txt", base_dir=pathlib.Path("."),
),
]
)
mock_create_accounts_app.assert_called_once_with(pathlib.Path("."))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant