我有一个基于类的视图
class HomePage(View):
def get(self, request):
return HttpResponse('<p>This is content.</p>')
和 url-pattern 定义如下:
urlpatterns = patterns('',
url(r'^$', HomePage.as_view()),
)
为了将此模式解析为当前视图功能,我编写了如下测试:
class HomePageTest(TestCase):
def test_root_url_resolves_to_home_page_view(self):
found = resolve('/')
self.assertIsInstance(found.func, HomePage)
通过运行此单元测试,我收到以下错误:
self.assertIsInstance(found.func, HomePage)
AssertionError: <function HomePage at 0x7f85dd2c7840> is not an instance of <class 'web.views.HomePage'>
任何想法如何测试这个案例?