mirror of
https://github.com/cookiecutter/cookiecutter-django.git
synced 2024-11-25 11:04:04 +03:00
Add DjangoCookieTestCase
This commit is contained in:
parent
a289d98a49
commit
43d33dc025
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -4,3 +4,4 @@
|
||||||
local_settings.py
|
local_settings.py
|
||||||
repo_name
|
repo_name
|
||||||
.idea
|
.idea
|
||||||
|
my_test_project/*
|
||||||
|
|
|
@ -4,7 +4,7 @@ before_install:
|
||||||
- time pip install pep8
|
- time pip install pep8
|
||||||
|
|
||||||
install:
|
install:
|
||||||
- pip install -r dev-requirements.txt
|
- pip install -r requirements.txt
|
||||||
|
|
||||||
script:
|
script:
|
||||||
- pep8 --ignore E201,E202 --max-line-length=120 --exclude='migrations' .
|
- pep8 --ignore E201,E202 --max-line-length=120 --exclude='migrations' .
|
||||||
|
@ -12,5 +12,5 @@ script:
|
||||||
|
|
||||||
notifications:
|
notifications:
|
||||||
email:
|
email:
|
||||||
on_success: never
|
on_success: change
|
||||||
on_failure: never
|
on_failure: always
|
||||||
|
|
2
Makefile
2
Makefile
|
@ -1,4 +1,4 @@
|
||||||
.PHONY: test
|
.PHONY: test
|
||||||
|
|
||||||
test:
|
test:
|
||||||
py.test -q tests/*.py
|
py.test tests/*.py
|
||||||
|
|
|
@ -1,3 +0,0 @@
|
||||||
cookiecutter
|
|
||||||
pep8
|
|
||||||
pytest
|
|
13
requirements.txt
Normal file
13
requirements.txt
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
cookiecutter==1.0.0
|
||||||
|
flake8==2.4.0
|
||||||
|
sh
|
||||||
|
|
||||||
|
# Debugging
|
||||||
|
# -------------------------------------
|
||||||
|
ipdb==0.8
|
||||||
|
ipython==3.1.0
|
||||||
|
|
||||||
|
# Testing
|
||||||
|
# -------------------------------------
|
||||||
|
pytest==2.7.0
|
||||||
|
git+git://github.com/mverteuil/pytest-ipdb.git
|
3
setup.cfg
Normal file
3
setup.cfg
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
[pytest]
|
||||||
|
python_paths = .
|
||||||
|
norecursedirs = .tox .git */migrations/* */static/* docs venv */{{cookiecutter.repo_name}}/*
|
51
tests/base.py
Normal file
51
tests/base.py
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
import os
|
||||||
|
import shutil
|
||||||
|
import unittest
|
||||||
|
from os.path import exists, dirname, join
|
||||||
|
|
||||||
|
import sh
|
||||||
|
|
||||||
|
from cookiecutter.main import cookiecutter
|
||||||
|
|
||||||
|
|
||||||
|
class DjangoCookieTestCase(unittest.TestCase):
|
||||||
|
|
||||||
|
root_dir = dirname(dirname(__file__))
|
||||||
|
ctx = {}
|
||||||
|
destpath = None
|
||||||
|
|
||||||
|
def generate_project(self, extra_context=None):
|
||||||
|
ctx = {
|
||||||
|
"project_name": "My Test Project",
|
||||||
|
"repo_name": "my_test_project",
|
||||||
|
"author_name": "Test Author",
|
||||||
|
"email": "test@example.com",
|
||||||
|
"description": "A short description of the project.",
|
||||||
|
"domain_name": "example.com",
|
||||||
|
"version": "0.1.0",
|
||||||
|
"timezone": "UTC",
|
||||||
|
"now": "2015/01/13",
|
||||||
|
"year": "2015"
|
||||||
|
}
|
||||||
|
if extra_context:
|
||||||
|
assert isinstance(extra_context, dict)
|
||||||
|
ctx.update(extra_context)
|
||||||
|
|
||||||
|
self.ctx = ctx
|
||||||
|
self.destpath = join(self.root_dir, self.ctx['repo_name'])
|
||||||
|
|
||||||
|
cookiecutter(template='./', checkout=None, no_input=True, extra_context=ctx)
|
||||||
|
|
||||||
|
# Build a list containing absolute paths to the generated files
|
||||||
|
paths = [os.path.join(dirpath, file_path)
|
||||||
|
for dirpath, subdirs, files in os.walk(self.destpath)
|
||||||
|
for file_path in files]
|
||||||
|
return paths
|
||||||
|
|
||||||
|
def clean(self):
|
||||||
|
if exists(self.destpath):
|
||||||
|
shutil.rmtree(self.destpath)
|
||||||
|
sh.cd(self.root_dir)
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
self.clean()
|
|
@ -1,28 +1,16 @@
|
||||||
import os
|
|
||||||
import re
|
import re
|
||||||
import shutil
|
|
||||||
import unittest
|
|
||||||
from os.path import dirname, exists, join
|
|
||||||
|
|
||||||
from cookiecutter.main import cookiecutter
|
import sh
|
||||||
|
|
||||||
|
from .base import DjangoCookieTestCase
|
||||||
|
|
||||||
|
|
||||||
class TestCookiecutterSubstitution(unittest.TestCase):
|
class TestCookiecutterSubstitution(DjangoCookieTestCase):
|
||||||
"""Test that all cookiecutter instances are substituted"""
|
"""Test that all cookiecutter instances are substituted"""
|
||||||
|
|
||||||
cookiecutter(dirname(dirname(__file__)), no_input=True)
|
|
||||||
|
|
||||||
destpath = join(dirname(dirname(__file__)), 'project_name')
|
|
||||||
|
|
||||||
def tearDown(self):
|
|
||||||
if exists(self.destpath):
|
|
||||||
shutil.rmtree(self.destpath)
|
|
||||||
|
|
||||||
def test_all_cookiecutter_instances_are_substituted(self):
|
def test_all_cookiecutter_instances_are_substituted(self):
|
||||||
# Build a list containing absolute paths to the generated files
|
# Build a list containing absolute paths to the generated files
|
||||||
paths = [os.path.join(dirpath, file_path)
|
paths = self.generate_project()
|
||||||
for dirpath, subdirs, files in os.walk(self.destpath)
|
|
||||||
for file_path in files]
|
|
||||||
|
|
||||||
# Construct the cookiecutter search pattern
|
# Construct the cookiecutter search pattern
|
||||||
pattern = "{{(\s?cookiecutter)[.](.*?)}}"
|
pattern = "{{(\s?cookiecutter)[.](.*?)}}"
|
||||||
|
@ -36,6 +24,10 @@ class TestCookiecutterSubstitution(unittest.TestCase):
|
||||||
match,
|
match,
|
||||||
"cookiecutter variable not replaced in {}".format(path))
|
"cookiecutter variable not replaced in {}".format(path))
|
||||||
|
|
||||||
|
def test_flake8_complaince(self):
|
||||||
if __name__ == '__main__':
|
"""generated project should pass flake8"""
|
||||||
unittest.main()
|
self.generate_project()
|
||||||
|
try:
|
||||||
|
sh.flake8(self.destpath)
|
||||||
|
except sh.ErrorReturnCode as e:
|
||||||
|
raise AssertionError(e)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user