View assertions

This commit is contained in:
Bernardo Heynemann 2011-05-09 21:30:27 -03:00
parent f23a51ff6d
commit f44ed3884e
4 changed files with 50 additions and 2 deletions

View file

@ -8,7 +8,8 @@
# http://www.opensource.org/licenses/mit-license
# Copyright (c) 2011 Rafael Caricio rafael@caricio.com
from pyvows import Vows
from pyvows import Vows, expect
from django.http import HttpResponse
class Url(object):
def __init__(self, context, path):
@ -46,3 +47,12 @@ def verify_url_is_mapped_to_method(topic, method=None, assert_method_as_well=Fal
assert found, "Expected url(%s) to be mapped but it wasn't"
if assert_method_as_well:
assert matches_method, "Expected url(%s) to match method(%s), but it didn't"
@Vows.assertion
def to_be_http_response(topic):
expect(topic).to_be_instance_of(HttpResponse)
@Vows.assertion
def to_have_contents_of(topic, expected):
expect(topic.content).to_be_like(expected)

View file

@ -12,6 +12,7 @@ import os
from pyvows import Vows
from django_pyvows.assertions import Url
from django.http import HttpRequest
class DjangoContext(Vows.Context):
@ -29,8 +30,14 @@ class DjangoContext(Vows.Context):
def _url(self, path):
return Url(self, path)
def _request(self, **kw):
return HttpRequest(**kw)
class DjangoSubContext(Vows.Context):
def _url(self, path):
return self.parent._url(path)
def _request(self, **kw):
return self.parent._request(**kw)

View file

@ -10,7 +10,6 @@
from pyvows import Vows, expect
from django_pyvows.context import DjangoContext, DjangoSubContext
import django_pyvows.assertions
from sandbox.main.views import home

32
vows/view_vows.py Normal file
View file

@ -0,0 +1,32 @@
#!/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
from pyvows import Vows, expect
from django_pyvows.context import DjangoContext, DjangoSubContext
from django.http import HttpResponse
from sandbox.main.views import home
@Vows.batch
class ViewVows(DjangoContext):
def _get_settings(self):
return 'sandbox.settings'
class Home(DjangoSubContext):
def topic(self):
return home(self._request())
def should_be_instance_of_http_response(self, topic):
expect(topic).to_be_http_response()
def should_be_hello_world(self, topic):
expect(topic).to_have_contents_of('Hello World')