1
cat
is an object in python. It doesn’t change unless you explicitly change it. Your database won’t have cat
in it, and your test should be:
self.assertEqual(Category.objects.count(), 0)
But the variable cat
will exist in that scope as you created it nevertheless.
When you test cat.views
, it only check the value of the views
field in the cat
instance that you’ve just created. This has nothing to do with your DB.
0
There are couple of things you could do easily. First point is
-
you could use Positive integer field in Django, if you want only positive integer in this model
-
if you want to do the custom way, please raise an exception or use the assert statement for it. Then in the test case could check whether exception or assertion Error is raised
Source:stackexchange.com