Skip to main content

Utilities to test Django applications with nosetests.

Project description

  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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tddspry-0.2.1.tar.gz (7.2 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page