diff --git a/Makefile b/Makefile index eff261f..f63b348 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ pyvows: db - @env PYTHONPATH=$$PYTHONPATH:vows/sandbox/:. pyvows --cover --cover_package=django_pyvows --cover_threshold=95 vows/settings_vows.py + @env PYTHONPATH=$$PYTHONPATH:vows/sandbox/:. pyvows --cover --cover_package=django_pyvows --cover_threshold=95 vows/ ci_test: @env PYTHONPATH=$$PYTHONPATH:vows/sandbox/:. python vows/sandbox/manage.py syncdb && pyvows --no_color --cover --cover_package=django_pyvows --cover_threshold=100 -r django_pyvows.coverage.xml -x vows/ diff --git a/django_pyvows/server.py b/django_pyvows/server.py index 7a0d684..f04047b 100644 --- a/django_pyvows/server.py +++ b/django_pyvows/server.py @@ -16,10 +16,6 @@ from cherrypy import wsgiserver from django.core.handlers.wsgi import WSGIHandler -def make_response_thread(thread, settings): - if not hasattr(thread, 'settings'): - thread.settings = settings - def run_app(host, port): server = wsgiserver.CherryPyWSGIServer( (host, port), @@ -51,9 +47,10 @@ class DjangoServer(object): sleep(0.1) for _thread in self.thr.server.requests._threads: - _thread.settings = hasattr(_thread, 'settings') and _thread.settings or local() + _thread.settings = hasattr(_thread, 'settings') and _thread.settings or {} for k, v in settings.iteritems(): - setattr(_thread.settings, k, v) + _thread.settings[k] = v + #setattr(_thread.settings, k, v) diff --git a/django_pyvows/settings_manager.py b/django_pyvows/settings_manager.py index f8365cf..fbdebc2 100644 --- a/django_pyvows/settings_manager.py +++ b/django_pyvows/settings_manager.py @@ -35,8 +35,8 @@ class VowsSettings(object): def __getattr__(self, attr_name): thread = current_thread() if hasattr(thread, 'settings'): - if hasattr(thread.settings, attr_name): - return getattr(thread.settings, attr_name) + if attr_name in thread.settings: + return thread.settings[attr_name] return getattr(self.original_settings, attr_name) settings_tracker = SettingsTracker() diff --git a/vows/settings_vows.py b/vows/settings_vows.py index c1f5441..d40eb36 100644 --- a/vows/settings_vows.py +++ b/vows/settings_vows.py @@ -23,50 +23,51 @@ class SettingsVows(DjangoContext): def topic(self): settings_tracker.install() - #class WhenImportFromDjangoConf(DjangoContext): + class WhenImportFromDjangoConf(DjangoContext): - #def topic(self): - #from django.conf import settings - #return settings + def topic(self): + from django.conf import settings + return settings - #def should_be_the_vows_settings(self, topic): - #expect(topic).to_be_instance_of(VowsSettings) + def should_be_the_vows_settings(self, topic): + expect(topic).to_be_instance_of(VowsSettings) - #class WhenIImportOnlyConfAndThenUseSettings(DjangoContext): + class WhenIImportOnlyConfAndThenUseSettings(DjangoContext): - #def topic(self): - #from django import conf - #return conf.settings + 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) + def should_be_the_vows_settings(self, topic): + expect(topic).to_be_instance_of(VowsSettings) - #class WhenIImportTheCompletePathAndThenUseSettings(DjangoContext): + class WhenIImportTheCompletePathAndThenUseSettings(DjangoContext): - #def topic(self): - #import django.conf - #return django.conf.settings + 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) + def should_be_the_vows_settings(self, topic): + expect(topic).to_be_instance_of(VowsSettings) - #class CannotSayHelloWithoutName(DjangoHTTPContext): + class CannotSayHelloWithoutName(DjangoHTTPContext): - #def topic(self): - #self.settings.SAY_HELLO_WITHOUT_NAME = False - #self.start_server(port=9000) - #return self.get('/say/') + def topic(self): + self.start_server(port=9000, settings={ + 'SAY_HELLO_WITHOUT_NAME': False + }) - #def should_be_ok(self, (topic, content)): - #expect(topic.status).to_equal(200) + return self.get('/say/') - #def should_ask_for_my_name(self, (topic, content)): - #expect(content).to_equal("What's your name?") + def should_be_ok(self, (topic, content)): + expect(topic.status).to_equal(200) + + def should_ask_for_my_name(self, (topic, content)): + expect(content).to_equal("What's your name?") class SayHelloWithoutName(DjangoHTTPContext): def topic(self): - #self.settings.SAY_HELLO_WITHOUT_NAME = True self.start_server(port=9001, settings={ 'SAY_HELLO_WITHOUT_NAME': True })