1
私は次のテストを持っている:解決されたURL関数は、クラスベースのビュー `as_view()`メソッドと等しくありませんか?
def test_root_url_resolves_to_home_page_view(self):
found = resolve('/')
self.assertEqual(
found.func,
views.HomePageView.as_view()
)
は、このエラーを与える:あなたのケースでdjango 2 documentation on testing the response resolver
# class-based views need to be compared by name, as the functions
# generated by as_view() won't be equal
self.assertEqual(response.resolver_match.func.__name__, MyView.as_view().__name__)
あたりとして
AssertionError: <function HomePageView at 0x107d65620> != <function HomePageView at 0x107d97400>
これは、 o ddテストするもの。 'as_view'は毎回新しい呼び出し可能オブジェクトを返し、他の命令オブジェクトがなければidで比較されます。これをテストするのは何ですか? –
これは 'urlpatterns 'をテストする方法であり、正しい' view'を使用しています。これは関数ベースのビューの例で使用されています:https://www.obeythetestinggoat.com/book/chapter_unit_test_first_view.html – surfer190
@ surfer190あなたが共有したページの下部にあるコメントを読むと、これはすでに答えられています。http://www.obeythetestinggoat.com/book/chapter_unit_test_first_view.html#comment-3279904435 –