django context coverage

This commit is contained in:
Bernardo Heynemann 2011-05-09 20:53:52 -03:00
parent 536eb1f255
commit f23a51ff6d
2 changed files with 23 additions and 5 deletions

View file

@ -17,6 +17,8 @@ class DjangoContext(Vows.Context):
def __init__(self, parent): def __init__(self, parent):
super(DjangoContext, self).__init__(parent) super(DjangoContext, self).__init__(parent)
if not hasattr(self, '_get_settings'):
raise RuntimeError('The context %s needs a _get_settings method that returns the DJANGO_SETTINGS_MODULE environment variable value.' % self.__class__.__name__)
os.environ['DJANGO_SETTINGS_MODULE'] = self._get_settings() os.environ['DJANGO_SETTINGS_MODULE'] = self._get_settings()
#Gotta set settings environment variable first #Gotta set settings environment variable first
@ -24,10 +26,6 @@ class DjangoContext(Vows.Context):
setup_test_environment() setup_test_environment()
def _get_settings(self):
return 'settings'
def _url(self, path): def _url(self, path):
return Url(self, path) return Url(self, path)

View file

@ -8,4 +8,24 @@
# http://www.opensource.org/licenses/mit-license # http://www.opensource.org/licenses/mit-license
# Copyright (c) 2011 Rafael Caricio rafael@caricio.com # Copyright (c) 2011 Rafael Caricio rafael@caricio.com
from pyvows import Vows from pyvows import Vows, expect
from django_pyvows.context import DjangoContext
class DjangoFailedContext(DjangoContext):
pass
@Vows.batch
class ContextTest(Vows.Context):
def topic(self):
return DjangoFailedContext(self)
def should_be_an_error(self, topic):
expect(topic).to_be_an_error()
def should_be_runtime_error(self, topic):
expect(topic).to_be_an_error_like(RuntimeError)
def should_have_nice_error_message(self, topic):
expect(topic).to_have_an_error_message_of('The context DjangoFailedContext needs a _get_settings method that returns the DJANGO_SETTINGS_MODULE environment variable value.')