mirror of
https://github.com/cookiecutter/cookiecutter-django.git
synced 2024-11-22 01:26:57 +03:00
Trim leading and trailing space in domain_name
and email
(#4163)
* remove trailing space in domain_name and email * Add test for leading and trailing spaces removals * Move magic string and add a comment explaining its role --------- Co-authored-by: Bruno Alla <browniebroke@users.noreply.github.com> Co-authored-by: Bruno Alla <alla.brunoo@gmail.com>
This commit is contained in:
parent
9ac1abe194
commit
dcea8f1e7b
|
@ -4,7 +4,7 @@
|
||||||
"description": "Behold My Awesome Project!",
|
"description": "Behold My Awesome Project!",
|
||||||
"author_name": "Daniel Roy Greenfeld",
|
"author_name": "Daniel Roy Greenfeld",
|
||||||
"domain_name": "example.com",
|
"domain_name": "example.com",
|
||||||
"email": "{{ cookiecutter.author_name.lower()|replace(' ', '-') }}@example.com",
|
"email": "{{ cookiecutter.author_name.lower() | trim() |replace(' ', '-') }}@{{ cookiecutter.domain_name.lower() | trim() }}",
|
||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"open_source_license": [
|
"open_source_license": [
|
||||||
"MIT",
|
"MIT",
|
||||||
|
|
|
@ -17,6 +17,14 @@ INFO = "\x1b[1;33m [INFO]: "
|
||||||
HINT = "\x1b[3;33m"
|
HINT = "\x1b[3;33m"
|
||||||
SUCCESS = "\x1b[1;32m [SUCCESS]: "
|
SUCCESS = "\x1b[1;32m [SUCCESS]: "
|
||||||
|
|
||||||
|
# The content of this string is evaluated by Jinja, and plays an important role.
|
||||||
|
# It updates the cookiecutter context to trim leading and trailing spaces
|
||||||
|
# from domain/email values
|
||||||
|
"""
|
||||||
|
{{ cookiecutter.update({ "domain_name": cookiecutter.domain_name | trim }) }}
|
||||||
|
{{ cookiecutter.update({ "email": cookiecutter.email | trim }) }}
|
||||||
|
"""
|
||||||
|
|
||||||
project_slug = "{{ cookiecutter.project_slug }}"
|
project_slug = "{{ cookiecutter.project_slug }}"
|
||||||
if hasattr(project_slug, "isidentifier"):
|
if hasattr(project_slug, "isidentifier"):
|
||||||
assert (
|
assert (
|
||||||
|
|
|
@ -319,10 +319,29 @@ def test_error_if_incompatible(cookies, context, invalid_context):
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_pycharm_docs_removed(cookies, context, use_pycharm, pycharm_docs_exist):
|
def test_pycharm_docs_removed(cookies, context, use_pycharm, pycharm_docs_exist):
|
||||||
"""."""
|
|
||||||
context.update({"use_pycharm": use_pycharm})
|
context.update({"use_pycharm": use_pycharm})
|
||||||
result = cookies.bake(extra_context=context)
|
result = cookies.bake(extra_context=context)
|
||||||
|
|
||||||
with open(f"{result.project_path}/docs/index.rst") as f:
|
with open(f"{result.project_path}/docs/index.rst") as f:
|
||||||
has_pycharm_docs = "pycharm/configuration" in f.read()
|
has_pycharm_docs = "pycharm/configuration" in f.read()
|
||||||
assert has_pycharm_docs is pycharm_docs_exist
|
assert has_pycharm_docs is pycharm_docs_exist
|
||||||
|
|
||||||
|
|
||||||
|
def test_trim_domain_email(cookies, context):
|
||||||
|
"""Check that leading and trailing spaces are trimmed in domain and email."""
|
||||||
|
context.update(
|
||||||
|
{
|
||||||
|
"use_docker": "y",
|
||||||
|
"domain_name": " example.com ",
|
||||||
|
"email": " me@example.com ",
|
||||||
|
}
|
||||||
|
)
|
||||||
|
result = cookies.bake(extra_context=context)
|
||||||
|
|
||||||
|
assert result.exit_code == 0
|
||||||
|
|
||||||
|
prod_django_env = result.project_path / ".envs" / ".production" / ".django"
|
||||||
|
assert "DJANGO_ALLOWED_HOSTS=.example.com" in prod_django_env.read_text()
|
||||||
|
|
||||||
|
base_settings = result.project_path / "config" / "settings" / "base.py"
|
||||||
|
assert '"me@example.com"' in base_settings.read_text()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user