【发布时间】:2015-02-03 21:56:35
【问题描述】:
我有一个基于类的视图
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'>
知道如何测试这个案例吗?
【问题讨论】:
标签: django django-views python-unittest django-unittest