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

54 lines
1.4 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-10 02:33:56 +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-10 02:14:48 +00:00
from django_pyvows.model_assertions import Model
2011-05-10 00:30:27 +00:00
from django.http import HttpRequest
2011-05-06 03:48:39 +00:00
2011-05-10 02:33:56 +00:00
class DjangoContext(Vows.Context):
2011-05-10 02:14:48 +00:00
@classmethod
def _start_environment(cls, settings_path):
if not settings_path:
raise RuntimeError('The settings_path argument is required.')
os.environ['DJANGO_SETTINGS_MODULE'] = settings_path
2011-05-06 03:48:39 +00:00
2011-05-10 02:33:56 +00:00
def __init__(self, parent):
super(DjangoContext, self).__init__(parent)
def _get_settings(self):
return 'settings'
def _url(self, path):
return Url(self, path)
2011-05-10 03:45:24 +00:00
def _template(self, template_name, context):
return Template(template_name, context)
2011-05-10 02:33:56 +00:00
class DjangoSubContext(Vows.Context):
def _url(self, path):
return self.parent._url(path)
2011-05-10 03:45:24 +00:00
def _template(self, template_name, context={}):
return self.parent._template(template_name, context)
2011-05-09 20:20:46 +00:00
def _url(self, path):
return Url(self, path)
2011-05-10 00:30:27 +00:00
def _request(self, **kw):
return HttpRequest(**kw)
2011-05-10 02:14:48 +00:00
def _model(self, model_class):
return Model(self, model_class)