Skip to content

Instantly share code, notes, and snippets.

@jarodreyes
Last active April 8, 2016 12:13
Show Gist options
  • Save jarodreyes/225b6048d54fadd516113da859371b37 to your computer and use it in GitHub Desktop.
Save jarodreyes/225b6048d54fadd516113da859371b37 to your computer and use it in GitHub Desktop.
Wagtail Unit Test - Template tag
def test_subnav_use_root_menu(self):
# Arrange
api_reference = Page.objects.get(url_path='/docs/api/')
lookups = Page.objects.get(url_path='/docs/api/lookups/')
mock_context = {'request': 'Request data'}
parent = lookups.get_site().root_page
menuitems = parent.get_children().live().in_menu()
# Act
nav_data = subnav(mock_context, lookups)
# Assert
self.assertEqual(nav_data['calling_page'], lookups)
self.assertEqual(len(nav_data['menuitems']), len(menuitems))
self.assertEqual(nav_data['section_index'], api_reference.specific)
self.assertEqual(nav_data['request'], 'Request data')
{
"model": "wagtailcore.site",
"fields": {
"hostname": "localhost",
"port": 80,
"site_name": "My Wagtail Site",
"root_page": 3,
"is_default_site": true
}
},
{
"model": "wagtailcore.page",
"pk": 1,
"fields": {
"path": "0001",
"depth": 1,
"numchild": 1,
"title": "Root",
"slug": "root",
"content_type": [
"wagtailcore",
"page"
],
"live": true,
"has_unpublished_changes": false,
"url_path": "/",
"owner": null,
"seo_title": "",
"show_in_menus": false,
"search_description": "",
"go_live_at": null,
"expire_at": null,
"expired": false,
"locked": false,
"first_published_at": null,
"latest_revision_created_at": null
}
},
{
"model": "wagtailcore.page",
"pk": 3,
"fields": {
"path": "00010002",
"depth": 2,
"numchild": 1,
"title": "My Blog",
"slug": "blog",
"content_type": [
"blog",
"blogpage"
],
"live": true,
"has_unpublished_changes": false,
"url_path": "/blog/",
"owner": [
"admin"
],
"seo_title": "",
"show_in_menus": true,
"search_description": "",
"go_live_at": null,
"expire_at": null,
"expired": false,
"locked": false,
"first_published_at": "2016-01-28T00:05:51.221Z",
"latest_revision_created_at": "2016-01-28T00:05:51.145Z"
}
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment