@@ -2081,6 +2081,7 @@ def test_collections_field_must_only_display_collections_the_user_is_bound(self)
2081
2081
2082
2082
2083
2083
class IssueBaseFormClassTests (unittest .TestCase ):
2084
+
2084
2085
def test_basic_structure (self ):
2085
2086
issue_form = forms .IssueBaseForm ()
2086
2087
@@ -3919,6 +3920,98 @@ def test_sections_must_not_be_trashed(self):
3919
3920
self .assertRaises (ValueError ,
3920
3921
lambda : form .set ('section' , str (trashed_section .pk )))
3921
3922
3923
+ def test_ADD_issues_with_valid_form_and_invalid_formset_raise_validation_error (self ):
3924
+ """
3925
+ TEST BUG #1018.
3926
+ Is the form submitted, are valid, but, title formset is invalid, the submittion
3927
+ must not raise any exception, only notify the wrong input message to user
3928
+ """
3929
+ perm_issue_change = _makePermission (perm = 'add_issue' ,
3930
+ model = 'issue' , app_label = 'journalmanager' )
3931
+ perm_issue_list = _makePermission (perm = 'list_issue' ,
3932
+ model = 'issue' , app_label = 'journalmanager' )
3933
+ self .user .user_permissions .add (perm_issue_change )
3934
+ self .user .user_permissions .add (perm_issue_list )
3935
+ for t in ['regular' , 'supplement' , 'special' ]:
3936
+ form = self .app .get (reverse ('issue.add_%s' % t ,
3937
+ args = [self .journal .pk ]), user = self .user ).forms ['issue-form' ]
3938
+
3939
+ if t == 'supplement' :
3940
+ form ['number' ] = ''
3941
+ form ['volume' ] = '29'
3942
+ form ['suppl_type' ] = 'volume'
3943
+ form ['suppl_text' ] = 'suppl.X'
3944
+ elif t == 'special' :
3945
+ form ['number' ] = '3'
3946
+ form ['spe_type' ] = 'number'
3947
+ form ['spe_text' ] = 'X'
3948
+ else : # regular
3949
+ form ['number' ] = '3'
3950
+ form ['volume' ] = '29'
3951
+
3952
+ form ['total_documents' ] = '16'
3953
+ form .set ('ctrl_vocabulary' , 'nd' )
3954
+
3955
+ form ['publication_start_month' ] = '9'
3956
+ form ['publication_end_month' ] = '11'
3957
+ form ['publication_year' ] = '2012'
3958
+ form ['is_marked_up' ] = False
3959
+ form ['editorial_standard' ] = 'other'
3960
+ # inline title formset
3961
+ form .set ('title-0-language' , '' )
3962
+ form .set ('title-0-id' , '' )
3963
+ form .set ('title-0-title' , 'La mexicanidad y el neoindianismo hoy' )
3964
+ response = form .submit ()
3965
+ self .assertTrue (response .context ['add_form' ].is_valid ())
3966
+ self .assertFalse (response .context ['titleformset' ].is_valid ())
3967
+ self .assertIn ('There are some errors or missing data.' , response .body )
3968
+
3969
+ def test_EDIT_issues_with_valid_form_and_invalid_formset_raise_validation_error (self ):
3970
+ """
3971
+ TEST BUG #1018.
3972
+ Is the form submitted, are valid, but, title formset is invalid, the submittion
3973
+ must not raise any exception, only notify the wrong input message to user
3974
+ """
3975
+ perm_issue_change = _makePermission (perm = 'add_issue' ,
3976
+ model = 'issue' , app_label = 'journalmanager' )
3977
+ perm_issue_list = _makePermission (perm = 'list_issue' ,
3978
+ model = 'issue' , app_label = 'journalmanager' )
3979
+ self .user .user_permissions .add (perm_issue_change )
3980
+ self .user .user_permissions .add (perm_issue_list )
3981
+ for t in ['regular' , 'supplement' , 'special' ]:
3982
+ issue = modelfactories .IssueFactory (journal = self .journal , suppl_text = '' , type = t )
3983
+ form = self .app .get (reverse ('issue.edit' , args = [self .journal .pk , issue .pk ]), user = self .user ).forms ['issue-form' ]
3984
+
3985
+ if t == 'supplement' :
3986
+ form ['number' ] = ''
3987
+ form ['volume' ] = '29'
3988
+ form ['suppl_type' ] = 'volume'
3989
+ form ['suppl_text' ] = 'suppl.X'
3990
+ elif t == 'special' :
3991
+ form ['number' ] = '3'
3992
+ form ['spe_type' ] = 'number'
3993
+ form ['spe_text' ] = 'X'
3994
+ else : # regular
3995
+ form ['number' ] = '3'
3996
+ form ['volume' ] = '29'
3997
+
3998
+ form ['total_documents' ] = '16'
3999
+ form .set ('ctrl_vocabulary' , 'nd' )
4000
+
4001
+ form ['publication_start_month' ] = '9'
4002
+ form ['publication_end_month' ] = '11'
4003
+ form ['publication_year' ] = '2012'
4004
+ form ['is_marked_up' ] = False
4005
+ form ['editorial_standard' ] = 'other'
4006
+ # inline title formset
4007
+ form .set ('title-0-language' , '' )
4008
+ form .set ('title-0-id' , '' )
4009
+ form .set ('title-0-title' , 'La mexicanidad y el neoindianismo hoy' )
4010
+ response = form .submit ()
4011
+ self .assertTrue (response .context ['add_form' ].is_valid ())
4012
+ self .assertFalse (response .context ['titleformset' ].is_valid ())
4013
+ self .assertIn ('There are some errors or missing data.' , response .body )
4014
+
3922
4015
3923
4016
class SearchFormTests (WebTest ):
3924
4017
0 commit comments