• Stars
    star
    145
  • Rank 254,144 (Top 6 %)
  • Language
    Python
  • License
    MIT License
  • Created about 16 years ago
  • Updated about 13 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A set of custom assertions and examples for use testing django applications

PyUnit provides a basic set of assertions which can get you started with unit testing python, but it’s always useful to have more. Django also has a few specific requirements and common patterns when it comes to testing. This set of classes aims to provide a useful starting point for both these situations.

The application also overrides the default Django test runner, adding a few useful features:

Installation

Just add the project to your INSTALLED_APPS.

INSTALLED_APPS = (
	'test_extensions',
)

Note that this application steals the test command from django, overriding it with extra toys. If another application in your INSTALLED_APPS does this too then the last one in the list will win. South migrations does this in order to use the django syncdb command for testing, which test_extensions does too. As of 0.4 test_extensions works with South, just as long as you include it after south in the list of installed apps.

Assertions

See the examples directory in the src/test_extensions directory for details of a large number of useful assertions for testing django apps:

  • assert_response_contains
  • assert_response_doesnt_contain
  • assert_regex_contains
  • assert_render_matches
  • assert_code
  • assert_render
  • assert_render_matches
  • assert_doesnt_render
  • assert_render_contains
  • assert_render_doesnt_contain

Test Runners

XMLUnit

Sometimes it’s nice to have a file reporting the results of a test run. Some applications such as CruiseControl can use this to display the results in a user interface.

python manage.py test --xml

Code Coverage

If you want to know what code is being run when you run your test suite then codecoverage is for you. These two flags use two different third party libraries to calculate coverage statistics. The first dumps the results to stdout, —xmlcoverage creates a cobertura-compatible xml output, and the last one creates a series of files displaying the results.

python manage.py test --coverage
python manage.py test --xmlcoverage
python manage.py test --figleaf

No Database

Sometimes your don’t want the overhead of setting up a database during testing, probably because your application just doesn’t use it.

python manage.py test --nodb
python manage.py test --nodb --coverage
python manage.py test --nodb --xmlcoverage

WARNING Don’t use this if you use the ORM in your app. An outstanding issue means that you can get into trouble. Your tests will still hit the database, but it will be your non test data.

Local Continuous Integration Command

Thanks to Roberto Aguilar (http://github.com/rca) for providing a auto-reloading version of the test runner. Run the runtester command and it should run your test suite whenever you change a file (similar to how runserver reloads the server each time you change something.)

See this thread
from the Django Developer list of more information and discussion.

python manage.py runtester

Licence

XMLUnit is included out of convenience. It was written by Marc-Elian Begin <[email protected]> and is Copyright © Members of the EGEE Collaboration. 2004. http://www.eu-egee.org

The rest of the code is licensed under an MIT license:

Copyright © 2008 Gareth Rushgrove <[email protected]>

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the “Software”), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

More Repositories

1

vagrantboxes-heroku

Repository for http://www.vagrantbox.es
1,281
star
2

garethr-docker

Puppet module for managing docker
Ruby
397
star
3

puppet-module-skeleton

A pretty opinionated skeleton for writing your own puppet modules
HTML
312
star
4

kubetest

Write unit tests for your Kubernetes configurations
Go
310
star
5

kubernetes-json-schema

A set of JSON schemas for various Kubernetes versions, extracted from the OpenAPI definitions
250
star
6

pentesting-playground

Code for installing various security minded tools onto Vagrant powered virtual machines
Puppet
172
star
7

django-timelog

Performance logging middlware and analysis tools for Django
Python
152
star
8

serf-master

A small python framework for writing Serf handlers
Python
126
star
9

django-project-templates

A set of Paster templates for Django projects, including a fabric deployment script
Python
124
star
10

multi-stage-build-example

Example repository to accompany my talk at Velocity 2018
Makefile
119
star
11

logstash-patterns

A collection of grok patterns for use with logstash
Ruby
98
star
12

cloth

EC2 tasks for Fabric
Python
97
star
13

packer-serverspec-example

Using Serverspec tests to verify images built using Packer
Ruby
96
star
14

prodder

An opinionated test suite focused on generally applicable web application security rules
Ruby
94
star
15

docker-label-inspector

Docker Label Inspector is a tool to help ensure you're providing your Docker images with the metadata they will need out in the wilds of the internet.
Python
80
star
16

ansible-provisioner

A Digital Ocean specific provisioning and orchestration tool built around Ansible
Python
76
star
17

zapr

Easy to use command line security scanner
Ruby
59
star
18

appengine-image-host

Simple image resizing and hosting application
Python
45
star
19

hiera-etcd

A hiera backend for use with the etcd distributed configuration store
Ruby
44
star
20

policykit

A set of utilities and classes for working with Open Policy Agent based tools, including Gatekeeper and Conftest
Python
39
star
21

ruby-vagrantboxes

Ruby gem for interacting with the vagrantbox.es api from inside vagrant
Ruby
37
star
22

riemann-vagrant

A vagrantfile and puppet setup to get playing with Riemann quickly
Ruby
37
star
23

packages

Scripts for building and maintaining a debian package repository using Vagrant
CSS
37
star
24

kubernetes-webhook-examples

Python examples of mutating and validating kubernetes webhook admission controllers
Python
36
star
25

puppet-docker-example

An example of using the Puppet Docker module to manage containers, including Consul for service discovery
Ruby
35
star
26

Asteroid

A simple web interface for running scripts and recording the results
Python
35
star
27

django-clue

A collection of useful development middleware for Django packaged under a custom runserver command
Python
33
star
28

garethr-key_value_config

Puppet type and providers for managing configuration in key/value stores
Ruby
30
star
29

puppet-docker-swarm-example

An example using Puppet to launch a Swarm cluster using Consul
Ruby
30
star
30

sinatra-hello-world

A Hello World style application demonstrating the Sinatra Ruby framework
Ruby
28
star
31

garethr-kubernetes

Puppet types and provider for managing Pods, ReplicationControllers, Services and more in Kubernetes
Ruby
28
star
32

appengine-imified

Example of providing an Instant Messaging interface to App Engine application
Python
24
star
33

web-puppet

A tiny ruby rack application which exposes the data from puppet as JSON over HTTP
Ruby
23
star
34

openshift-json-schema

A set of JSON schemas for various OpenShift versions, extracted from the OpenAPI definitions
Shell
23
star
35

django-googlecalendar

A Django application which provides a front end to one or more Google Calendars
23
star
36

capistrano-puppet

Get capistrano hosts from puppet
Ruby
21
star
37

bolt

A script runner
Ruby
19
star
38

localbuilder

Python script for monitoring a given directory for changes and running a command when something changes
Python
19
star
39

pycnab

Python library for manipulating Cloud Native Application Bundles
Python
19
star
40

garethr-iaas

Experiment with Puppet types and providers for managing virtual machines from an IaaS
Ruby
17
star
41

appengine-bugs

Super simple issue tracker for Google AppEngine, the code behind GitBug
Python
16
star
42

garethr-riemann

Puppet module for Riemann, published on the Puppet Forge
Ruby
16
star
43

snyk-sbom-examples

Examples of using Snyk's SBOM APIs.
Python
15
star
44

sensu-playground

A demo of a vagrant powered multi-node sensu setup, using the sensu puppet module
Puppet
15
star
45

docker-app-cnab-examples

Examples originally for the KubeCon workshop at Microsoft Reactor
Makefile
14
star
46

appengine-uptime

site monitoring utility hosted on Google App Engine
Python
14
star
47

helm-travis-testing-example

Smarty
14
star
48

kubernetes-tools

Python
13
star
49

devopsweekly

Content for the Devops Weekly site
HTML
12
star
50

snyky

A known vulnerable Flask app with an excessive amount of automated testing
Open Policy Agent
12
star
51

tk-demo-puppet

A working example of using Test Kitchen for integration testing of puppet manifests and modules
Ruby
12
star
52

librarian-puppet-vagrant

Vagrant middleware to run librarian puppet before each vagrant up and vagrant provision
Ruby
12
star
53

jenkins-build-list

A very simple Clojure/Noir application which hits the Jenkins API and lists recent builds for a particular job.
Clojure
12
star
54

docker-spec-example

An example of testing docker image builds
Ruby
12
star
55

snyk-tekton

