Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding test methods and utilities for class-based views #11

Merged
merged 8 commits into from
Jul 12, 2015
Merged

Adding test methods and utilities for class-based views #11

merged 8 commits into from
Jul 12, 2015

Conversation

grahamu
Copy link
Contributor

@grahamu grahamu commented Jun 22, 2015

For generic view unit testing, rather than use MyClass.as_view(), CBVTestCase allows instantiation of a generic view class for testing class methods.

Django's generic View.as_view() invokes URL resolvers and middleware, both of which are often not needed for testing class methods. Use CBVTestCase.get_instance() to obtain an initialized instance of your class, then test the class methods as desired.

View.get() and .post() methods are provided for CBVs, and both work with existing django-test-plus TestCase assertion methods.

Sets up and returns an instance of a class-based generic view
without invoking Django's URL resolvers and middleware.

Allows easy testing of custom view methods.
Using class instead of URL name.
instance.head() is set by Django for use by instance.dispatch().
Since this test class assumes you are not using as_view() or dispatch(),
this assignment is not needed.
@grahamu
Copy link
Contributor Author

grahamu commented Jun 23, 2015

Oops, forgot documentation. I'll add that soon.

Fixing 'data' parameter default in CBVTestCase.post().
@grahamu
Copy link
Contributor Author

grahamu commented Jun 23, 2015

For reference, CBVTestCase is based on my personal test suite with substantial input from this post by Benoît Bryon, and this Django pull request by Vincent Prouillet.

@frankwiles frankwiles merged commit 2e33af4 into revsys:master Jul 12, 2015
@grahamu grahamu deleted the cbv branch December 7, 2022 01:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants