Add a pre-generation hook to avoid non-lowercase slugs - fixes #2042

This commit is contained in:
Bruno Alla 2019-06-05 19:00:43 +01:00
parent 72c92187a9
commit 2103cf2f9d
2 changed files with 16 additions and 0 deletions

View File

@ -22,6 +22,10 @@ if hasattr(project_slug, "isidentifier"):
project_slug.isidentifier()
), "'{}' project slug is not a valid Python identifier.".format(project_slug)
assert (
project_slug == project_slug.lower()
), "'{}' project slug should be all lowercase".format(project_slug)
assert (
"\\" not in "{{ cookiecutter.author_name }}"
), "Don't include backslashes in author name."

View File

@ -2,6 +2,7 @@ import os
import re
import pytest
from cookiecutter.exceptions import FailedHookException
from pytest_cases import pytest_fixture_plus
import sh
import yaml
@ -145,3 +146,14 @@ def test_travis_invokes_pytest(cookies, context):
assert yaml.load(travis_yml)["script"] == ["pytest"]
except yaml.YAMLError as e:
pytest.fail(e)
@pytest.mark.parametrize("slug", ["project slug", "Project_Slug"])
def test_invalid_slug(cookies, context, slug):
"""Invalid slug should failed pre-generation hook."""
context.update({"project_slug": slug})
result = cookies.bake(extra_context=context)
assert result.exit_code != 0
assert isinstance(result.exception, FailedHookException)