Beispiel #1
0
 def test_clean_form_is_missing_title_field(self):
     form = ShelfForm({
         'title': '',
         'endpoint': 'search',
         'criteria': self.criteria_sea})
     assert not form.is_valid()
     assert form.errors == {'title': ['This field is required.']}
Beispiel #2
0
 def test_clean_form_is_missing_criteria_field(self):
     form = ShelfForm({
         'title': 'Recommended extensions',
         'endpoint': 'search',
         'criteria': ''})
     assert not form.is_valid()
     assert form.errors == {'criteria': ['This field is required.']}
Beispiel #3
0
 def test_clean_collections(self):
     form = ShelfForm({
         'title': 'Password managers (Collections)',
         'endpoint': 'collections',
         'criteria': self.criteria_col})
     assert form.is_valid(), form.errors
     assert form.cleaned_data['criteria'] == 'password-managers'
Beispiel #4
0
 def test_clean_search(self):
     form = ShelfForm({
         'title': 'Recommended extensions',
         'endpoint': 'search',
         'criteria': self.criteria_sea})
     assert form.is_valid(), form.errors
     assert form.cleaned_data['criteria'] == (
         '?recommended=true&sort=random&type=extension')
Beispiel #5
0
 def test_clean_form_is_missing_endpoint_field(self):
     form = ShelfForm(
         {
             'title': 'Recommended extensions',
             'endpoint': '',
             'criteria': self.criteria_sea,
             'addon_count': '0',
         }, )
     assert not form.is_valid()
     assert form.errors == {'endpoint': ['This field is required.']}
Beispiel #6
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 #7
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.')
Beispiel #8
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 #9
0
 def test_clean_search(self):
     form = ShelfForm(
         {
             'title': 'Recommended extensions',
             'endpoint': 'search',
             'criteria': self.criteria_sea,
             'addon_count': '0',
         }, )
     assert form.is_valid(), form.errors
     assert form.cleaned_data['criteria'] == (
         '?promoted=recommended&sort=random&type=extension')
 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 #12
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 #13
0
 def test_clean_search_themes(self):
     form = ShelfForm(
         {
             'title': 'Popular themes',
             'endpoint': 'search',
             'addon_type': amo.ADDON_STATICTHEME,
             'criteria': self.criteria_sea_thm,
             'addon_count': '0',
         },
     )
     assert form.is_valid(), form.errors
     assert form.cleaned_data['criteria'] == '?sort=users&type=statictheme'
Beispiel #14
0
 def test_clean_form_is_missing_criteria_field(self):
     form = ShelfForm(
         {
             'title': 'Recommended extensions',
             'endpoint': 'search',
             'addon_type': amo.ADDON_EXTENSION,
             'criteria': '',
             'addon_count': '0',
         },
     )
     assert not form.is_valid()
     assert form.errors == {'criteria': ['This field is required.']}
Beispiel #15
0
 def test_clean_collections_themes(self):
     form = ShelfForm(
         {
             'title': 'Featured themes',
             'endpoint': 'collections',
             'addon_type': amo.ADDON_STATICTHEME,
             'criteria': self.criteria_col_thm,
             'addon_count': '0',
         },
     )
     assert form.is_valid(), form.errors
     assert form.cleaned_data['criteria'] == 'featured-personas'
Beispiel #16
0
 def test_clean_collections_extensions(self):
     form = ShelfForm(
         {
             'title': 'Password managers (Collections)',
             'endpoint': 'collections',
             'addon_type': amo.ADDON_EXTENSION,
             'criteria': self.criteria_col_ext,
             'addon_count': '0',
         },
     )
     assert form.is_valid(), form.errors
     assert form.cleaned_data['criteria'] == 'password-managers'
Beispiel #17
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.')
Beispiel #18
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 #19
0
 def test_clean_tags(self):
     form = ShelfForm(
         {
             'title': 'Show tags',
             'endpoint': 'random-tag',
             'addon_type': amo.ADDON_EXTENSION,
             'criteria': '?',
             'addon_count': '0',
             'position': 0,
             'enabled': False,
         }, )
     assert form.is_valid(), form.errors
     assert form.cleaned_data['criteria'] == '?'
Beispiel #20
0
 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 #21
0
 def test_clean_form_is_missing_addon_type_field(self):
     form = ShelfForm(
         {
             'title': 'Recommended extensions',
             'endpoint': 'search',
             'addon_type': '',
             'criteria': self.criteria_sea_ext,
             'addon_count': '0',
             'position': 0,
             'enabled': False,
         }, )
     assert not form.is_valid()
     assert form.errors == {'addon_type': ['This field is required.']}
Beispiel #22
0
 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',
         'position': 0,
         'enabled': False,
     }
     form = ShelfForm(data)
     assert not form.is_valid()
     assert form.errors['criteria'] == ['Invalid "sort" parameter.']
Beispiel #23
0
 def test_clean_col_returns_404(self):
     data = {
         'title': 'Password manager (Collections)',
         'endpoint': 'collections',
         'addon_type': amo.ADDON_EXTENSION,
         'criteria': self.criteria_col_404,
         'addon_count': '0',
         'position': 0,
         'enabled': False,
     }
     form = ShelfForm(data)
     assert not form.is_valid()
     assert form.errors['criteria'] == ['URL was a 404.']
Beispiel #24
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',
             'position': 0,
             'enabled': False,
         }, )
     assert not form.is_valid()
     assert form.errors['criteria'] == ['Collection not found.']
Beispiel #25
0
 def test_clean_search_extensions(self):
     form = ShelfForm(
         {
             'title': 'Recommended extensions',
             'endpoint': 'search',
             'addon_type': amo.ADDON_EXTENSION,
             'criteria': self.criteria_sea_ext,
             'addon_count': '0',
             'position': 0,
             'enabled': False,
         }, )
     assert form.is_valid(), form.errors
     assert form.cleaned_data['criteria'] == (
         '?promoted=recommended&sort=random&type=extension')
Beispiel #26
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 #27
0
 def test_clean_tag_shelf_specifies_tag_in_criteria(self):
     data = {
         'title': 'Tags!',
         'endpoint': 'random-tag',
         'addon_type': amo.ADDON_EXTENSION,
         'criteria': '?tag=foo',
         'addon_count': '0',
         'position': 0,
         'enabled': False,
     }
     form = ShelfForm(data)
     assert not form.is_valid()
     assert form.errors['criteria'] == [
         'Omit `tag` param for tags shelf - a random tag will be chosen.'
     ]
Beispiel #28
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',
         'position': 0,
         'enabled': False,
     }
     form = ShelfForm(data)
     assert not form.is_valid()
     assert form.non_field_errors() == [
         'Use "Theme (Static)" in Addon type field for type=statictheme.'
     ]
Beispiel #29
0
 def test_clean_search_criteria_has_multiple_qmark(self):
     form = ShelfForm(
         {
             'title': 'Recommended extensions',
             'endpoint': 'search',
             'addon_type': amo.ADDON_EXTENSION,
             'criteria': '??recommended-true',
             'addon_count': '0',
             'position': 0,
             'enabled': False,
         }, )
     assert not form.is_valid()
     assert form.errors['criteria'] == [
         'Must start with a "?" and be a valid query string.'
     ]
Beispiel #30
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.'
     )