mirror of
https://github.com/cookiecutter/cookiecutter-django.git
synced 2024-11-22 09:36:52 +03:00
Add a pre-generation hook to avoid non-lowercase slugs - fixes #2042
This commit is contained in:
parent
72c92187a9
commit
2103cf2f9d
|
@ -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."
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue
Block a user