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-18 23:25:24 +02:00

44 lines
1.2 KiB
Python

#!/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
import os
import django
from pyvows import Vows
from django_pyvows import http_helpers
class DjangoContext(Vows.Context):
@classmethod
def start_environment(cls, settings_path):
if not settings_path:
raise ValueError('The settings_path argument is required.')
os.environ.update({'DJANGO_SETTINGS_MODULE': settings_path})
django.setup()
from django.test.utils import setup_test_environment
setup_test_environment()
def __init__(self, parent):
super(DjangoContext, self).__init__(parent)
self.ignore('start_environment', 'settings', 'get', 'post')
def settings(self, **kwargs):
from django.test.utils import override_settings
return override_settings(**kwargs)
def get(self, *args, **kwargs):
return http_helpers.get(*args, **kwargs)
def post(self, *args, **kwargs):
return http_helpers.post(*args, **kwargs)