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
2015-07-19 11:42:54 +02:00

42 lines
1.2 KiB
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
import os
import django
from pyvows import Vows
from django_pyvows.http_helpers import HttpClientSupport
from django_pyvows.settings_helpers import SettingsOverrideSupport
class DjangoContext(Vows.Context, HttpClientSupport, SettingsOverrideSupport):
def __init__(self, parent):
super(DjangoContext, self).__init__(parent)
HttpClientSupport.__init__(self)
SettingsOverrideSupport.__init__(self)
self.ignore('setup_environment', 'settings_module')
DjangoContext.setup_environment(self.settings_module())
def settings_module(self):
return 'settings'
@classmethod
def setup_environment(cls, settings_module):
if not settings_module:
raise ValueError('The settings_path argument is required.')
os.environ.update({'DJANGO_SETTINGS_MODULE': settings_module})
django.setup()
from django.test.utils import setup_test_environment
setup_test_environment()