skip to navigation
skip to content

tddspry 0.2

Utilities to test Django applications with nosetests.

Downloads ↓

Latest Version: 0.4-beta

  1. Introduction
  2. Requirements
  3. Installation
  4. Usage

Introduction

tddspry is collection of utilities for testing Django applications with nosetests library.

Requirements

Installation

To install:

python setup.py install

Or via easy_install:

easy_install tddspry

Also you can retrieve fresh version of tddspry from GitHub:

git clone git://github.com/playpauseandstop/tddspry.git

Usage

We create tddspry to easying testing Django projects and applications. Okay, let's see, to test login and logout pages in your Django project, you need only:

from tddspry.django import HttpTestCase
from tddspry.django.helpers import create_user

from django.conf import settings


class TestLoginPage(HttpTestCase):

    def test_login(self):
        user = create_user('username', 'password')
        self.login('username', 'password')
        self.url(settings.LOGIN_REDIRECT_URL)

    def test_logout(self):
        user = create_user('username', 'password')
        self.login('username', 'password')
        self.logout()
        self.url('/')

That's all ;) But really for test_login,

  • First, HttpTestCase creates test sqlite3 database in memory and starts Django WSGI-server.
  • Then, we creates test user by create_user helper.
  • Next, twill browser goes to your 'auth_login' page and checks that response code is 200.
  • Next, twill browser fill out login form with USERNAME and PASSWORD values and submits it. Also here twill browser again checks that response code is 200.
  • And finally, we check that current url after success login is our LOGIN_REDIRECT_URL that set in projects settings.

And for test_logout we repeate these steps and adding logging out from current Django session and simple check that after logout we go to index page.

Easy? No? Okay, create new issue on GitHub and say how exactly create easy tests for Django applications :)

ps. More examples how-to usage tddspry exist in tests for testproject project in tddspry repository.

 
File Type Py Version Uploaded on Size # downloads
tddspry-0.2.tar.gz (md5) Source 2009-04-24 7KB 356