Skip to content

Commit

Permalink
Merged head from zbyte64/django-configstore to webcube/django-configs…
Browse files Browse the repository at this point in the history
…tore to add new test fixes.
  • Loading branch information
apires committed Mar 7, 2013
1 parent 0edf7dd commit 3c7c552
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 33 deletions.
12 changes: 12 additions & 0 deletions configstore/serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,18 @@ def default(self, obj):
if isinstance(obj, handler.instancetype):
return handler.encode(obj)
return super(JSONEncoder, self).default(obj)

def encode(self, o):
if isinstance(o, dict):
new_struct = dict()
for key, value in o.iteritems():
for handler in self.handlers:
if isinstance(value, handler.instancetype):
value = handler.encode(value)
break
new_struct[key] = value
return super(JSONEncoder, self).encode(new_struct)
return super(JSONEncoder, self).encode(o)

def make_serializers():
handlers = [ModelHandler(), DecimalHandler()]
Expand Down
7 changes: 7 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@
url='http://github.com/cuker/django-configstore',
packages=find_packages(exclude=['ez_setup', 'test', 'tests']),
test_suite='tests.runtests.runtests',
tests_require=(
'pep8',
'coverage',
'django',
'nose',
'django-nose',
),
include_package_data=True,
license = 'BSD',
classifiers=[
Expand Down
11 changes: 0 additions & 11 deletions tests/manage.py

This file was deleted.

36 changes: 27 additions & 9 deletions tests/runtests.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,33 @@
import os, sys
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
test_dir = os.path.dirname(__file__)
sys.path.insert(0, test_dir)
"""
Test support harness for doing setup.py test.
See http://ericholscher.com/blog/2009/jun/29/enable-setuppy-test-your-django-apps/.
"""
import sys

from django.test.simple import run_tests as django_test_runner
import os

os.environ['DJANGO_SETTINGS_MODULE'] = 'tests.test_settings'

# Bootstrap Django's settings.
from django.conf import settings
settings.DATABASES = {
'default': {'ENGINE': 'django.db.backends.sqlite3', 'NAME': ':memory;'}
}
settings.TEST_RUNNER = "django_nose.NoseTestSuiteRunner"

def runtests():
failures = django_test_runner(['configstore'], verbosity=1, interactive=True)
sys.exit(failures)
"""Test runner for setup.py test."""
# Run you some tests.
import django.test.utils
runner_class = django.test.utils.get_runner(settings)
test_runner = runner_class(verbosity=1, interactive=True)
failures = test_runner.run_tests(['configstore'])

if __name__ == '__main__':
runtests()
# Okay, so this is a nasty hack. If this isn't here, `setup.py test` craps out
# when generating a coverage report via Nose. I have no idea why, or what's
# supposed to be going on here, but this seems to fix the problem, and I
# *really* want coverage, so, unless someone can tell me *why* I shouldn't
# do this, I'm going to just whistle innocently and keep on doing this.
sys.exitfunc = lambda: 0

sys.exit(failures)
29 changes: 17 additions & 12 deletions tests/settings.py → tests/test_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,17 @@

MANAGERS = ADMINS

DATABASE_ENGINE = 'sqlite3'
DATABASE_NAME = 'db.sqlite'
DATABASE_USER = ''
DATABASE_PASSWORD = ''
DATABASE_HOST = ''
DATABASE_PORT = ''

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
'NAME': ':memory:', # 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.
}
}



Expand Down Expand Up @@ -54,19 +59,20 @@

# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.load_template_source',
'django.template.loaders.app_directories.load_template_source',
# 'django.template.loaders.eggs.load_template_source',
'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.middleware.doc.XViewMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
)

ROOT_URLCONF = 'urls'
ROOT_URLCONF = 'tests.urls'

from os import path
CUR_DIR = path.dirname(__file__)
Expand All @@ -85,6 +91,5 @@
'django.contrib.admin',
'django.contrib.sessions',
'configstore',
'example_app',
)

2 changes: 1 addition & 1 deletion tests/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
admin.autodiscover()

urlpatterns = patterns('',
(r'^$', 'example_app.views.display_my_config'),
#(r'^$', 'example_app.views.display_my_config'),
(r'^admin/', include(admin.site.urls)),
)

0 comments on commit 3c7c552

Please sign in to comment.