test driven development and mixin for views

34 views
Skip to first unread message

Sven

unread,
Jan 5, 2014, 1:31:30 PM1/5/14
to django...@googlegroups.com
Hi Folks,

i recently wrote some small mixins that are intented to be attached to CBV
like ListView, UpdateView, DetailView or even CreateView. The aim is to give
users only access to their data. Their in terms of ownership. As an Example
you have a Post model were a field called owner is a ForeignKey to 'auth.User'
as a basic example.

So the mixin does filtering the queryset and passes an additional parameter to
form classes where as an additional form Mixin then passes this down to the
model. So far so good. (see http://pastebin.kde.org/pyzrouxfw)

Now my Question:

what would be the best solution to write a dedicated test against this mixin?
Would it be good or worth to create some Views loke the 4 above that inherits
also the Mixin and then test against this as a complete behaviour? Or better
mock it somehow differently?

I really appreaciate your suggestions!!


--


Best Regards

Sven

trojactory

unread,
Jan 6, 2014, 5:08:29 AM1/6/14
to django...@googlegroups.com
Hi sassman,

Since you mentioned TDD, I assume you are talking about unit tests. As with any matter in quality control, the more you can test, the better! 

In my opinion, you would need to provide atleast one testcase for each of the four CBV views. It is better to create a derived class in each case rather than mocking it.

Regards,
Arun

Sven

unread,
Jan 6, 2014, 7:37:02 AM1/6/14
to django...@googlegroups.com, trojactory
Hi Arun,

thanks for this advice. I finally came also to the conclusion that the best
test would be to create (as part of each test case) all possible use case
szenarios for this mixin class. For instance if it should be utilizable for
ListView and CreateView then i would create unit tests against those 2 classes
with an inheritance of that mixin. This should be the only way to quarantee
the correct behavior of the mixin within a given use case.

If someone would use the mixin outside of this, let's say for DetailView and
this was not explicit tested then there is no gurantee that it will still
behave as expected. That should be fair enought.

Thanks,
Sven
> > Best Regards
> >
> > Sven
--


Best Regards,
Sven

Reply all
Reply to author
Forward
0 new messages