Guarantee override settings works

This commit is contained in:
Rafael Caricio 2015-07-18 23:25:24 +02:00
parent 242bb9df19
commit 7dcbf31c5a
4 changed files with 73 additions and 9 deletions

View file

@ -31,16 +31,12 @@ class DjangoContext(Vows.Context):
def __init__(self, parent):
super(DjangoContext, self).__init__(parent)
self.ignore('start_environment', 'settings', 'modify_settings', 'get', 'post')
self.ignore('start_environment', 'settings', 'get', 'post')
def settings(self, **kwargs):
from django.test.utils import override_settings
return override_settings(**kwargs)
def modify_settings(self, **kwargs):
from django.test.utils import modify_settings
return modify_settings(**kwargs)
def get(self, *args, **kwargs):
return http_helpers.get(*args, **kwargs)

61
vows/client_vows.py Normal file
View file

@ -0,0 +1,61 @@
#!/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 os.path import abspath, join, dirname
from pyvows import Vows, expect
from django_pyvows.context import DjangoContext
TEST_FILE_PATH = abspath(join(dirname(__file__), 'fixtures/the_file.txt'))
DjangoContext.start_environment("sandbox.sandbox.settings")
@Vows.batch
class DjangoHTTPTestClientCompatibilityVows(DjangoContext):
class SimpleGet(DjangoContext):
def topic(self):
return self.get('/say/')
def should_be_ok(self, topic):
expect(topic.status_code).to_equal(200)
def should_ask_for_my_name(self, topic):
expect(topic.content).to_equal('What\'s your name?')
class SimpleGetWithParams(DjangoContext):
def topic(self):
return self.get('/say/?name=Rafael')
def should_say_hello_to_me(self, topic):
expect(topic.content).to_equal('Hello, Rafael!')
class SimplePost(DjangoContext):
def topic(self):
return self.post('/post_it/', {'value': 'posted!'})
def should_be_posted(self, topic):
expect(topic.content).to_equal('posted!')
class PostFile(DjangoContext):
def topic(self):
return self.post('/post_file/', {'the_file': open(TEST_FILE_PATH)})
def should_be_posted_to_the_server(self, topic):
expect(topic.content).to_equal("the contents")
class WhenNotFound(DjangoContext):
def topic(self):
return self.post('/post_/', {'the_file': open(TEST_FILE_PATH)})
def should_be_404(self, topic):
expect(topic.status_code).to_equal(404)

View file

@ -21,7 +21,7 @@ def say_hello(request):
if 'name' in request.GET:
name = request.GET['name']
elif SAY_HELLO_WITHOUT_NAME:
name = 'guess'
name = 'guest'
else:
return HttpResponse("What's your name?")
return HttpResponse("Hello, %s!" % name)

View file

@ -9,6 +9,7 @@
# Copyright (c) 2011 Rafael Caricio rafael@caricio.com
from pyvows import Vows, expect
from django.test.utils import override_settings
from django_pyvows.context import DjangoContext
@ -19,7 +20,6 @@ DjangoContext.start_environment("sandbox.sandbox.settings")
class SettingsOverridingVows(DjangoContext):
class CannotSayHelloWithoutName(DjangoContext):
def topic(self):
with self.settings(SAY_HELLO_WITHOUT_NAME=False):
return self.get('/say/')
@ -31,7 +31,6 @@ class SettingsOverridingVows(DjangoContext):
expect(topic.content).to_equal("What's your name?")
class SayHelloWithoutName(DjangoContext):
def topic(self):
with self.settings(SAY_HELLO_WITHOUT_NAME=True):
return self.get('/say/')
@ -40,4 +39,12 @@ class SettingsOverridingVows(DjangoContext):
expect(topic.status_code).to_equal(200)
def should_(self, topic):
expect(topic.content).to_equal("Hello, guess!")
expect(topic.content).to_equal("Hello, guest!")
class UseDecoratorToChangeSettings(DjangoContext):
@override_settings(SAY_HELLO_WITHOUT_NAME=True)
def topic(self):
return self.get('/say/')
def should_say_hello_to_guest(self, topic):
expect(topic.content).to_equal("Hello, guest!")