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-10 02:33:56 +00:00
|
|
|
import os
|
2011-08-18 20:18:45 +00:00
|
|
|
|
2015-07-18 20:33:33 +00:00
|
|
|
import django
|
2011-08-18 21:44:43 +00:00
|
|
|
from pyvows import Vows
|
2011-08-18 20:18:45 +00:00
|
|
|
|
2011-08-22 18:08:00 +00:00
|
|
|
from django_pyvows import http_helpers
|
2015-07-18 20:39:47 +00:00
|
|
|
from django_pyvows.assertions import Model, Template
|
2011-08-18 20:18:45 +00:00
|
|
|
|
|
|
|
|
2011-08-18 21:44:43 +00:00
|
|
|
class DjangoContext(Vows.Context):
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def start_environment(cls, settings_path):
|
|
|
|
if not settings_path:
|
2015-07-18 20:33:33 +00:00
|
|
|
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()
|
2011-08-18 20:18:45 +00:00
|
|
|
|
2011-08-18 21:44:43 +00:00
|
|
|
def __init__(self, parent):
|
|
|
|
super(DjangoContext, self).__init__(parent)
|
2015-07-18 20:36:24 +00:00
|
|
|
self.ignore('template', 'request', 'model', 'url', 'find_in_parent',
|
|
|
|
'start_environment', 'settings', 'modify_settings', 'get', 'post')
|
2011-08-18 20:18:45 +00:00
|
|
|
|
2015-07-18 20:33:33 +00:00
|
|
|
def settings(self, **kwargs):
|
|
|
|
from django.test.utils import override_settings
|
|
|
|
return override_settings(**kwargs)
|
2011-08-18 20:18:45 +00:00
|
|
|
|
2015-07-18 20:33:33 +00:00
|
|
|
def modify_settings(self, **kwargs):
|
|
|
|
from django.test.utils import modify_settings
|
|
|
|
return modify_settings(**kwargs)
|
2011-08-18 20:18:45 +00:00
|
|
|
|
2011-08-18 21:44:43 +00:00
|
|
|
def template(self, template_name, context):
|
|
|
|
return Template(template_name, context)
|
|
|
|
|
|
|
|
def model(self, model_class):
|
|
|
|
return Model(self, model_class)
|
|
|
|
|
2011-08-18 21:47:23 +00:00
|
|
|
def get(self, path):
|
2015-07-18 20:33:33 +00:00
|
|
|
return http_helpers.get(path)
|
2011-08-18 21:44:43 +00:00
|
|
|
|
2011-08-18 21:47:23 +00:00
|
|
|
def post(self, path, params):
|
2015-07-18 20:33:33 +00:00
|
|
|
return http_helpers.post(path, params)
|
2011-12-21 19:36:13 +00:00
|
|
|
|
2012-03-09 17:02:27 +00:00
|
|
|
|
2011-08-18 21:44:43 +00:00
|
|
|
class DjangoHTTPContext(DjangoContext):
|
2015-07-18 20:33:33 +00:00
|
|
|
pass
|