Beispiel #1
0
 def test_clean_search_criteria_has_multiple_qmark(self):
     form = ShelfForm({
         'title': 'Recommended extensions',
         'endpoint': 'search',
         'criteria': '??recommended-true'
     })
     assert not form.is_valid()
     with self.assertRaises(ValidationError) as exc:
         form.clean()
     assert exc.exception.message == ('Check criteria field.')
Beispiel #2
0
 def test_clean_form_throws_error_for_NoReverseMatch(self):
     form = ShelfForm({
         'title': 'New collection',
         'endpoint': 'collections',
         'criteria': '/'})
     assert not form.is_valid()
     with self.assertRaises(ValidationError) as exc:
         form.clean()
     assert exc.exception.message == (
         'No data found - check criteria parameters.')
 def test_clean_col_returns_404(self):
     data = {
         'title': 'Password manager (Collections)',
         'endpoint': 'collections',
         'criteria': self.criteria_col_404,
     }
     form = ShelfForm(data)
     assert not form.is_valid()
     with self.assertRaises(ValidationError) as exc:
         form.clean()
     assert exc.exception.message == ('URL was a 404. Check criteria')
 def test_clean_searchtheme_criteria_theme_not_used_for_other_type(self):
     form = ShelfForm({
         'title': 'Recommended extensions',
         'endpoint': 'search-themes',
         'criteria': '?recommended=true&type=extension',
     })
     assert not form.is_valid()
     with self.assertRaises(ValidationError) as exc:
         form.clean()
     assert exc.exception.message == (
         'Don`t use "search-themes" endpoint for non themes. Use "search".')
Beispiel #5
0
 def test_clean_returns_empty(self):
     data = {
         'title': 'Popular themes',
         'endpoint': 'search',
         'criteria': self.criteria_empty}
     form = ShelfForm(data)
     assert not form.is_valid()
     with self.assertRaises(ValidationError) as exc:
         form.clean()
     assert exc.exception.message == (
         'Check criteria parameters - e.g., "type"')
Beispiel #6
0
 def test_clean_returns_not_200(self):
     data = {
         'title': 'Popular themes',
         'endpoint': 'search',
         'criteria': self.criteria_not_200}
     form = ShelfForm(data)
     assert not form.is_valid()
     with self.assertRaises(ValidationError) as exc:
         form.clean()
     assert exc.exception.message == (
         'Check criteria - Invalid \"sort\" parameter.')
Beispiel #7
0
 def test_clean_searchtheme_criteria_theme_used_for_statictheme_type(self):
     form = ShelfForm({
         'title': 'Recommended extensions',
         'endpoint': 'search',
         'criteria': '?recommended=true&type=statictheme',
         'addon_count': '0',
     })
     assert not form.is_valid()
     with self.assertRaises(ValidationError) as exc:
         form.clean()
     assert exc.exception.message == (
         'Use "search-themes" endpoint for type=statictheme.')
Beispiel #8
0
 def test_clean_search_criteria_does_not_start_with_qmark(self):
     form = ShelfForm(
         {
             'title': 'Recommended extensions',
             'endpoint': 'search',
             'criteria': '..?recommended-true',
             'addon_count': '0',
         }, )
     assert not form.is_valid()
     with self.assertRaises(ValidationError) as exc:
         form.clean()
     assert exc.exception.message == ('Check criteria field.')
 def test_clean_returns_not_200(self):
     data = {
         'title': 'Popular extensions',
         'endpoint': 'search',
         'addon_type': amo.ADDON_EXTENSION,
         'criteria': self.criteria_not_200,
         'addon_count': '0',
     }
     form = ShelfForm(data)
     assert not form.is_valid()
     with self.assertRaises(ValidationError) as exc:
         form.clean()
     assert exc.exception.message == ('Check criteria - Invalid "sort" parameter.')
Beispiel #10
0
 def test_clean_cannot_use_extensions_addontype_with_type_statictheme(self):
     data = {
         'title': 'Popular themes',
         'endpoint': 'search',
         'addon_type': amo.ADDON_EXTENSION,
         'criteria': self.criteria_sea_thm,
         'addon_count': '0',
     }
     form = ShelfForm(data)
     assert not form.is_valid()
     with self.assertRaises(ValidationError) as exc:
         form.clean()
     assert exc.exception.message == (
         'Use "Theme (Static)" in Addon type field for type=statictheme.'
     )
Beispiel #11
0
 def test_clean_form_throws_error_for_NoReverseMatch(self):
     form = ShelfForm(
         {
             'title': 'New collection',
             'endpoint': 'collections',
             'addon_type': amo.ADDON_EXTENSION,
             'criteria': '/',
             'addon_count': '0',
         },
     )
     assert not form.is_valid()
     with self.assertRaises(ValidationError) as exc:
         form.clean()
     assert exc.exception.message == (
         'Collection not found - check criteria parameters.'
     )
Beispiel #12
0
 def test_clean_cannot_use_theme_addontype_without_type_statictheme(self):
     data = {
         'title': 'Popular themes',
         'endpoint': 'search',
         'addon_type': amo.ADDON_STATICTHEME,
         'criteria': self.criteria_sea_ext,
         'addon_count': '0',
     }
     form = ShelfForm(data)
     assert not form.is_valid()
     with self.assertRaises(ValidationError) as exc:
         form.clean()
     assert exc.exception.message == (
         'Check fields - for "Theme (Static)" addon type, use type=statictheme. '
         'For non theme addons, use "Extension" in Addon type field, '
         'not "Theme (Static)".'
     )