File tree 2 files changed +29
-0
lines changed
2 files changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -182,6 +182,15 @@ class Meta(object):
182
182
widget = forms .Textarea ,
183
183
)
184
184
185
+ def clean_tags (self ):
186
+ tags = self .cleaned_data .get ('tags' , [])
187
+ for tag in tags :
188
+ if len (tag ) > 100 :
189
+ raise forms .ValidationError (
190
+ _ ('Length of each tag must be less than or equal to 100 characters.' )
191
+ )
192
+ return tags
193
+
185
194
186
195
class ProjectAdvancedForm (ProjectTriggerBuildMixin , ProjectForm ):
187
196
Original file line number Diff line number Diff line change @@ -163,6 +163,26 @@ def test_changing_vcs_should_not_change_latest_is_not_none(self):
163
163
latest .refresh_from_db ()
164
164
self .assertEqual (latest .identifier , 'custom' )
165
165
166
+ def test_length_of_tags (self ):
167
+ data = {
168
+ 'documentation_type' : 'sphinx' ,
169
+ 'language' : 'en'
170
+ }
171
+ data ['tags' ] = '{},{}' .format ('a' * 50 , 'b' * 99 )
172
+ form = ProjectExtraForm (data )
173
+ self .assertTrue (form .is_valid ())
174
+
175
+ data ['tags' ] = '{},{}' .format ('a' * 90 , 'b' * 100 )
176
+ form = ProjectExtraForm (data )
177
+ self .assertTrue (form .is_valid ())
178
+
179
+ data ['tags' ] = '{},{}' .format ('a' * 99 , 'b' * 101 )
180
+ form = ProjectExtraForm (data )
181
+ self .assertFalse (form .is_valid ())
182
+ self .assertTrue (form .has_error ('tags' ))
183
+ error_msg = 'Length of each tag must be less than or equal to 100 characters.'
184
+ self .assertDictEqual (form .errors , {'tags' : [error_msg ]})
185
+
166
186
167
187
class TestProjectAdvancedForm (TestCase ):
168
188
You can’t perform that action at this time.
0 commit comments