GithubHelp home page GithubHelp logo

nitr0man / tddspry Goto Github PK

View Code? Open in Web Editor NEW

This project forked from meako689/tddspry

0.0 2.0 0.0 410 KB

Collection of testcases and helpers to test Django projects and applications with nose and twill libraries.

Home Page: http://playpauseandstop.github.com/tddspry/

License: BSD 3-Clause "New" or "Revised" License

Makefile 1.90% Python 93.23% Shell 0.25% HTML 4.63%

tddspry's Introduction

tddspry

Collection of testcases and helpers to test Django projects and applications with nose and twill libraries.

  1. Key features
  2. Quick examples
    1. Writing tests
    2. Running tests
  3. Requirements
  4. Installation
  5. License
  6. Documentation
  7. Sending bugs and feature requests
  8. Contacts

Key features

  • Support of assert methods from unittest2 library (assertIn, assertIs and others).
  • Full support of all features from django.test.TestCase or django.test.TransationalTestCase classes.
  • Run tests for Django projects and applications via nosetests command instead of python manage.py test. You don't need to place tests in tests module - nosetests automaticly find its in project or application.
  • Assert methods for testing Django models (assert_create, assert_count, etc).
  • Test web responses with twill library instead of using django.test.Client.
  • Helpers for make particular actions in tests (create users or superusers, login or logout from projects).

Quick examples

Writing tests

Database test

Check that username field of standart auth.User model is unique:

from tddspry.django import TestCase

from django.contrib.auth.models import User


TEST_EMAIL = '[email protected]'
TEST_PASSWORD = 'test-password'
TEST_USERNAME = 'test-username'


class TestUserModel(TestCase):

    def test_unique(self):
        self.assert_create(User,
                           username=TEST_USERNAME,
                           password=TEST_PASSWORD,
                           email=TEST_EMAIL)
        self.assert_raises(Exception,
                           self.assert_create,
                           User,
                           username=TEST_USERNAME,
                           password=TEST_PASSWORD,
                           email=TEST_EMAIL)

Http (twill) test

Login into project and check that login url does not exist in index page and logout and profile links exist:

from tddspry.django import TestCase


class TestHttp(TestCase):

    def setup(self):
        # Create user
        self.user = self.helper('create_user')

        # Login this user into project
        self.login(self.helpers.USERNAME, self.helpers.PASSWORD)

    def test_index_links(self):
        # Login, logout and profile urls
        login_url = self.build_url('auth_login')
        logout_url = self.build_url('auth_logout')
        profile_url = self.build_url('auth_profile')

        # Go to index page
        self.go200('/')

        # Login url does not exist cause user already logged in
        self.notfind(login_url)

        # But logout and profile url exist
        # Profile url must find at page 3 times
        self.find(logout_url)
        self.find(profile_url, count=3)

Running tests

There are three ways to run tests in your project.

First, using nosetests command, e.g.:

$ nosetests --with-django --django-settings=project.settings project
$ DJANGO_SETTINGS_MODULE=project.settings NOSE_WTIH_DJANGO=1 nosetests project

This way requires install tddspry to your system.

Second, using django-nosetests.py script, e.g.:

$ django-nosetests.py --django-settings=project.settings project
$ DJANGO_SETTINGS_MODULE=project.settings django-nosetests.py project

This script is wrapper to previous method (you don't need to run nosetests with --with-django option or NOSE_WTIH_DJANGO environment var), but does not require install tddspry to your system (it's good idea if you want use latest development version of tddspry). Script located in bin/ directory.

Third, using TEST_RUNNER setting in Django >= 1.2 (requires django-nose app installed):

TEST_RUNNER = 'tddspry.django.runner.TestSuiteRunner'

Then you can use Django's internal test manage command to run your tests:

$ ./manage.py test

Otherwise, you can use all power of nosetests command to run tests in your Django project or applications.

Requirements

Installation

On most UNIX-like systems, you'll probably need to run these commands as root or using sudo.

To install use:

$ pip install tddspry

Or:

$ python setup.py install

Also, you can retrieve fresh version of tddspry from GitHub:

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

and place tddspry directory somewhere to PYTHONPATH (or sys.path).

License

tddspry is licensed under the BSD License.

Documentation

Sphinx-generated documentation for tddspry located at GitHub pages. This documentation updates after every tddspry release.

Fresh documentation always can access in docs/ directory.

Sending bugs and feature requests

Found a bug? Have a good idea for improving tddspry? Head over to tddspry's trac to create a new ticket or to GitHub to create a new fork.

Contacts

Authors:Igor Davydenko < playpauseandstop [at] gmail >, Volodymyr Hotsyk < gotsyk [at] gmail >
Idea:Andriy Khavryuchenko < akhavr [at] gmail >

tddspry's People

Contributors

dgladkov avatar meako689 avatar nitr0man avatar playpauseandstop avatar t0ster avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.