Fixing problem with parent configuration.

This commit is contained in:
Rafael Caricio 2011-08-22 10:39:02 -03:00
parent 728dee527d
commit f3470f2693
4 changed files with 33 additions and 8 deletions

View file

@ -9,6 +9,7 @@
# Copyright (c) 2011 Rafael Caricio rafael@caricio.com
import os
import re
import urllib2
from pyvows import Vows
@ -28,9 +29,14 @@ class DjangoContext(Vows.Context):
def __init__(self, parent):
super(DjangoContext, self).__init__(parent)
self.port = 8080
self.host = '127.0.0.1'
self.ignore('get_settings', 'template', 'request', 'model', 'url', 'start_environment', 'get_url', 'get', 'post')
if parent:
self.port = parent.port
self.host = parent.host
else:
self.port = 3331
self.host = '127.0.0.1'
self.ignore('get_settings', 'template', 'request', 'model', 'url',
'start_environment', 'port', 'host', 'get_url', 'get', 'post')
def setup(self):
DjangoContext.start_environment(self.get_settings())
@ -75,9 +81,10 @@ class DjangoHTTPContext(DjangoContext):
def __init__(self, parent):
super(DjangoHTTPContext, self).__init__(parent)
self.port = 3331
self.host = '127.0.0.1'
self.ignore('start_server', 'port', 'host')
self.ignore('start_server', 'settings')
def get_url(self, path):
if re.match('^https?:\/\/', path):
return path
return 'http://%s:%d%s' % (self.host, self.port, path)

View file

@ -8,12 +8,27 @@
# http://www.opensource.org/licenses/mit-license
# Copyright (c) 2011 Rafael Caricio rafael@caricio.com
from django.conf import settings
from django.http import HttpResponse
def home(request):
return HttpResponse('hello world')
def say_hello(request):
if not 'name' in request.GET:
SAY_HELLO_WITHOUT_NAME = getattr(settings, "SAY_HELLO_WITHOUT_NAME", False)
if 'name' in request.GET:
name = request.GET['name']
elif not SAY_HELLO_WITHOUT_NAME:
return HttpResponse("What's your name?")
return HttpResponse("Hello, %s!" % request.GET['name'])
elif SAY_HELLO_WITHOUT_NAME:
name = 'guess'
return HttpResponse("Hello, %s!" % name)
def get_setting(request, attr):
return HttpResponse(str(getattr(settings, attr)))

View file

@ -130,6 +130,8 @@ INSTALLED_APPS = (
# 'django.contrib.admindocs',
)
SAY_HELLO_WITHOUT_NAME = False
# 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.

View file

@ -17,6 +17,7 @@ from django.conf.urls.defaults import patterns, include, url
urlpatterns = patterns('',
url(r'^$', 'sandbox.main.views.home', name='home'),
url(r'^say/$', 'sandbox.main.views.say_hello', name='say_hello'),
url(r'^settings/(?P<attr>[\w_]+)/?$', 'sandbox.main.views.get_setting', name='get_setting'),
# url(r'^sandbox/', include('sandbox.foo.urls')),