﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
20456	Easier unit testing for class-based views	Benoît Bryon	Felipe Lee	"When django users create class-based views, they create custom code. Testing this code matters. Writing unit tests for the custom code (and only for the custom code) is important.

As of Django 1.5, the easiest way to test class-based views is using the builtin test client. But it performs integration tests, i.e. involves middlewares, URL resolvers, decorators...
It is also quite easy to use django.test.RequestFactory and as_view() classmethod. But, since as_view() returns a function, the tests can only check the response. It means the class-based views are tested as a system.

It seems that writing unit tests is possible, i.e. we can write unit tests for class-based views methods.
There is at least one technique which was presented at DjangoCon Europe 2013 Warsaw:

* http://tech.novapost.fr/static/images/slides/djangocon-europe-2013-unit-test-class-based-views.html
* http://tech.novapost.fr/django-unit-test-your-views-en.html

The recipe mentioned above seems to work (to be confirmed). But wouldn't be better if the recipe was documented in Django's documentation (https://docs.djangoproject.com/en/1.5/topics/testing/advanced/ I guess) and tools (setup_view) were builtin Django?

Note: perhaps, it would be even better if setup_view() is not a standalone function but is a method of View class. Something like as_view(), but which returns an instance."	New feature	closed	Testing framework	dev	Normal	fixed	cbv test	bmispelon@… marc.tamlyn@… Rémy Hubscher unai@… Sergey Fedoseev	Ready for checkin	1	0	0	0	0	0
