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

43 lines
1.2 KiB
Python
Raw Normal View History

2011-05-06 02:53:07 +00:00
# -*- 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-10 02:33:56 +00:00
import os
2015-07-18 20:33:33 +00:00
import django
from pyvows import Vows
2015-07-19 09:17:55 +00:00
from django_pyvows.http_helpers import HttpClientSupport
from django_pyvows.settings_helpers import SettingsOverrideSupport
2015-07-19 09:17:55 +00:00
class DjangoContext(Vows.Context, HttpClientSupport, SettingsOverrideSupport):
def __init__(self, parent):
super(DjangoContext, self).__init__(parent)
2015-07-19 09:42:54 +00:00
2015-07-19 09:17:55 +00:00
HttpClientSupport.__init__(self)
SettingsOverrideSupport.__init__(self)
2015-07-19 09:42:54 +00:00
self.ignore('setup_environment', 'settings_module')
DjangoContext.setup_environment(self.settings_module())
2015-07-19 09:17:55 +00:00
def settings_module(self):
return 'settings'
@classmethod
2015-07-19 09:42:54 +00:00
def setup_environment(cls, settings_module):
2015-07-19 09:17:55 +00:00
if not settings_module:
2015-07-18 20:33:33 +00:00
raise ValueError('The settings_path argument is required.')
2015-07-19 09:17:55 +00:00
os.environ.update({'DJANGO_SETTINGS_MODULE': settings_module})
2015-07-18 20:33:33 +00:00
django.setup()
from django.test.utils import setup_test_environment
setup_test_environment()