Django pyvows FIXED

This commit is contained in:
Bernardo Heynemann 2012-03-09 18:55:05 -03:00
parent 5c90b4e77e
commit d26f1de0db
4 changed files with 35 additions and 37 deletions

View file

@ -1,5 +1,5 @@
pyvows: db 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: 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/ @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/

View file

@ -16,10 +16,6 @@ from cherrypy import wsgiserver
from django.core.handlers.wsgi import WSGIHandler 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): def run_app(host, port):
server = wsgiserver.CherryPyWSGIServer( server = wsgiserver.CherryPyWSGIServer(
(host, port), (host, port),
@ -51,9 +47,10 @@ class DjangoServer(object):
sleep(0.1) sleep(0.1)
for _thread in self.thr.server.requests._threads: 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(): for k, v in settings.iteritems():
setattr(_thread.settings, k, v) _thread.settings[k] = v
#setattr(_thread.settings, k, v)

View file

@ -35,8 +35,8 @@ class VowsSettings(object):
def __getattr__(self, attr_name): def __getattr__(self, attr_name):
thread = current_thread() thread = current_thread()
if hasattr(thread, 'settings'): if hasattr(thread, 'settings'):
if hasattr(thread.settings, attr_name): if attr_name in thread.settings:
return getattr(thread.settings, attr_name) return thread.settings[attr_name]
return getattr(self.original_settings, attr_name) return getattr(self.original_settings, attr_name)
settings_tracker = SettingsTracker() settings_tracker = SettingsTracker()

View file

@ -23,50 +23,51 @@ class SettingsVows(DjangoContext):
def topic(self): def topic(self):
settings_tracker.install() settings_tracker.install()
#class WhenImportFromDjangoConf(DjangoContext): class WhenImportFromDjangoConf(DjangoContext):
#def topic(self): def topic(self):
#from django.conf import settings from django.conf import settings
#return settings return settings
#def should_be_the_vows_settings(self, topic): def should_be_the_vows_settings(self, topic):
#expect(topic).to_be_instance_of(VowsSettings) expect(topic).to_be_instance_of(VowsSettings)
#class WhenIImportOnlyConfAndThenUseSettings(DjangoContext): class WhenIImportOnlyConfAndThenUseSettings(DjangoContext):
#def topic(self): def topic(self):
#from django import conf from django import conf
#return conf.settings return conf.settings
#def should_be_the_vows_settings(self, topic): def should_be_the_vows_settings(self, topic):
#expect(topic).to_be_instance_of(VowsSettings) expect(topic).to_be_instance_of(VowsSettings)
#class WhenIImportTheCompletePathAndThenUseSettings(DjangoContext): class WhenIImportTheCompletePathAndThenUseSettings(DjangoContext):
#def topic(self): def topic(self):
#import django.conf import django.conf
#return django.conf.settings return django.conf.settings
#def should_be_the_vows_settings(self, topic): def should_be_the_vows_settings(self, topic):
#expect(topic).to_be_instance_of(VowsSettings) expect(topic).to_be_instance_of(VowsSettings)
#class CannotSayHelloWithoutName(DjangoHTTPContext): class CannotSayHelloWithoutName(DjangoHTTPContext):
#def topic(self): def topic(self):
#self.settings.SAY_HELLO_WITHOUT_NAME = False self.start_server(port=9000, settings={
#self.start_server(port=9000) 'SAY_HELLO_WITHOUT_NAME': False
#return self.get('/say/') })
#def should_be_ok(self, (topic, content)): return self.get('/say/')
#expect(topic.status).to_equal(200)
#def should_ask_for_my_name(self, (topic, content)): def should_be_ok(self, (topic, content)):
#expect(content).to_equal("What's your name?") 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): class SayHelloWithoutName(DjangoHTTPContext):
def topic(self): def topic(self):
#self.settings.SAY_HELLO_WITHOUT_NAME = True
self.start_server(port=9001, settings={ self.start_server(port=9001, settings={
'SAY_HELLO_WITHOUT_NAME': True 'SAY_HELLO_WITHOUT_NAME': True
}) })