Tests for management of the django settings module.

This commit is contained in:
Rafael Caricio 2011-08-23 10:38:37 -03:00
parent 40940cfe22
commit 5992cab02e
2 changed files with 31 additions and 20 deletions

View file

@ -21,10 +21,11 @@ class SettingsTracker(object):
def _import(self, name, globals=None, locals=None, fromlist=[], level=-1):
result = apply(self.real_import, (name, globals, locals, fromlist, level))
if name == 'django.conf':
fromlist = (fromlist or [])
if name == 'django.conf' and 'settings' in fromlist:
result.settings = VowsSettings(result.settings)
elif name == "django" and 'conf' in (fromlist or []):
result.conf.settings = VowsSettings(result.settings)
elif name == "django" and 'conf' in fromlist:
result.conf.settings = VowsSettings(result.conf.settings)
return result
class VowsSettings(object):

View file

@ -11,33 +11,43 @@
from pyvows import Vows, expect
from django_pyvows.context import DjangoContext, DjangoHTTPContext
#from django_pyvows.settings_manager import settings_tracker
from django_pyvows.settings_manager import settings_tracker, VowsSettings
@Vows.batch
class SettingsVows(DjangoContext):
#class WhenIUseTheModulesTracker(DjangoContext):
class WhenIUseTheSettingsTracker(DjangoContext):
#def topic(self):
#settings_tracker.install()
#import to_test
#return modules_tracker
def topic(self):
settings_tracker.install()
#def should_track_the_new_imported_module(self, topic):
#expect('to_test' in topic.new_modules).to_be_true()
class WhenImportFromDjangoConf(DjangoContext):
#class WhenIReloadTheImportedModule(DjangoContext):
def topic(self):
from django.conf import settings
return settings
#def topic(self, modules_tracker):
#import to_test
#imported_first_time_at = to_test.imported_at
#modules_tracker.reload()
#import to_test
#return (modules_tracker, imported_first_time_at, to_test.imported_at)
def should_be_the_vows_settings(self, topic):
expect(topic).to_be_instance_of(VowsSettings)
#def should_be_different_instances(self, topic):
#expect(topic[1]).not_to_equal(topic[2])
class WhenIImportOnlyConfAndThenUseSettings(DjangoContext):
def topic(self):
from django import conf
return conf.settings
def should_be_the_vows_settings(self, topic):
expect(topic).to_be_instance_of(VowsSettings)
class WhenIImportTheCompletePathAndThenUseSettings(DjangoContext):
def topic(self):
import django.conf
return django.conf.settings
def should_be_the_vows_settings(self, topic):
expect(topic).to_be_instance_of(VowsSettings)
class CannotSayHelloWithoutName(DjangoHTTPContext):