Permalink
Browse files

Add base, model generator tests.

 - Also added some minor fixes for bugs discovered while writing tests.
  • Loading branch information...
1 parent ffc3d41 commit 0c661b295cc3fbc76dfdc491e36dee5e62898754 @modocache committed Jun 20, 2012
Showing with 829 additions and 3 deletions.
  1. +81 −0 .rvmrc
  2. +3 −0 Gemfile
  3. +10 −0 Gemfile.lock
  4. +4 −0 autotest.rb
  5. +4 −1 generate_scaffold/generators/base.py
  6. +3 −1 generate_scaffold/generators/models.py
  7. +1 −1 generate_scaffold/templates/generate_scaffold/models/fields/filepathfield.txt
  8. +10 −0 test_project/manage.py
  9. 0 test_project/test_app/__init__.py
  10. +11 −0 test_project/test_app/models.py
  11. +59 −0 test_project/test_app/tests/generator_tests/base_tests.py
  12. +356 −0 test_project/test_app/tests/generator_tests/models_tests.py
  13. +19 −0 test_project/test_app/tests/sample_test.py
  14. +1 −0 test_project/test_app/views.py
  15. 0 test_project/test_modelgen_with_models_with_now/__init__.py
  16. +4 −0 test_project/test_modelgen_with_models_with_now/models.py
  17. 0 {generate_scaffold → test_project/test_modelgen_with_models_with_now}/tests.py
  18. +1 −0 test_project/test_modelgen_with_models_with_now/views.py
  19. 0 test_project/test_modelgen_with_models_without_now/__init__.py
  20. +3 −0 test_project/test_modelgen_with_models_without_now/models.py
  21. +16 −0 test_project/test_modelgen_with_models_without_now/tests.py
  22. +1 −0 test_project/test_modelgen_with_models_without_now/views.py
  23. 0 test_project/test_modelgen_without_models_with_now/__init__.py
  24. +3 −0 test_project/test_modelgen_without_models_with_now/models.py
  25. +16 −0 test_project/test_modelgen_without_models_with_now/tests.py
  26. +1 −0 test_project/test_modelgen_without_models_with_now/views.py
  27. 0 test_project/test_modelgen_without_models_without_now/__init__.py
  28. 0 test_project/test_modelgen_without_models_without_now/models.py
  29. +16 −0 test_project/test_modelgen_without_models_without_now/tests.py
  30. +1 −0 test_project/test_modelgen_without_models_without_now/views.py
  31. 0 test_project/test_project/__init__.py
  32. +159 −0 test_project/test_project/settings.py
  33. +18 −0 test_project/test_project/urls.py
  34. +28 −0 test_project/test_project/wsgi.py
