Remove useless assertions

This commit is contained in:
Rafael Caricio 2015-07-18 22:39:47 +02:00
parent 27492fd8c6
commit 8adb51c756
5 changed files with 3 additions and 128 deletions

View file

@ -8,6 +8,5 @@
# http://www.opensource.org/licenses/mit-license
# Copyright (c) 2011 Rafael Caricio rafael@caricio.com
from urls import *
from models import *
from templates import *
from models import * # NOQA
from templates import * # NOQA

View file

@ -1,54 +0,0 @@
#!/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.http import HttpResponse
class Url(object):
def __init__(self, context, path):
self.context = context
self.path = path
@Vows.assertion
def to_be_mapped(topic):
verify_url_is_mapped_to_method(topic)
@Vows.assertion
def to_match_view(topic, view):
verify_url_is_mapped_to_method(topic, view, True)
@Vows.assertion
def to_be_http_response(topic):
expect(topic).to_be_instance_of(HttpResponse)
def verify_url_is_mapped_to_method(topic, method=None, assert_method_as_well=False):
assert isinstance(topic, Url), "Only django_pyvows.Url items can be verified for mapping"
from django.conf import settings
project_urls = settings.ROOT_URLCONF
urlpatterns = __import__(project_urls).urls.urlpatterns
found = False
matches_method = False
for urlpattern in urlpatterns:
regex = urlpattern.regex
pattern = regex.pattern
actual_method = urlpattern.callback
if topic.path == pattern:
found = True
if method == actual_method:
matches_method = True
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"

View file

@ -12,10 +12,9 @@ import os
import django
from pyvows import Vows
from django.http import HttpRequest
from django_pyvows import http_helpers
from django_pyvows.assertions import Url, Model, Template
from django_pyvows.assertions import Model, Template
class DjangoContext(Vows.Context):
@ -44,15 +43,9 @@ class DjangoContext(Vows.Context):
from django.test.utils import modify_settings
return modify_settings(**kwargs)
def url(self, path):
return Url(self, path)
def template(self, template_name, context):
return Template(template_name, context)
def request(self, **kw):
return HttpRequest(**kw)
def model(self, model_class):
return Model(self, model_class)

View file

@ -1,32 +0,0 @@
#!/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 expect
from django_pyvows.context import DjangoContext
from django_pyvows.assertions import * # NOQA
DjangoContext.start_environment("sandbox.settings")
from sandbox.main.views import home # NOQA
class UrlVows(DjangoContext):
class Home(DjangoContext):
def topic(self):
return self.url('^$')
def should_have_home_url_mapped(self, topic):
expect(topic).to_be_mapped()
def should_have_url_mapped_to_home_view(self, topic):
expect(topic).to_match_view(home)

View file

@ -1,31 +0,0 @@
#!/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
DjangoContext.start_environment("sandbox.settings")
from sandbox.main.views import home # NOQA
@Vows.batch
class ViewVows(DjangoContext):
class Home(DjangoContext):
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')