A set of Tekton Tasks for using Snyk to check for vulnerabilities in your pipelines
HTML
11
star
56

booky

script to build compile a book from text file
Python
11
star
57

puppet-swagger-generator

Generate Puppet types and providers from Swagger specifications
Ruby
11
star
58

snykctl

A CLI tool for interacting with the Snyk API.
Crystal
11
star
59

appengine-queue

Simple Queue for App Engine
Python
10
star
60

garethr-kibana

Puppet module to install and configure the kibana logstash interface
Puppet
10
star
61

nginx-json-proxy

An experiment with openresty, lua and nginx
Nginx
10
star
62

chef-repo

Personal cookbooks
Ruby
10
star
63

appengine-books

AppEngine book listing webservice, web site and admin
Python
10
star
64

vagrant-cucumber-host

Vagrant plugin to run cucumber acceptance tests for Vagrant boxes
Ruby
10
star
65

garethr-diamond

Puppet module for the Diamond stats collection daemon
Ruby
9
star
66

cloud-native-tools

A database of activity around various Cloud Native tools
Makefile
9
star
67

gmetric-web

Simple HTTP interface for adding custom time metrics to Ganglia.
Python
9
star
68

serverspec-puppetdb

Example using PuppetDB to generate Serverspec tests
Ruby
9
star
69

garethr-nginx

A very un-opinionated nginx module for Puppet which focuses on installation and NOT configuration
Ruby
9
star
70

dockerfilepp

Library for writing your own Dockerfile pre-processors
Go
8
star
71

urltest

A simple DSL for writing url based tests for WSGI applications
Python
8
star
72

garethr-graphite

Puppet module for the Graphite monitoring tool
Puppet
8
star
73

snyksh

An interactive shell for exploring the Snyk API
Python
8
star
74

garethr-erlang

Puppet module for managing erlang from official package repository
Ruby
7
star
75

web-facter

Expose facts from Facter as JSON over HTTP
Ruby
7
star
76

findcve

Find CVEs from a list of packages in different formats
Python
7
star
77

dockerfilepp-labels

A dockerfile pre-processor for adding dynamic labels
Go
7
star
78

appengine-seller

Sample App Engine integration with PayPal
Python
7
star
79

epydoc-themes

Application to support alternative stylesheets for epydoc
7
star
80

digitalocean-expect

Experiments in testing an IaaS
Clojure
7
star
81

fixmysite

Like FixMyStreet but for Websites, or like GetSatisfaction but for the UK Government Online
Python
7
star
82

garethr-mirageos

Puppet module to install Mirage and it's dependencies
Ruby
7
star
83

puppet-mesos-example

An example of using Puppet to manage a Mesos, Chronos and Marathon cluster
Ruby
7
star
84

garethr-digitalocean

Puppet module to manage droplets on digitalocean IaaS
Ruby
7
star
85

lastbot

A simple search bot for last.fm created during the last.fm hackday
Python
7
star
86

django-http-debug

Simple HTTP logging server, useful for debugging HTTP clients of various types
Python
6
star
87

garethr-sysdig

Puppet module for installing sysdig
Ruby
6
star
88

inboxer

Putting the web in your inbox
Ruby
6
star
89

appengine-template

Quick start template for App Engine projects based on webapp
6
star
90

puppetdb-expect

Experiment writing tests against data in PuppetDB
Clojure
6
star
91

do-test-kitchen

An example, ideal for a CI environment, of using the Test Kitchen Digital Ocean driver and the new shell provisioner
Ruby
6
star
92

docker-applications

A set of example Docker Apps
6
star
93

django-train

Django blogging application based around generic views, flatpages and tagging
Python
5
star
94

django-linklist

Django application for managing a set of ordered lists of links
Python
5
star
95

knb

Proof-of-concept Knative Build user interface
Python
5
star
96

dockerfilepp-puppet

A small experiment in Dockerfile pre-processing
Makefile
5
star
97

jruby-embedded-jetty

Simple example of creating an executable war file with an embedded jetty
Ruby
5
star
98

graylogtail

Use logtail to push log files into Graylog2
Python
5
star
99

gatling-demo

Simple demo of using Gatling assertions
Scala
5
star
100

nash

Nagios dashboard
Ruby
5
star