def clean(self): cleaned_data = super(SnippetAdminForm, self).clean() if any([cleaned_data['on_startpage_4'], cleaned_data['on_startpage_3'], cleaned_data['on_startpage_2'], cleaned_data['on_startpage_1']]): validate_xml_variables(cleaned_data['data']) version_upper_bound = cleaned_data.get('client_option_version_upper_bound', 'any') version_lower_bound = cleaned_data.get('client_option_version_lower_bound', 'any') if (version_upper_bound == 'older_than_current_release' and version_lower_bound == 'current_release'): raise forms.ValidationError( "It doesn't make sense to combine those two Firefox version filters") if 'any' not in [version_lower_bound, version_upper_bound]: if Version(version_upper_bound) < Version(version_lower_bound): raise forms.ValidationError( 'Firefox version upper bound must be bigger than lower bound.') profileage_lower_bound = int(cleaned_data.get('client_option_profileage_lower_bound', -1)) profileage_upper_bound = int(cleaned_data.get('client_option_profileage_upper_bound', -1)) cleaned_data['client_option_profileage_lower_bound'] = profileage_lower_bound cleaned_data['client_option_profileage_upper_bound'] = profileage_upper_bound if ((profileage_lower_bound > -1 and profileage_upper_bound > -1 and profileage_upper_bound <= profileage_lower_bound)): raise forms.ValidationError('Profile age upper bound must be bigger than lower bound.') sessionage_lower_bound = int(cleaned_data.get('client_option_sessionage_lower_bound', -1)) sessionage_upper_bound = int(cleaned_data.get('client_option_sessionage_upper_bound', -1)) cleaned_data['client_option_sessionage_lower_bound'] = sessionage_lower_bound cleaned_data['client_option_sessionage_upper_bound'] = sessionage_upper_bound if ((sessionage_lower_bound > -1 and sessionage_upper_bound > -1 and sessionage_upper_bound <= sessionage_lower_bound)): raise forms.ValidationError('Profile age upper bound must be bigger than lower bound.') bookmarks_count_lower_bound = int( cleaned_data.get('client_option_bookmarks_count_lower_bound', -1)) bookmarks_count_upper_bound = int( cleaned_data.get('client_option_bookmarks_count_upper_bound', -1)) cleaned_data['client_option_bookmarks_count_lower_bound'] = bookmarks_count_lower_bound cleaned_data['client_option_bookmarks_count_upper_bound'] = bookmarks_count_upper_bound if ((bookmarks_count_lower_bound > -1 and bookmarks_count_upper_bound > -1 and bookmarks_count_upper_bound <= bookmarks_count_lower_bound)): raise forms.ValidationError('Bookmarks count upper bound must be ' 'bigger than lower bound.') if not any([cleaned_data['on_release'], cleaned_data['on_beta'], cleaned_data['on_aurora'], cleaned_data['on_nightly'], cleaned_data['on_esr']]): raise forms.ValidationError('Select at least one channel to publish this snippet on.') if ((cleaned_data.get('on_startpage_5') and any([cleaned_data['on_startpage_4'], cleaned_data['on_startpage_3'], cleaned_data['on_startpage_2'], cleaned_data['on_startpage_1']]))): raise forms.ValidationError('Activity Stream cannot be combined ' 'with Startpage Versions 1-4.') if not any([cleaned_data.get('on_startpage_4'), cleaned_data.get('on_startpage_3'), cleaned_data.get('on_startpage_2'), cleaned_data.get('on_startpage_1'), cleaned_data.get('on_startpage_5')]): raise forms.ValidationError('Select at least one Startpage to publish this snippet on.') if ((cleaned_data.get('client_option_addon_name') and cleaned_data.get('client_option_addon_check_type') == 'any')): raise forms.ValidationError('Select an add-on check or remove add-on name.') if ((not cleaned_data.get('client_option_addon_name') and cleaned_data.get('client_option_addon_check_type', 'any') != 'any')): raise forms.ValidationError('Type add-on name to check or remove add-on check.') self._publish_permission_check(cleaned_data) return cleaned_data
def test_non_string_values(self): """ If a value isn't a string, skip over it and continue validating. """ valid_xml = '{"foo": "<b>Bar</b>", "baz": true}' self.assertEqual(validate_xml_variables(valid_xml), valid_xml)
def clean(self): cleaned_data = super(SnippetAdminForm, self).clean() if any([ cleaned_data['on_startpage_4'], cleaned_data['on_startpage_3'], cleaned_data['on_startpage_2'], cleaned_data['on_startpage_1'] ]): validate_xml_variables(cleaned_data['data']) version_upper_bound = cleaned_data.get( 'client_option_version_upper_bound', 'any') version_lower_bound = cleaned_data.get( 'client_option_version_lower_bound', 'any') if (version_upper_bound == 'older_than_current_release' and version_lower_bound == 'current_release'): raise forms.ValidationError( "It doesn't make sense to combine those two Firefox version filters" ) if 'any' not in [version_lower_bound, version_upper_bound]: if Version(version_upper_bound) < Version(version_lower_bound): raise forms.ValidationError( 'Firefox version upper bound must be bigger than lower bound.' ) profileage_lower_bound = int( cleaned_data.get('client_option_profileage_lower_bound', -1)) profileage_upper_bound = int( cleaned_data.get('client_option_profileage_upper_bound', -1)) cleaned_data[ 'client_option_profileage_lower_bound'] = profileage_lower_bound cleaned_data[ 'client_option_profileage_upper_bound'] = profileage_upper_bound if ((profileage_lower_bound > -1 and profileage_upper_bound > -1 and profileage_upper_bound <= profileage_lower_bound)): raise forms.ValidationError( 'Profile age upper bound must be bigger than lower bound.') sessionage_lower_bound = int( cleaned_data.get('client_option_sessionage_lower_bound', -1)) sessionage_upper_bound = int( cleaned_data.get('client_option_sessionage_upper_bound', -1)) cleaned_data[ 'client_option_sessionage_lower_bound'] = sessionage_lower_bound cleaned_data[ 'client_option_sessionage_upper_bound'] = sessionage_upper_bound if ((sessionage_lower_bound > -1 and sessionage_upper_bound > -1 and sessionage_upper_bound <= sessionage_lower_bound)): raise forms.ValidationError( 'Profile age upper bound must be bigger than lower bound.') bookmarks_count_lower_bound = int( cleaned_data.get('client_option_bookmarks_count_lower_bound', -1)) bookmarks_count_upper_bound = int( cleaned_data.get('client_option_bookmarks_count_upper_bound', -1)) cleaned_data[ 'client_option_bookmarks_count_lower_bound'] = bookmarks_count_lower_bound cleaned_data[ 'client_option_bookmarks_count_upper_bound'] = bookmarks_count_upper_bound if ((bookmarks_count_lower_bound > -1 and bookmarks_count_upper_bound > -1 and bookmarks_count_upper_bound <= bookmarks_count_lower_bound)): raise forms.ValidationError('Bookmarks count upper bound must be ' 'bigger than lower bound.') if not any([ cleaned_data['on_release'], cleaned_data['on_beta'], cleaned_data['on_aurora'], cleaned_data['on_nightly'], cleaned_data['on_esr'] ]): raise forms.ValidationError( 'Select at least one channel to publish this snippet on.') if ((cleaned_data.get('on_startpage_5') and any([ cleaned_data['on_startpage_4'], cleaned_data['on_startpage_3'], cleaned_data['on_startpage_2'], cleaned_data['on_startpage_1'] ]))): raise forms.ValidationError('Activity Stream cannot be combined ' 'with Startpage Versions 1-4.') if not any([ cleaned_data.get('on_startpage_4'), cleaned_data.get('on_startpage_3'), cleaned_data.get('on_startpage_2'), cleaned_data.get('on_startpage_1'), cleaned_data.get('on_startpage_5') ]): raise forms.ValidationError( 'Select at least one Startpage to publish this snippet on.') if ((cleaned_data.get('client_option_addon_name') and cleaned_data.get('client_option_addon_check_type') == 'any')): raise forms.ValidationError( 'Select an add-on check or remove add-on name.') if ((not cleaned_data.get('client_option_addon_name') and cleaned_data.get('client_option_addon_check_type', 'any') != 'any')): raise forms.ValidationError( 'Type add-on name to check or remove add-on check.') self._publish_permission_check(cleaned_data) return cleaned_data
def test_unicode(self): unicode_xml = '{"foo": "<b>\u03c6\u03bf\u03bf</b>"}' self.assertEqual(validate_xml_variables(unicode_xml), unicode_xml)
def test_valid_xml(self): valid_xml = '{"foo": "<b>foobar</b>"}' self.assertEqual(validate_xml_variables(valid_xml), valid_xml)
def test_non_string_values(self): """ If a value isn't a string, skip over it and continue validating. """ valid_xml = '{"foo": "<b>Bar</b>", "baz": true}' self.assertEqual(validate_xml_variables(valid_xml), valid_xml)
def test_unicode(self): unicode_xml = '{"foo": "<b>\u03c6\u03bf\u03bf</b>"}' self.assertEqual(validate_xml_variables(unicode_xml), unicode_xml)
def test_valid_xml(self): valid_xml = '{"foo": "<b>foobar</b>"}' self.assertEqual(validate_xml_variables(valid_xml), valid_xml)