2011-08-22 20:06:54 +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
|
|
|
|
|
|
|
|
from pyvows import Vows, expect
|
|
|
|
|
|
|
|
from django_pyvows.context import DjangoContext, DjangoHTTPContext
|
2011-08-23 13:38:37 +00:00
|
|
|
from django_pyvows.settings_manager import settings_tracker, VowsSettings
|
2011-08-22 20:06:54 +00:00
|
|
|
|
2011-08-29 22:11:44 +00:00
|
|
|
DjangoContext.start_environment("sandbox.settings")
|
2011-08-22 20:06:54 +00:00
|
|
|
|
|
|
|
@Vows.batch
|
|
|
|
class SettingsVows(DjangoContext):
|
|
|
|
|
2011-08-23 13:38:37 +00:00
|
|
|
class WhenIUseTheSettingsTracker(DjangoContext):
|
2011-08-22 20:06:54 +00:00
|
|
|
|
2011-08-23 13:38:37 +00:00
|
|
|
def topic(self):
|
|
|
|
settings_tracker.install()
|
|
|
|
|
2012-03-09 21:55:05 +00:00
|
|
|
class WhenImportFromDjangoConf(DjangoContext):
|
2011-08-23 13:38:37 +00:00
|
|
|
|
2012-03-09 21:55:05 +00:00
|
|
|
def topic(self):
|
|
|
|
from django.conf import settings
|
|
|
|
return settings
|
2011-08-23 13:38:37 +00:00
|
|
|
|
2012-03-09 21:55:05 +00:00
|
|
|
def should_be_the_vows_settings(self, topic):
|
|
|
|
expect(topic).to_be_instance_of(VowsSettings)
|
2011-08-23 13:38:37 +00:00
|
|
|
|
2012-03-09 21:55:05 +00:00
|
|
|
class WhenIImportOnlyConfAndThenUseSettings(DjangoContext):
|
2011-08-23 13:38:37 +00:00
|
|
|
|
2012-03-09 21:55:05 +00:00
|
|
|
def topic(self):
|
|
|
|
from django import conf
|
|
|
|
return conf.settings
|
2011-08-22 20:06:54 +00:00
|
|
|
|
2012-03-09 21:55:05 +00:00
|
|
|
def should_be_the_vows_settings(self, topic):
|
|
|
|
expect(topic).to_be_instance_of(VowsSettings)
|
2011-08-22 20:06:54 +00:00
|
|
|
|
2012-03-09 21:55:05 +00:00
|
|
|
class WhenIImportTheCompletePathAndThenUseSettings(DjangoContext):
|
2011-08-22 20:06:54 +00:00
|
|
|
|
2012-03-09 21:55:05 +00:00
|
|
|
def topic(self):
|
|
|
|
import django.conf
|
|
|
|
return django.conf.settings
|
2011-08-22 20:06:54 +00:00
|
|
|
|
2012-03-09 21:55:05 +00:00
|
|
|
def should_be_the_vows_settings(self, topic):
|
|
|
|
expect(topic).to_be_instance_of(VowsSettings)
|
2011-08-22 20:06:54 +00:00
|
|
|
|
2012-03-09 21:55:05 +00:00
|
|
|
class CannotSayHelloWithoutName(DjangoHTTPContext):
|
2011-08-22 20:06:54 +00:00
|
|
|
|
2012-03-09 21:55:05 +00:00
|
|
|
def topic(self):
|
|
|
|
self.start_server(port=9000, settings={
|
|
|
|
'SAY_HELLO_WITHOUT_NAME': False
|
|
|
|
})
|
|
|
|
|
|
|
|
return self.get('/say/')
|
2011-08-22 20:06:54 +00:00
|
|
|
|
2012-03-09 21:55:05 +00:00
|
|
|
def should_be_ok(self, (topic, content)):
|
|
|
|
expect(topic.status).to_equal(200)
|
2011-08-22 20:06:54 +00:00
|
|
|
|
2012-03-09 21:55:05 +00:00
|
|
|
def should_ask_for_my_name(self, (topic, content)):
|
|
|
|
expect(content).to_equal("What's your name?")
|
2011-08-22 20:06:54 +00:00
|
|
|
|
|
|
|
class SayHelloWithoutName(DjangoHTTPContext):
|
|
|
|
|
|
|
|
def topic(self):
|
2012-03-09 17:02:27 +00:00
|
|
|
self.start_server(port=9001, settings={
|
|
|
|
'SAY_HELLO_WITHOUT_NAME': True
|
|
|
|
})
|
2011-08-22 20:06:54 +00:00
|
|
|
return self.get('/say/')
|
|
|
|
|
2012-03-08 18:57:32 +00:00
|
|
|
def should_be_ok(self, (topic, content)):
|
|
|
|
expect(topic.status).to_equal(200)
|
2011-08-22 20:06:54 +00:00
|
|
|
|
2012-03-08 18:57:32 +00:00
|
|
|
def should_(self, (topic, content)):
|
|
|
|
expect(content).to_equal("Hello, guess!")
|
2011-08-22 20:06:54 +00:00
|
|
|
|