장고를 사용하여 장고에서 단위 테스트를 설정하려고합니다. ,django unit test with fixtures - 객체 일치 쿼리가 없습니다.
DoesNotExist: BlogIndexPage matching query does not exist.
여기 테스트 (필자는 할미새 CMS를 사용하고 내 코드입니다 :
나는 성공적으로 내 비품을로드 할 수 있습니다,하지만 난 그들로부터 데이터를 검색 할 때 나는 오류
class BlogTests(WagtailPageTests):
fixtures = ['demosite.json']
def test_can_create_blog_entry(self):
blog_index_page = BlogIndexPage.objects.get(pk=5)
self.assertCanCreate(blog_index_page, BlogPage, {
'title': 'Post 2',
'date': '2017-10-11',
'intro': 'Post 2',
'body': '<p>Test Post</p>'
})
을 그리고 이것은 내 고정물입니다 :하는) a few additional methods와 유닛 테스트 확장
[
{
"pk": 1,
"model": "wagtailcore.page",
"fields": {
"title": "Root",
"draft_title": "Root",
"numchild": 1,
"show_in_menus": false,
"live": true,
"seo_title": "",
"depth": 1,
"search_description": "",
"content_type": [
"wagtailcore",
"page"
],
"has_unpublished_changes": false,
"owner": null,
"path": "0001",
"url_path": "/",
"slug": "root"
}
},
{
"pk": 2,
"model": "wagtailcore.page",
"fields": {
"title": "Home page",
"draft_title": "Home page",
"numchild": 5,
"show_in_menus": true,
"live": true,
"seo_title": "",
"depth": 2,
"search_description": "",
"content_type": [
"home",
"homepage"
],
"has_unpublished_changes": false,
"owner": null,
"path": "00010002",
"url_path": "/home-page/",
"slug": "home-page"
}
},
{
"pk": 5,
"model": "wagtailcore.page",
"fields": {
"title": "Blog index",
"draft_title": "Blog index",
"numchild": 3,
"show_in_menus": true,
"live": true,
"seo_title": "",
"depth": 3,
"search_description": "",
"content_type": [
"blog",
"blogindexpage"
],
"has_unpublished_changes": false,
"owner": null,
"path": "000100020002",
"url_path": "/blog/",
"slug": "blog"
}
},
{
"pk": 16,
"model": "wagtailcore.page",
"fields": {
"title": "Blog post",
"draft_title": "Blog post",
"numchild": 0,
"show_in_menus": false,
"live": true,
"seo_title": "",
"depth": 4,
"search_description": "The origin of the genus appears to be in the general area of Eastern Siberia/Mongolia. Wagtails spread rapidly across Eurasia and dispersed to Africa in the Zanclean (Early Pliocene) where the sub-Saharan lineage was later isolated. The African Pied Wagtail (and possibly the Mekong Wagtail) diverged prior to the massive radiation of the white-bellied black-throated and most yellow-bellied forms, all of which took place during the late Piacenzian (early Late Pliocene), c. 3 mya.",
"content_type": [
"blog",
"blogpage"
],
"has_unpublished_changes": false,
"owner": null,
"path": "0001000200020001",
"url_path": "/home-page/blog-index/blog-post/",
"slug": "blog-post"
}
}
]
기본적으로 나는 단지 블로그 색인 페이지를 잡고 그 밑에 블로그 페이지 (블로그 게시물)를 만들 수 있는지 테스트하려고합니다. 내가 도대체 뭘 잘못하고있는 겁니까?
실제로 'BlogIndexPage'모델을 쿼리하고 있습니다. 그러나 픽스처에는'Page' 모델이 포함됩니다. 가장 가능성있는 것은 'from wagtailcore.models import page' 명령을 사용하여 해당 모델을 가져올 수 있다는 것입니다. – raratiru