View
81 .rvmrc
@@ -0,0 +1,81 @@
+#!/usr/bin/env bash
+
+# This is an RVM Project .rvmrc file, used to automatically load the ruby
+# development environment upon cd'ing into the directory
+
+# First we specify our desired <ruby>[@<gemset>], the @gemset name is optional.
+environment_id="ruby-1.9.3-p0@django-generate-scaffold"
+
+#
+# Uncomment the following lines if you want to verify rvm version per project
+#
+# rvmrc_rvm_version="1.10.2" # 1.10.1 seams as a safe start
+# eval "$(echo ${rvm_version}.${rvmrc_rvm_version} | awk -F. '{print "[[ "$1*65536+$2*256+$3" -ge "$4*65536+$5*256+$6" ]]"}' )" || {
+# echo "This .rvmrc file requires at least RVM ${rvmrc_rvm_version}, aborting loading."
+# return 1
+# }
+#
+
+#
+# Uncomment following line if you want options to be set only for given project.
+#
+# PROJECT_JRUBY_OPTS=( --1.9 )
+#
+# The variable PROJECT_JRUBY_OPTS requires the following to be run in shell:
+#
+# chmod +x ${rvm_path}/hooks/after_use_jruby_opts
+#
+
+#
+# First we attempt to load the desired environment directly from the environment
+# file. This is very fast and efficient compared to running through the entire
+# CLI and selector. If you want feedback on which environment was used then
+# insert the word 'use' after --create as this triggers verbose mode.
+#
+if [[ -d "${rvm_path:-$HOME/.rvm}/environments" \
+ && -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
+then
+ \. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
+
+ if [[ -s "${rvm_path:-$HOME/.rvm}/hooks/after_use" ]]
+ then
+ . "${rvm_path:-$HOME/.rvm}/hooks/after_use"
+ fi
+else
+ # If the environment file has not yet been created, use the RVM CLI to select.
+ if ! rvm --create use "$environment_id"
+ then
+ echo "Failed to create RVM environment '${environment_id}'."
+ return 1
+ fi
+fi
+
+#
+# If you use an RVM gemset file to install a list of gems (*.gems), you can have
+# it be automatically loaded. Uncomment the following and adjust the filename if
+# necessary.
+#
+# filename=".gems"
+# if [[ -s "$filename" ]]
+# then
+# rvm gemset import "$filename" | grep -v already | grep -v listed | grep -v complete | sed '/^$/d'
+# fi
+
+# If you use bundler, this might be useful to you:
+# if [[ -s Gemfile ]] && ! command -v bundle >/dev/null
+# then
+# printf "%b" "The rubygem 'bundler' is not installed. Installing it now.\n"
+# gem install bundler
+# fi
+# if [[ -s Gemfile ]] && command -v bundle
+# then
+# bundle install
+# fi
+
+if [[ $- == *i* ]] # check for interactive shells
+then
+ echo "Using: $(tput setaf 2)$GEM_HOME$(tput sgr0)" # show the user the ruby and gemset they are using in green
+else
+ echo "Using: $GEM_HOME" # don't use colors in interactive shells
+fi
+
View
3 Gemfile
@@ -0,0 +1,3 @@
+source 'https://rubygems.org'
+
+gem 'watchr', '~> 0.7'
View
10 Gemfile.lock
@@ -0,0 +1,10 @@
+GEM
+ remote: https://rubygems.org/
+ specs:
+ watchr (0.7)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ watchr (~> 0.7)
View
4 autotest.rb
@@ -0,0 +1,4 @@
+watch('.*\.(py|html|txt)') do |match_data_object|
+ system('python setup.py install --force')
+ system('cd test_project && python manage.py test')
+end
View
5 generate_scaffold/generators/base.py
@@ -35,6 +35,9 @@
'positiveintegerfield': [
'posint', 'positiveint', 'positiveinteger', 'positiveintegerfield'
],
+ 'positivesmallintegerfield': [
+ 'positivesmallint', 'positivesmallinteger', 'positivesmallintegerfield'
+ ],
'slugfield': ['slug', 'slugfield'],
'smallintegerfield': ['smallint', 'smallinteger', 'smallintegerfield'],
'textfield': ['text', 'textfield'],
@@ -70,7 +73,7 @@ def get_app_module(self, module_name):
return module
- def get_timestamp_field(self, model, timestamp_fieldname):
+ def get_timestamp_field(self, model, timestamp_fieldname=None):
if timestamp_fieldname:
try:
timestamp_field = model._meta.get_field(timestamp_fieldname)
View
4 generate_scaffold/generators/models.py
@@ -22,10 +22,11 @@ def get_field_key(self, name):
def render_field(self, field_name, field_key_alias, other_model=None):
original_field_name = field_name
- field_name = get_valid_variable(field_name).lower()
+ field_name = get_valid_variable(field_name)
if not field_name:
raise GeneratorError(
'{0} is not a valid field name.'.format(original_field_name))
+ field_name = field_name.lower()
field_key = self.get_field_key(field_key_alias)
if not field_key:
@@ -50,6 +51,7 @@ def render_field(self, field_name, field_key_alias, other_model=None):
return tpl.render(context)
def render_model(self, model_name, fields, add_timestamp=True):
+ # FIXME - Ensure model_name is valid
rendered_fields = [self.render_field(*field) for field in fields]
app_models_module = self.get_app_module('models')
View
2 generate_scaffold/templates/generate_scaffold/models/fields/filepathfield.txt
@@ -1 +1 @@
-{{ field_name }} = models.FilePathField(path='uplaoded_files')
+{{ field_name }} = models.FilePathField(path='uploaded_files')
View
10 test_project/manage.py
@@ -0,0 +1,10 @@
+#!/usr/bin/env python
+import os
+import sys
+
+if __name__ == "__main__":
+ os.environ.setdefault("DJANGO_SETTINGS_MODULE", "test_project.settings")
+
+ from django.core.management import execute_from_command_line
+
+ execute_from_command_line(sys.argv)
View
0 test_project/test_app/__init__.py
No changes.
View
11 test_project/test_app/models.py
@@ -0,0 +1,11 @@
+from django.db import models
+from django.utils.timezone import now
+
+
+class PreExistingModel(models.Model):
+ description = models.TextField()
+
+
+class PreExistingDatedModel(models.Model):
+ created_at = models.DateTimeField(
+ auto_now_add=True, default=now(), editable=False)
View
59 test_project/test_app/tests/generator_tests/base_tests.py
@@ -0,0 +1,59 @@
+from types import ModuleType
+
+from nose.tools import eq_, raises
+
+from generate_scaffold.generators import GeneratorError
+from generate_scaffold.generators.base import BaseGenerator
+from test_app.models import PreExistingModel, PreExistingDatedModel
+
+
+TEST_APP_NAME = 'test_app'
+BASE_GENERATOR = BaseGenerator(TEST_APP_NAME)
+DATED_MODEL = PreExistingDatedModel()
+NON_DATED_MODEL = PreExistingModel()
+
+
+def test_init():
+ eq_(BASE_GENERATOR.app_name, TEST_APP_NAME)
+
+
+def test_get_app_module():
+ module = BASE_GENERATOR.get_app_module('models')
+ eq_(module.__name__, '{}.models'.format(TEST_APP_NAME))
+ eq_(type(module), ModuleType)
+
+
+@raises(GeneratorError)
+def test_get_app_module_raises_error():
+ BASE_GENERATOR.get_app_module('spaceships')
+
+
+def test_get_timestamp_field_no_field_not_named():
+ eq_(BASE_GENERATOR.get_timestamp_field(NON_DATED_MODEL), None)
+
+
+@raises(GeneratorError)
+def test_get_timestamp_field_no_field_named():
+ BASE_GENERATOR.get_timestamp_field(NON_DATED_MODEL, 'doesnt-exist')
+
+
+@raises(GeneratorError)
+def test_get_timestamp_field_field_named_not_timestamp():
+ BASE_GENERATOR.get_timestamp_field(NON_DATED_MODEL, 'description')
+
+
+def test_get_timestamp_field_not_named():
+ dated_field = DATED_MODEL._meta.get_field('created_at')
+ timestamp_field = BASE_GENERATOR.get_timestamp_field(DATED_MODEL)
+
+ eq_(dated_field, timestamp_field)
+ eq_(timestamp_field.__class__.__name__, 'DateTimeField')
+
+
+def test_get_timestamp_field_named():
+ dated_field = DATED_MODEL._meta.get_field('created_at')
+ timestamp_field = \
+ BASE_GENERATOR.get_timestamp_field(DATED_MODEL, 'created_at')
+
+ eq_(dated_field, timestamp_field)
+ eq_(timestamp_field.__class__.__name__, 'DateTimeField')
View
356 test_project/test_app/tests/generator_tests/models_tests.py
@@ -0,0 +1,356 @@
+from nose.tools import eq_, raises
+
+from generate_scaffold.generators import ModelsGenerator, GeneratorError
+from generate_scaffold.generators.base import FIELD_ALIASES
+
+
+TEST_APP_NAME = 'test_app'
+MODELS_GENERATOR = ModelsGenerator(TEST_APP_NAME)
+
+
+def test_get_field_key():
+ for field_key, aliases in FIELD_ALIASES.items():
+ [eq_(field_key, MODELS_GENERATOR.get_field_key(a))
+ for a in aliases]
+
+
+def test_get_field_key_found():
+ eq_(MODELS_GENERATOR.get_field_key('bool'), 'booleanfield')
+
+
+def test_get_field_key_not_found():
+ eq_(MODELS_GENERATOR.get_field_key('doesnt-exist'), None)
+
+
+@raises(GeneratorError)
+def test_render_field_bad_variable_name():
+ MODELS_GENERATOR.render_field('class', 'text')
+
+
+@raises(GeneratorError)
+def test_render_field_no_such_field():
+ MODELS_GENERATOR.render_field('foo', 'doesnt-exist')
+
+
+def test_render_autofield():
+ target_field = u'auto = models.AutoField()\n'
+ test_field = MODELS_GENERATOR.render_field('auto', 'auto')
+ eq_(target_field, test_field)
+
+
+def test_render_bigintegerfield():
+ target_field = u'bigi = models.BigIntegerField()\n'
+ test_field = MODELS_GENERATOR.render_field('bigi', 'bigint')
+ eq_(target_field, test_field)
+
+
+def test_render_booleanfield():
+ target_field = u'boo = models.BooleanField()\n'
+ test_field = MODELS_GENERATOR.render_field('boo', 'bool')
+ eq_(target_field, test_field)
+
+
+def test_render_charfield():
+ target_field = u'char = models.CharField(max_length=200)\n'
+ test_field = MODELS_GENERATOR.render_field('char', 'string')
+ eq_(target_field, test_field)
+
+
+def test_render_commaseparatedintegerfield():
+ target_field = u'c = models.CommaSeparatedIntegerField()\n'
+ test_field = MODELS_GENERATOR.render_field('c', 'comma')
+ eq_(target_field, test_field)
+
+
+def test_render_datefield():
+ target_field = u'da = models.DateField()\n'
+ test_field = MODELS_GENERATOR.render_field('da', 'date')
+ eq_(target_field, test_field)
+
+
+def test_render_datetimefield():
+ target_field = u'dt = models.DateTimeField()\n'
+ test_field = MODELS_GENERATOR.render_field('dt', 'datetime')
+ eq_(target_field, test_field)
+
+
+def test_render_decimalfield():
+ target_field = \
+ u'd = models.DecimalField(max_digits=10, decimal_places=5)\n'
+ test_field = MODELS_GENERATOR.render_field('d', 'decimal')
+ eq_(target_field, test_field)
+
+
+def test_render_emailfield():
+ target_field = u'emailfield = models.EmailField(max_length=254)\n'
+ test_field = MODELS_GENERATOR.render_field('emailfield', 'email')
+ eq_(target_field, test_field)
+
+
+def test_render_filefield():
+ target_field = u"__f__ = models.FileField(upload_to='uploaded_files')\n"
+ test_field = MODELS_GENERATOR.render_field('__F__', 'file')
+ eq_(target_field, test_field)
+
+
+def test_render_filepathfield():
+ target_field = u"foo = models.FilePathField(path='uploaded_files')\n"
+ test_field = MODELS_GENERATOR.render_field('%&fo$o**', 'path')
+ eq_(target_field, test_field)
+
+
+def test_render_floatfield():
+ target_field = u"this_is_a_really_long_variable_name_this_is_crazy_what_is_going_on = models.FloatField()\n"
+ test_field = MODELS_GENERATOR.render_field('this_is_a_really_long_variable_name_this_is_crazy_what_is_going_on', 'float')
+ eq_(target_field, test_field)
+
+
+@raises(GeneratorError)
+def test_render_foreignkey_without_other_model():
+ MODELS_GENERATOR.render_field('owner', 'foreignkey')
+
+
+def test_render_foreignkey_with_other_model():
+ target_field = u"owner = models.ForeignKey('django.contrib.auth.models.User')\n"
+ test_field = MODELS_GENERATOR.render_field('owner', 'foreign', 'django.contrib.auth.models.User')
+ eq_(target_field, test_field)
+
+
+def test_render_genericipaddressfield():
+ target_field = u'ip = models.GenericIPAddressField()\n'
+ test_field = MODELS_GENERATOR.render_field('ip', 'genericip')
+ eq_(target_field, test_field)
+
+
+def test_render_imagefield():
+ target_field = u"image = models.ImageField(upload_to='uploaded_files')\n"
+ test_field = MODELS_GENERATOR.render_field('image', 'image')
+ eq_(target_field, test_field)
+
+
+def test_render_integerfield():
+ target_field = u'int = models.IntegerField()\n'
+ test_field = MODELS_GENERATOR.render_field('int', 'int')
+ eq_(target_field, test_field)
+
+
+def test_render_ipaddressfield():
+ target_field = u'ip = models.IPAddressField()\n'
+ test_field = MODELS_GENERATOR.render_field('ip', 'ip')
+ eq_(target_field, test_field)
+
+
+@raises(GeneratorError)
+def test_render_manytomanyfield_without_other_model():
+ MODELS_GENERATOR.render_field('friends', 'many')
+
+
+def test_render_manytomanyfield_with_other_model():
+ target_field = u"friends = models.ManyToManyField('User')\n"
+ test_field = MODELS_GENERATOR.render_field('friends', 'many', 'User')
+ eq_(target_field, test_field)
+
+
+def test_render_nullbooleanfield():
+ target_field = u'nulbol = models.NullBooleanField()\n'
+ test_field = MODELS_GENERATOR.render_field('nulbol', 'nullbool')
+ eq_(target_field, test_field)
+
+
+@raises(GeneratorError)
+def test_render_onetoonefield_without_other_model():
+ MODELS_GENERATOR.render_field('case', 'one')
+
+
+def test_render_onetoonefield_with_other_model():
+ target_field = u"case = models.OneToOneField('Case')\n"
+ test_field = MODELS_GENERATOR.render_field('case', 'onetoone', 'Case')
+ eq_(target_field, test_field)
+
+
+def test_render_positiveintegerfield():
+ target_field = u'posint = models.PositiveIntegerField()\n'
+ test_field = MODELS_GENERATOR.render_field('posint', 'positiveint')
+ eq_(target_field, test_field)
+
+
+def test_render_positivesmallintegerfield():
+ target_field = u'posmall = models.PositiveSmallIntegerField()\n'
+ test_field = MODELS_GENERATOR.render_field('posmall', 'positivesmallint')
+ eq_(target_field, test_field)
+
+
+def test_render_slugfield():
+ target_field = u'slug = models.SlugField(max_length=200)\n'
+ test_field = MODELS_GENERATOR.render_field('slug', 'slug')
+ eq_(target_field, test_field)
+
+
+def test_render_smallintegerfield():
+ target_field = u'small = models.SmallIntegerField()\n'
+ test_field = MODELS_GENERATOR.render_field('small', 'smallint')
+ eq_(target_field, test_field)
+
+
+def test_render_textfield():
+ target_field = u'test = models.TextField()\n'
+ test_field = MODELS_GENERATOR.render_field('test', 'text')
+ eq_(target_field, test_field)
+
+
+def test_render_timefield():
+ target_field = u'time = models.TimeField()\n'
+ test_field = MODELS_GENERATOR.render_field('time', 'time')
+ eq_(target_field, test_field)
+
+
+def test_render_urlfield():
+ target_field = u'url = models.URLField()\n'
+ test_field = MODELS_GENERATOR.render_field('url', 'url')
+ eq_(target_field, test_field)
+
+
+@raises(GeneratorError)
+def test_render_model_already_exists():
+ MODELS_GENERATOR.render_model('PreExistingModel', [['foo', 'text']])
+
+
+@raises(GeneratorError)
+def test_render_model_already_exists_with_capitalization():
+ MODELS_GENERATOR.render_model('preExistingModel', [['foo', 'text']])
+
+
+@raises(GeneratorError)
+def test_render_model_bad_field_args():
+ MODELS_GENERATOR.render_model('BrandNewModel', ['doo', 'boop', 'bebop'])
+
+
+def test_render_model_without_timestamps():
+ test_model = MODELS_GENERATOR.render_model(
+ 'BrandNewModel', [['foo', 'text'],], add_timestamp=False)
+ target_model = (u"""
+class BrandNewModel(models.Model):
+ foo = models.TextField()
+
+
+ @models.permalink
+ def get_absolute_url(self):
+ return ('test_app_brandnewmodel_detail', (), {'pk': self.pk})
+""", 'BrandNewModel')
+
+ eq_(test_model, target_model)
+
+
+# TODO - Should this raise an error?
+# @raises(GeneratorError)
+# def test_render_model_without_timestamps_or_fields():
+# MODELS_GENERATOR.render_model('BrandNewModel', [], add_timestamp=False)
+
+
+def test_render_model_with_models_with_now():
+ models_generator = ModelsGenerator('test_modelgen_with_models_with_now')
+ fields = [['foo', 'text'],]
+ test_model = models_generator.render_model('BrandNewModel', fields)
+ target_model = (u"""
+class BrandNewModel(models.Model):
+ foo = models.TextField()
+ created_at = models.DateTimeField(
+ auto_now_add=True,
+ default=now(),
+ editable=False,
+ )
+ updated_at = models.DateTimeField(
+ auto_now=True,
+ default=now(),
+ editable=False,
+ )
+
+ @models.permalink
+ def get_absolute_url(self):
+ return ('test_modelgen_with_models_with_now_brandnewmodel_detail', (), {'pk': self.pk})
+""", 'BrandNewModel')
+
+ eq_(test_model, target_model)
+
+
+def test_render_model_with_models_without_now():
+ models_generator = ModelsGenerator('test_modelgen_with_models_without_now')
+ fields = [['foo', 'text'], ['bar', 'date'], ['biz', 'foreign', 'Blog']]
+ test_model = models_generator.render_model('somemodel', fields)
+ target_model = (u"""
+from django.utils.timezone import now
+class Somemodel(models.Model):
+ foo = models.TextField()
+ bar = models.DateField()
+ biz = models.ForeignKey('Blog')
+ created_at = models.DateTimeField(
+ auto_now_add=True,
+ default=now(),
+ editable=False,
+ )
+ updated_at = models.DateTimeField(
+ auto_now=True,
+ default=now(),
+ editable=False,
+ )
+
+ @models.permalink
+ def get_absolute_url(self):
+ return ('test_modelgen_with_models_without_now_somemodel_detail', (), {'pk': self.pk})
+""", 'Somemodel')
+
+ eq_(test_model, target_model)
+
+
+def test_render_model_without_models_with_now():
+ models_generator = ModelsGenerator('test_modelgen_without_models_with_now')
+ fields = []
+ test_model = models_generator.render_model('a', fields)
+ target_model = (u"""
+from django.db import models
+class A(models.Model):
+ created_at = models.DateTimeField(
+ auto_now_add=True,
+ default=now(),
+ editable=False,
+ )
+ updated_at = models.DateTimeField(
+ auto_now=True,
+ default=now(),
+ editable=False,
+ )
+
+ @models.permalink
+ def get_absolute_url(self):
+ return ('test_modelgen_without_models_with_now_a_detail', (), {'pk': self.pk})
+""", 'A')
+
+ eq_(test_model, target_model)
+
+
+def test_render_model_without_models_without_now():
+ models_generator = ModelsGenerator('test_modelgen_without_models_without_now')
+ fields = [['a', 'bigint'],]
+ test_model = models_generator.render_model('THISISALLCAPS', fields)
+ target_model = (u"""
+from django.db import models
+from django.utils.timezone import now
+class THISISALLCAPS(models.Model):
+ a = models.BigIntegerField()
+ created_at = models.DateTimeField(
+ auto_now_add=True,
+ default=now(),
+ editable=False,
+ )
+ updated_at = models.DateTimeField(
+ auto_now=True,
+ default=now(),
+ editable=False,
+ )
+
+ @models.permalink
+ def get_absolute_url(self):
+ return ('test_modelgen_without_models_without_now_thisisallcaps_detail', (), {'pk': self.pk})
+""", 'THISISALLCAPS')
+
+ eq_(test_model, target_model)
View
19 test_project/test_app/tests/sample_test.py
@@ -0,0 +1,19 @@
+"""
+This file demonstrates writing tests using the unittest module. These will pass
+when you run "manage.py test".
+
+Replace this with more appropriate tests for your application.
+"""
+
+from django.test import TestCase
+from generate_scaffold.generators.base import BaseGenerator
+
+
+
+class SimpleTest(TestCase):
+ def test_basic_addition(self):
+ """
+ Tests that 1 + 1 always equals 2.
+ """
+ b = BaseGenerator('bollocks')
+ self.assertEqual(1 + 1, 2)
View
1 test_project/test_app/views.py
@@ -0,0 +1 @@
+# Create your views here.
View
0 test_project/test_modelgen_with_models_with_now/__init__.py
No changes.
View
4 test_project/test_modelgen_with_models_with_now/models.py
@@ -0,0 +1,4 @@
+from django.db import models
+from django.utils.timezone import now
+
+# Create your models here.
View
0 generate_scaffold/tests.py → ...st_modelgen_with_models_with_now/tests.py
File renamed without changes.
View
1 test_project/test_modelgen_with_models_with_now/views.py
@@ -0,0 +1 @@
+# Create your views here.
View
0 test_project/test_modelgen_with_models_without_now/__init__.py
No changes.
View
3 test_project/test_modelgen_with_models_without_now/models.py
@@ -0,0 +1,3 @@
+from django.db import models
+
+# Create your models here.
View
16 test_project/test_modelgen_with_models_without_now/tests.py
@@ -0,0 +1,16 @@
+"""
+This file demonstrates writing tests using the unittest module. These will pass
+when you run "manage.py test".
+
+Replace this with more appropriate tests for your application.
+"""
+
+from django.test import TestCase
+
+
+class SimpleTest(TestCase):
+ def test_basic_addition(self):
+ """
+ Tests that 1 + 1 always equals 2.
+ """
+ self.assertEqual(1 + 1, 2)
View
1 test_project/test_modelgen_with_models_without_now/views.py
@@ -0,0 +1 @@
+# Create your views here.
View
0 test_project/test_modelgen_without_models_with_now/__init__.py
No changes.
View
3 test_project/test_modelgen_without_models_with_now/models.py
@@ -0,0 +1,3 @@
+from django.utils.timezone import now
+
+# Create your models here.
View
16 test_project/test_modelgen_without_models_with_now/tests.py
@@ -0,0 +1,16 @@
+"""
+This file demonstrates writing tests using the unittest module. These will pass
+when you run "manage.py test".
+
+Replace this with more appropriate tests for your application.
+"""
+
+from django.test import TestCase
+
+
+class SimpleTest(TestCase):
+ def test_basic_addition(self):
+ """
+ Tests that 1 + 1 always equals 2.
+ """
+ self.assertEqual(1 + 1, 2)
View
1 test_project/test_modelgen_without_models_with_now/views.py
@@ -0,0 +1 @@
+# Create your views here.
View
0 test_project/test_modelgen_without_models_without_now/__init__.py
No changes.
View
0 test_project/test_modelgen_without_models_without_now/models.py
No changes.
View
16 test_project/test_modelgen_without_models_without_now/tests.py
@@ -0,0 +1,16 @@
+"""
+This file demonstrates writing tests using the unittest module. These will pass
+when you run "manage.py test".
+
+Replace this with more appropriate tests for your application.
+"""
+
+from django.test import TestCase
+
+
+class SimpleTest(TestCase):
+ def test_basic_addition(self):
+ """
+ Tests that 1 + 1 always equals 2.
+ """
+ self.assertEqual(1 + 1, 2)
View
1 test_project/test_modelgen_without_models_without_now/views.py
@@ -0,0 +1 @@
+# Create your views here.
View
0 test_project/test_project/__init__.py
No changes.
View
159 test_project/test_project/settings.py
@@ -0,0 +1,159 @@
+# Django settings for test_project project.
+
+TEST_RUNNER = 'django_nose.NoseTestSuiteRunner'
+NOSE_ARGS = ['--with-sneazr']
+
+DEBUG = True
+TEMPLATE_DEBUG = DEBUG
+
+ADMINS = (
+ # ('Your Name', 'your_email@example.com'),
+)
+
+MANAGERS = ADMINS
+
+DATABASES = {
+ 'default': {
+ 'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
+ 'NAME': 'test_db', # Or path to database file if using sqlite3.
+ 'USER': '', # Not used with sqlite3.
+ 'PASSWORD': '', # Not used with sqlite3.
+ 'HOST': '', # Set to empty string for localhost. Not used with sqlite3.
+ 'PORT': '', # Set to empty string for default. Not used with sqlite3.
+ }
+}
+
+# Local time zone for this installation. Choices can be found here:
+# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
+# although not all choices may be available on all operating systems.
+# On Unix systems, a value of None will cause Django to use the same
+# timezone as the operating system.
+# If running in a Windows environment this must be set to the same as your
+# system time zone.
+TIME_ZONE = 'America/Chicago'
+
+# Language code for this installation. All choices can be found here:
+# http://www.i18nguy.com/unicode/language-identifiers.html
+LANGUAGE_CODE = 'en-us'
+
+SITE_ID = 1
+
+# If you set this to False, Django will make some optimizations so as not
+# to load the internationalization machinery.
+USE_I18N = True
+
+# If you set this to False, Django will not format dates, numbers and
+# calendars according to the current locale.
+USE_L10N = True
+
+# If you set this to False, Django will not use timezone-aware datetimes.
+USE_TZ = True
+
+# Absolute filesystem path to the directory that will hold user-uploaded files.
+# Example: "/home/media/media.lawrence.com/media/"
+MEDIA_ROOT = ''
+
+# URL that handles the media served from MEDIA_ROOT. Make sure to use a
+# trailing slash.
+# Examples: "http://media.lawrence.com/media/", "http://example.com/media/"
+MEDIA_URL = ''
+
+# Absolute path to the directory static files should be collected to.
+# Don't put anything in this directory yourself; store your static files
+# in apps' "static/" subdirectories and in STATICFILES_DIRS.
+# Example: "/home/media/media.lawrence.com/static/"
+STATIC_ROOT = ''
+
+# URL prefix for static files.
+# Example: "http://media.lawrence.com/static/"
+STATIC_URL = '/static/'
+
+# Additional locations of static files
+STATICFILES_DIRS = (
+ # Put strings here, like "/home/html/static" or "C:/www/django/static".
+ # Always use forward slashes, even on Windows.
+ # Don't forget to use absolute paths, not relative paths.
+)
+
+# List of finder classes that know how to find static files in
+# various locations.
+STATICFILES_FINDERS = (
+ 'django.contrib.staticfiles.finders.FileSystemFinder',
+ 'django.contrib.staticfiles.finders.AppDirectoriesFinder',
+# 'django.contrib.staticfiles.finders.DefaultStorageFinder',
+)
+
+# Make this unique, and don't share it with anybody.
+SECRET_KEY = '&amp;%qqycz+krd@izd)s54$-cs1t^lug6@4g1h^f^ycx7ya#8vb8-'
+
+# List of callables that know how to import templates from various sources.
+TEMPLATE_LOADERS = (
+ 'django.template.loaders.filesystem.Loader',
+ 'django.template.loaders.app_directories.Loader',
+# 'django.template.loaders.eggs.Loader',
+)
+
+MIDDLEWARE_CLASSES = (
+ 'django.middleware.common.CommonMiddleware',
+ 'django.contrib.sessions.middleware.SessionMiddleware',
+ 'django.middleware.csrf.CsrfViewMiddleware',
+ 'django.contrib.auth.middleware.AuthenticationMiddleware',
+ 'django.contrib.messages.middleware.MessageMiddleware',
+ # Uncomment the next line for simple clickjacking protection:
+ # 'django.middleware.clickjacking.XFrameOptionsMiddleware',
+)
+
+ROOT_URLCONF = 'test_project.urls'
+
+# Python dotted path to the WSGI application used by Django's runserver.
+WSGI_APPLICATION = 'test_project.wsgi.application'
+
+TEMPLATE_DIRS = (
+ # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
+ # Always use forward slashes, even on Windows.
+ # Don't forget to use absolute paths, not relative paths.
+)
+
+INSTALLED_APPS = (
+ 'django.contrib.auth',
+ 'django.contrib.contenttypes',
+ 'django.contrib.sessions',
+ 'django.contrib.sites',
+ 'django.contrib.messages',
+ 'django.contrib.staticfiles',
+ # Uncomment the next line to enable the admin:
+ # 'django.contrib.admin',
+ # Uncomment the next line to enable admin documentation:
+ # 'django.contrib.admindocs',
+ 'generate_scaffold',
+ 'django_nose',
+)
+
+# A sample logging configuration. The only tangible logging
+# performed by this configuration is to send an email to
+# the site admins on every HTTP 500 error when DEBUG=False.
+# See http://docs.djangoproject.com/en/dev/topics/logging for
+# more details on how to customize your logging configuration.
+LOGGING = {
+ 'version': 1,
+ 'disable_existing_loggers': False,
+ 'filters': {
+ 'require_debug_false': {
+ '()': 'django.utils.log.RequireDebugFalse'
+ }
+ },
+ 'handlers': {
+ 'mail_admins': {
+ 'level': 'ERROR',
+ 'filters': ['require_debug_false'],
+ 'class': 'django.utils.log.AdminEmailHandler'
+ }
+ },
+ 'loggers': {
+ 'django.request': {
+ 'handlers': ['mail_admins'],
+ 'level': 'ERROR',
+ 'propagate': True,
+ },
+ }
+}
View
18 test_project/test_project/urls.py
@@ -0,0 +1,18 @@
+from django.conf.urls import patterns, include, url
+
+# Uncomment the next two lines to enable the admin:
+# from django.contrib import admin
+# admin.autodiscover()
+
+urlpatterns = patterns('',
+ # Examples:
+ # url(r'^$', 'test_project.views.home', name='home'),
+ # url(r'^test_project/', include('test_project.foo.urls')),
+
+ # Uncomment the admin/doc line below to enable admin documentation:
+ # url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
+
+ # Uncomment the next line to enable the admin:
+ # url(r'^admin/', include(admin.site.urls)),
+ url(r'^test_app/', include('test_app.urls')),
+)
View
28 test_project/test_project/wsgi.py
@@ -0,0 +1,28 @@
+"""
+WSGI config for test_project project.
+
+This module contains the WSGI application used by Django's development server
+and any production WSGI deployments. It should expose a module-level variable
+named ``application``. Django's ``runserver`` and ``runfcgi`` commands discover
+this application via the ``WSGI_APPLICATION`` setting.
+
+Usually you will have the standard Django WSGI application here, but it also
+might make sense to replace the whole Django WSGI application with a custom one
+that later delegates to the Django one. For example, you could introduce WSGI
+middleware here, or combine a Django application with an application of another
+framework.
+
+"""
+import os
+
+os.environ.setdefault("DJANGO_SETTINGS_MODULE", "test_project.settings")
+
+# This application object is used by any WSGI server configured to use this
+# file. This includes Django's development server, if the WSGI_APPLICATION
+# setting points here.
+from django.core.wsgi import get_wsgi_application
+application = get_wsgi_application()
+
+# Apply WSGI middleware here.
+# from helloworld.wsgi import HelloWorldApplication
+# application = HelloWorldApplication(application)

0 comments on commit 0c661b2

Please sign in to comment.