Python wagtail testing














































Python wagtail testing



  In the previous article we have discuss about Basic Block in which i have discuss what are the different type of Basic Block.If you have not gone through it you see through this link Basic Block . In this article will start a new topic that how we can test our wagtail site in which we will discuss about various method involved in it.  


 In this article we will learn how we can test our wagtail site

  1. WagtailPageTests

  • class wagtail.tests.utils.WagtailPageTests
           WagtailPageTests  extends django.test.TestCase   adding a few new assert methods.
from wagtail.tests.utils import WagtailPageTests
from myapp.models import MyPage

class MyPageTests(WagtailPageTests):
def test_can_create_a_page(self):
...
You can extend this class and make use of the following methods:

  • assertCanCreateAt(parent_modelchild_modelmsg=None)
def test_cant_create_under_event_page(self):
# You can not create a ContentPage under an EventPage
self.assertCanNotCreateAt(EventPage, ContentPage)
  • assertCanCreate(parentchild_modeldatamsg=None)
    from wagtail.tests.utils.form_data import nested_form_data, streamfield

    def test_can_create_content_page(self):
    # Get the HomePage
    root_page = HomePage.objects.get(pk=2)

    # Assert that a ContentPage can be made here, with this POST data
    self.assertCanCreate(root_page, ContentPage, nested_form_data({
    'title': 'About us',
    'body': streamfield([
    ('text', 'Lorem ipsum dolor sit amet'),
    ])
    1. }))
    
  • assertAllowedParentPageTypes(child_modelparent_modelsmsg=None)
def test_content_page_parent_pages(self):
# A ContentPage can only be created under a HomePage
# or another ContentPage
self.assertAllowedParentPageTypes(
ContentPage, {HomePage, ContentPage})

# An EventPage can only be created under an EventIndex
self.assertAllowedParentPageTypes(
EventPage, {EventIndex})
assertAllowedSubpageTypes(parent_modelchild_modelsmsg=None)
def test_content_page_subpages(self):
# A ContentPage can only have other ContentPage children
self.assertAllowedSubpageTypes(
ContentPage, {ContentPage})

# A HomePage can have ContentPage and EventIndex children
self.assertAllowedParentPageTypes(
HomePage, {ContentPage, EventIndex}

   2.Form data helpers

  • wagtail.tests.utils.form_data.nested_form_data(data)

nested_form_data({
'foo': 'bar',
'parent': {
'child': 'field',
},
})
# Returns: {'foo': 'bar', 'parent-child': 'field'}
  • wagtail.tests.utils.form_data.rich_text(valueeditor='default'features=None)
self.assertCanCreate(root_page, ContentPage, nested_form_data({
'title': 'About us',
'body': rich_text('<p>Lorem ipsum dolor sit amet</p>'),
}))
  • wagtail.tests.utils.form_data.streamfield(items)
    nested_form_data({'content': streamfield([
    ('text', 'Hello, world'),
    ])})
    # Returns:
    # {
    # 'content-count': '1',
    # 'content-0-type': 'text',
    # 'content-0-value': 'Hello, world',
    # 'content-0-order': '0',
    # 'content-0-deleted': '',
  • wagtail.tests.utils.form_data.inline_formset(itemsinitial=0min=0max=1000)

nested_form_data({'lines': inline_formset([
{'text': 'Hello'},
{'text': 'World'},
])})
# Returns:
# {
# 'lines-TOTAL_FORMS': '2',
# 'lines-INITIAL_FORMS': '0',
# 'lines-MIN_NUM_FORMS': '0',
# 'lines-MAX_NUM_FORMS': '1000',
# 'lines-0-text': 'Hello',
# 'lines-0-ORDER': '0',
# 'lines-0-DELETE': '',
# 'lines-1-text': 'World',
# 'lines-1-ORDER': '1',
# 'lines-1-DELETE': '',
# }





More Articles of SAYENDEEP MAHANTY:

Name Views Likes
C++ Exception Handling-|| 85 3
C++ Exception Handling 116 3
C++ File Handling EOF 93 5
C++ File Handling Error Handling During file Operation 1135 5
C++ File Handling seekp() Function 105 5
C++ File Handling seekg() Function 105 6
C++ File Handling tellg() Function 127 5
C++ File Handling tellp() Function 133 5
C++ File Handling close() Function 78 5
C++ File Handling:: open() 106 5
C++ File Handling Introduction 131 5
C++ Container Library:: std ::array-II 101 4
Top Django Interview Questions and Answers You Need to Know 302 6
C++ Container Library::std::array 96 6
C++ Container Library Introduction 103 5
Essential Engineering Skills for Your Resume 127 5
Mistakes To Avoid During Technical Interview 133 5
Mistakes You Must Avoid During Work From Home 178 6
Seven Common Mistakes that Beginners Should Avoid While Learning to Code 109 6
Simple Linear Regression 96 6
Python wagtailmenus 122 6
Python wagtail application 119 6
Python guppy GSL 136 5
Python wagtail guppy subpackage heapy 174 6
Python guppy Introduction 215 6
Python wagtail Structural Block 258 6
Python wagtail Integrating into Django Project 370 6
Python wagtail testing 281 7
Python wagtail Basic Block 349 7
Python wagtail image tag 216 7
Python wagtail Templates 179 6
Python wagtail Backends 206 6
Python wagtail Indexing 190 6
Python wagtail Search 173 7
Python wagtail Snippets 192 6
Python wagtail Writing your own page models 165 9
Python wagtail model class PageRevision 196 10
Python wagtail model class Site 199 9
Python wagtail wagtail core model 219 9
Python wagtail page models 189 10
Python wagtail 166 11

Comments