I'm adding unit tests to my blog and I can not pass the test that should happen .
The test is this:
from django.test import TestCase
from django.urls import resolve
from apps.blog.views import EntryList
class ApiRootTest(TestCase):
def test_la_portada_apunta_a_entrylist_view(self):
found = resolve('/')
self.assertEqual(found.func, EntryList.as_view())
It's very simple, I want to prove that the root points to the CBV EntryList, which is more or less like this:
from django.views.generic import ListView
from apps.blog.models import Entry
class EntryList(ListView):
model = Entry
And in the file urls.py
the root points to that class:
from django.conf.urls import url
urlpatterns = [
url(r'^$', EntryList.as_view(), name='index')
]
When executing the east, I get this error:
$ python manage.py test
Creating test database for alias 'default'...
System check identified no issues (0 silenced).
F
======================================================================
FAIL: test_la_portada_apunta_a_entrylist_view (src.apps.blog.tests.ApiRootTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Volumes/datos/Proyectos/nspaces/src/apps/blog/tests.py", line 11, in test_la_portada_apunta_a_entrylist_view
self.assertEqual(found.func, EntryList.as_view())
AssertionError: <function EntryList at 0x11010dd08> != <function EntryList at 0x10fe1dea0>
----------------------------------------------------------------------
Ran 1 test in 0.004s
I do not understand why two instances of class EntryList
are created, instead of just one, which would make my test pass OK.
What changes should I make to pass the unit test?
Plus: What am I doing wrong?