This repository has been archived on 2023-01-02. You can view files and clone it, but cannot push or open issues or pull requests.
django-pyvows/django_pyvows/context.py

37 lines
1.1 KiB
Python
Raw Normal View History

2011-05-06 02:53:07 +00:00
#!/usr/bin/python
# -*- coding: utf-8 -*-
# django-pyvows extensions
# https://github.com/rafaelcaricio/django-pyvows
# Licensed under the MIT license:
# http://www.opensource.org/licenses/mit-license
# Copyright (c) 2011 Rafael Caricio rafael@caricio.com
2011-05-09 20:20:46 +00:00
import os
2011-05-06 02:53:07 +00:00
from pyvows import Vows
2011-05-09 20:20:46 +00:00
from django_pyvows.assertions import Url
2011-05-06 03:48:39 +00:00
2011-05-09 20:20:46 +00:00
class DjangoContext(Vows.Context):
2011-05-06 03:48:39 +00:00
2011-05-09 20:20:46 +00:00
def __init__(self, parent):
super(DjangoContext, self).__init__(parent)
2011-05-09 23:53:52 +00:00
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__)
2011-05-09 20:20:46 +00:00
os.environ['DJANGO_SETTINGS_MODULE'] = self._get_settings()
2011-05-06 03:48:39 +00:00
2011-05-09 20:20:46 +00:00
#Gotta set settings environment variable first
from django.test.utils import setup_test_environment #, teardown_test_environment
2011-05-06 03:48:39 +00:00
setup_test_environment()
2011-05-09 20:20:46 +00:00
def _url(self, path):
return Url(self, path)
class DjangoSubContext(Vows.Context):
def _url(self, path):
return self.parent._url(path)