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/vows/context_vows.py

118 lines
3.5 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-09 23:53:52 +00:00
from pyvows import Vows, expect
from django_pyvows.context import DjangoContext, DjangoHTTPContext
2011-05-09 23:53:52 +00:00
@Vows.batch
class ContextTest(Vows.Context):
def topic(self):
return DjangoContext.start_environment(None)
2011-05-09 23:53:52 +00:00
def should_be_an_error(self, topic):
expect(topic).to_be_an_error()
def should_be_runtime_error(self, topic):
expect(topic).to_be_an_error_like(RuntimeError)
def should_have_nice_error_message(self, topic):
2011-05-10 02:14:48 +00:00
expect(topic).to_have_an_error_message_of('The settings_path argument is required.')
class WithinANoDjangoContext(Vows.Context):
class TheGetUrlMethod(DjangoContext):
def topic(self):
return self.get_url('/')
def should_return_the_same_path(self, topic):
expect(topic).to_equal('/')
class TheHost(DjangoHTTPContext):
def topic(self):
return self.host
def should_return_an_error(self, topic):
expect(topic).to_be_an_error_like(ValueError)
class ThePort(DjangoHTTPContext):
def topic(self):
return self.port
def should_return_an_error(self, topic):
expect(topic).to_be_an_error_like(ValueError)
class WithinAServer(DjangoHTTPContext):
def setup(self):
self.start_server(port=8085)
def should_default_to_one_thread(self,topic):
expect(self.server.thr.server._get_numthreads()).to_equal(1)
class WithinDjangoHTTPContextTheGetUrlMethod(DjangoHTTPContext):
def topic(self):
return self.get_url('http://127.0.0.1:8085/complete_url/')
def when_passed_a_complete_url_should_return_the_url_without_modification(self, topic):
expect(topic).to_equal('http://127.0.0.1:8085/complete_url/')
class InADjangoHTTPContext(DjangoHTTPContext):
def topic(self):
return self.get_url('/')
def the_get_url_should_return_a_well_formed_url(self, topic):
expect(topic).to_equal('http://127.0.0.1:8085/')
class ANoDjangoContext(Vows.Context):
class TheHost(DjangoHTTPContext):
def topic(self):
return self.host
def should_be_equal_to_the_host_in_out_context(self, topic):
expect(topic).to_equal('127.0.0.1')
class ThePort(DjangoHTTPContext):
def topic(self):
return self.port
def should_be_equal_to_the_port_in_out_context(self, topic):
expect(topic).to_equal(8085)
class AnDjangoContext(DjangoContext):
def topic(self):
return self.get_url('/')
def the_get_url_method_should_return_a_well_formed_url(self, topic):
expect(topic).to_equal('http://127.0.0.1:8085/')
class WithinAMultiThreadedServer(DjangoHTTPContext):
def setup(self):
self.start_server(threads=5)
def topic(self):
return self.server
def should_default_to_one_thread(self,topic):
expect(topic.thr.server._get_numthreads()).to_equal(5)