#NEWLINE# def assertCanCreate( self , parent , child_model , data , msg = None ) : #NEWLINE# #INDENT# '\n        Assert that a child of the given Page type can be created under the\n        parent, using the supplied POST data.\n\n        ``parent`` should be a Page instance, and ``child_model`` should be a\n        Page subclass. ``data`` should be a dict that will be POSTed at the\n        Wagtail admin Page creation method.\n        ' #NEWLINE# self . assertCanCreateAt ( parent . specific_class , child_model ) #NEWLINE# if ( ( 'slug' not in data ) and ( 'title' in data ) ) : #NEWLINE# #INDENT# data [ 'slug' ] = slugify ( data [ 'title' ] ) #NEWLINE# #UNINDENT# data [ 'action-publish' ] = 'action-publish' #NEWLINE# add_url = reverse ( 'wagtailadmin_pages:add' , args = [ child_model . _meta . app_label , child_model . _meta . model_name , parent . pk ] ) #NEWLINE# response = self . client . post ( add_url , data , follow = True ) #NEWLINE# if ( response . status_code != 200 ) : #NEWLINE# #INDENT# msg = self . _formatMessage ( msg , ( 'Creating a %s.%s returned a %d' % ( child_model . _meta . app_label , child_model . _meta . model_name , response . status_code ) ) ) #NEWLINE# raise self . failureException ( msg ) #NEWLINE# #UNINDENT# if ( response . redirect_chain == [ ] ) : #NEWLINE# #INDENT# if ( 'form' not in response . context ) : #NEWLINE# #INDENT# msg = self . _formatMessage ( msg , 'Creating a page failed unusually' ) #NEWLINE# raise self . failureException ( msg ) #NEWLINE# #UNINDENT# form = response . context [ 'form' ] #NEWLINE# if ( not form . errors ) : #NEWLINE# #INDENT# msg = self . _formatMessage ( msg , 'Creating a page failed for an unknown reason' ) #NEWLINE# raise self . failureException ( msg ) #NEWLINE# #UNINDENT# errors = '\n' . join ( ( ( '  %s:\n    %s' % ( field , '\n    ' . join ( errors ) ) ) for ( field , errors ) in sorted ( form . errors . items ( ) ) ) ) #NEWLINE# msg = self . _formatMessage ( msg , ( 'Validation errors found when creating a %s.%s:\n%s' % ( child_model . _meta . app_label , child_model . _meta . model_name , errors ) ) ) #NEWLINE# raise self . failureException ( msg ) #NEWLINE# #UNINDENT# if ( django . VERSION >= ( 1 , 9 ) ) : #NEWLINE# #INDENT# explore_url = reverse ( 'wagtailadmin_explore' , args = [ parent . pk ] ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# explore_url = ( 'http://testserver' + reverse ( 'wagtailadmin_explore' , args = [ parent . pk ] ) ) #NEWLINE# #UNINDENT# if ( response . redirect_chain != [ ( explore_url , 302 ) ] ) : #NEWLINE# #INDENT# msg = self . _formatMessage ( msg , ( 'Creating a page %s.%s didnt redirect the user to the explorer, but to %s' % ( child_model . _meta . app_label , child_model . _meta . model_name , response . redirect_chain ) ) ) #NEWLINE# raise self . failureException ( msg )