def test_parse_complex_valid_filter_string(self): filtershandler = FiltersHandler(urlbuilder=mock.MagicMock()) filtershandler.add_filter(MinimalStringFilter()) filtershandler.add_filter(MinimalIntFilter()) filtershandler.parse('/i-10/s-jane,joe/') self.assertEqual(2, len(filtershandler.filtermap)) self.assertEqual(['10'], filtershandler.filtermap['i'].values) self.assertEqual(['jane', 'joe'], filtershandler.filtermap['s'].values)
def test_parse_multivalue_valid_filter_string(self): filtershandler = FiltersHandler(urlbuilder=mock.MagicMock()) filtershandler.add_filter(MinimalStringFilter()) filtershandler.parse('s-a,b,c') self.assertEqual(['a', 'b', 'c'], filtershandler.filtermap['s'].values)
def test_parse_simple_valid_filter_string_leading_slash(self): filtershandler = FiltersHandler(urlbuilder=mock.MagicMock()) filtershandler.add_filter(MinimalStringFilter()) filtershandler.parse('/s-test') self.assertEqual(['test'], filtershandler.filtermap['s'].values)
def test_parse_none(self): filtershandler = FiltersHandler(urlbuilder=mock.MagicMock()) filtershandler.parse(None) self.assertEqual({}, filtershandler.filtermap)
def test_parse_empty_string(self): filtershandler = FiltersHandler(urlbuilder=mock.MagicMock()) filtershandler.parse('') self.assertEqual({}, filtershandler.filtermap)
def test_invalid_filter_slug(self): filtershandler = FiltersHandler(urlbuilder=mock.MagicMock()) with self.assertRaisesMessage(InvalidFiltersStringError, '"x" is not a valid filter slug.'): filtershandler.parse('x-10')
def test_invalid_filter_string(self): filtershandler = FiltersHandler(urlbuilder=mock.MagicMock()) with self.assertRaisesMessage(InvalidFiltersStringError, '"x" does not contain "-".'): filtershandler.parse('x')
def test_get_cleaned_values_for(self): filtershandler = FiltersHandler(urlbuilder=mock.MagicMock()) filtershandler.add_filter(MinimalIntFilter()) filtershandler.parse('/i-10') self.assertEqual([10], filtershandler.get_cleaned_values_for('i'))