9 Home
rafaelcaricio edited this page 2011-08-23 11:51:27 -07:00

Django-Pyvows

Pyvows

pyvows is a BDD (Behaviour Driven Development) inspired by Vows for node.js

More documentation about pyvows can be found at the project homepage

http://pyvows.org

Django-Pyvows

This project contains extensions to test Django projects under pyVows.

Using Django-Pyvows

There is no need to modify your project to use Django-PyVows. You only have to create the vows as you usually would, start the server and call your project urls:

from pyvows import Vows, expect

from django_pyvows.context import DjangoHTTPContext

@Vows.batch
class ContextTest(DjangoHTTPContext):

    def get_settings(self):
        return "project.settings"

    def setup(self):
        self.start_server()

    def topic(self):
        return self.get('/mygreaturl/')

    def should_be_a_success(self, topic):
        expect(topic.getcode()).to_equal(200)

    def should_return_the_correct_response_type(self, topic):
        expect(topic.headers.type).to_equal("text/html")

To work you only need to override the get_settings method from DjangoHTTPContext to return the path of your settings module. The default get_settings returns "settings".

You can start more than one server with different configurations that you can specify. Like this:

from pyvows import Vows, expect

from django_pyvows import DjangoContext, DjangoHTTPContext

@Vows.batch
class ContextTest(DjangoContext):
   
    class InDebugMode(DjangoHTTPContext):

         def setup(self):
             self.settings["DEBUG"] = True
             self.start_server(port=8081)

         def topic(self):
             return self.get("/homepage/")

         def should_be_ok(self, topic):
             expect(topic.msg).to_equal("OK")

     class NotInDebugMode(DjangoHTTPContext):
         
         def setup(self):
             self.settings["DEBUG"] = False
             self.start_server(port=8082)

         def topic(self):
             return self.get("/homepage/")

         def should_be_ok(self, topic):
             expect(topic.msg).to_equal("OK")