Example #1
0
 def test_single_field_term(self):
     """User has entered a single term for a field-based search."""
     data = MultiDict({
         "terms-0-operator": "AND",
         "terms-0-field": "title",
         "terms-0-term": "foo",
     })
     form = AdvancedSearchForm(data)
     self.assertTrue(form.validate())
Example #2
0
 def test_single_field_term(self):
     """User has entered a single term for a field-based search."""
     data = MultiDict({
         'terms-0-operator': 'AND',
         'terms-0-field': 'title',
         'terms-0-term': 'foo'
     })
     form = AdvancedSearchForm(data)
     self.assertTrue(form.validate())
Example #3
0
 def test_term_starts_with_wildcard(self):
     """User has entered a string that starts with a wildcard."""
     data = MultiDict({
         "terms-0-operator": "AND",
         "terms-0-field": "title",
         "terms-0-term": "*foo",
     })
     form = AdvancedSearchForm(data)
     self.assertFalse(form.validate(), "Form should be invalid")
Example #4
0
 def test_term_starts_with_wildcard(self):
     """User has entered a string that starts with a wildcard."""
     data = MultiDict({
         'terms-0-operator': 'AND',
         'terms-0-field': 'title',
         'terms-0-term': '*foo'
     })
     form = AdvancedSearchForm(data)
     self.assertFalse(form.validate(), "Form should be invalid")
Example #5
0
    def test_date_range_must_be_specified(self):
        """If the user selects date range, they must indicate start or end."""
        data = MultiDict({
            "terms-0-operator": "AND",
            "terms-0-field": "title",
            "terms-0-term": "foo",
            "date-filter_by": "date_range",
        })
        form = AdvancedSearchForm(data)
        self.assertFalse(form.validate())
        self.assertEqual(len(form.errors), 1)

        data = MultiDict({
            "terms-0-operator": "AND",
            "terms-0-field": "title",
            "terms-0-term": "foo",
            "date-filter_by": "date_range",
            "date-from_date": "2012-02-05",
        })
        form = AdvancedSearchForm(data)
        self.assertTrue(form.validate())

        data = MultiDict({
            "terms-0-operator": "AND",
            "terms-0-field": "title",
            "terms-0-term": "foo",
            "date-filter_by": "date_range",
            "date-to_date": "2012-02-05",
        })
        form = AdvancedSearchForm(data)
        self.assertTrue(form.validate())
Example #6
0
    def test_date_range_supports_variable_precision(self):
        """Date range in advanced search should support variable precision."""
        data = MultiDict({
            "terms-0-operator": "AND",
            "terms-0-field": "title",
            "terms-0-term": "foo",
            "date-filter_by": "date_range",
            "date-to_date": "2012-02-05",
        })
        form = AdvancedSearchForm(data)
        self.assertTrue(form.validate())

        data = MultiDict({
            "terms-0-operator": "AND",
            "terms-0-field": "title",
            "terms-0-term": "foo",
            "date-filter_by": "date_range",
            "date-to_date": "2012-02",
        })
        form = AdvancedSearchForm(data)
        self.assertTrue(form.validate())

        data = MultiDict({
            "terms-0-operator": "AND",
            "terms-0-field": "title",
            "terms-0-term": "foo",
            "date-filter_by": "date_range",
            "date-to_date": "2013",
            "date-from_date": "2012-03",
        })
        form = AdvancedSearchForm(data)
        self.assertTrue(form.validate())
Example #7
0
    def test_date_range_must_be_specified(self):
        """If the user selects date range, they must indicate start or end."""
        data = MultiDict({
            'terms-0-operator': 'AND',
            'terms-0-field': 'title',
            'terms-0-term': 'foo',
            'date-filter_by': 'date_range',
        })
        form = AdvancedSearchForm(data)
        self.assertFalse(form.validate())
        self.assertEqual(len(form.errors), 1)

        data = MultiDict({
            'terms-0-operator': 'AND',
            'terms-0-field': 'title',
            'terms-0-term': 'foo',
            'date-filter_by': 'date_range',
            'date-from_date': '2012-02-05'
        })
        form = AdvancedSearchForm(data)
        self.assertTrue(form.validate())

        data = MultiDict({
            'terms-0-operator': 'AND',
            'terms-0-field': 'title',
            'terms-0-term': 'foo',
            'date-filter_by': 'date_range',
            'date-to_date': '2012-02-05'
        })
        form = AdvancedSearchForm(data)
        self.assertTrue(form.validate())
Example #8
0
    def test_date_range_supports_variable_precision(self):
        """Date range in advanced search should support variable precision."""
        data = MultiDict({
            'terms-0-operator': 'AND',
            'terms-0-field': 'title',
            'terms-0-term': 'foo',
            'date-filter_by': 'date_range',
            'date-to_date': '2012-02-05'
        })
        form = AdvancedSearchForm(data)
        self.assertTrue(form.validate())

        data = MultiDict({
            'terms-0-operator': 'AND',
            'terms-0-field': 'title',
            'terms-0-term': 'foo',
            'date-filter_by': 'date_range',
            'date-to_date': '2012-02'
        })
        form = AdvancedSearchForm(data)
        self.assertTrue(form.validate())

        data = MultiDict({
            'terms-0-operator': 'AND',
            'terms-0-field': 'title',
            'terms-0-term': 'foo',
            'date-filter_by': 'date_range',
            'date-to_date': '2013',
            'date-from_date': '2012-03'
        })
        form = AdvancedSearchForm(data)
        self.assertTrue(form.validate())
Example #9
0
 def test_input_whitespace_is_stripped(self):
     """If query has padding whitespace, it should be removed."""
     data = MultiDict({
         "terms-0-operator": "AND",
         "terms-0-field": "title",
         "terms-0-term": " foo ",
     })
     form = AdvancedSearchForm(data)
     self.assertTrue(form.validate(), "Form should be valid.")
     self.assertEqual(form.terms[0].term.data, "foo",
                      "Whitespace should be stripped.")
Example #10
0
 def test_input_whitespace_is_stripped(self):
     """If query has padding whitespace, it should be removed."""
     data = MultiDict({
         'terms-0-operator': 'AND',
         'terms-0-field': 'title',
         'terms-0-term': ' foo '
     })
     form = AdvancedSearchForm(data)
     self.assertTrue(form.validate(), "Form should be valid.")
     self.assertEqual(form.terms[0].term.data, 'foo',
                      "Whitespace should be stripped.")
Example #11
0
    def test_year_must_be_after_1990(self):
        """If the user selects a specific year, it must be after 1990."""
        data = MultiDict({
            "terms-0-operator": "AND",
            "terms-0-field": "title",
            "terms-0-term": "foo",
            "date-filter_by": "specific_year",
            "date-year": "1990",
        })
        form = AdvancedSearchForm(data)
        self.assertFalse(form.validate())

        data = MultiDict({
            "terms-0-operator": "AND",
            "terms-0-field": "title",
            "terms-0-term": "foo",
            "date-filter_by": "specific_year",
            "date-year": "1991",
        })
        form = AdvancedSearchForm(data)
        self.assertTrue(form.validate())
Example #12
0
    def test_specific_year_must_be_specified(self):
        """If the user selects specific year, they must indicate a year."""
        data = MultiDict({
            "terms-0-operator": "AND",
            "terms-0-field": "title",
            "terms-0-term": "foo",
            "date-filter_by": "specific_year",
        })
        form = AdvancedSearchForm(data)
        self.assertFalse(form.validate())
        self.assertEqual(len(form.errors), 1)

        data = MultiDict({
            "terms-0-operator": "AND",
            "terms-0-field": "title",
            "terms-0-term": "foo",
            "date-filter_by": "specific_year",
            "date-year": "2012",
        })
        form = AdvancedSearchForm(data)
        self.assertTrue(form.validate())
Example #13
0
    def test_year_must_be_after_1990(self):
        """If the user selects a specific year, it must be after 1990."""
        data = MultiDict({
            'terms-0-operator': 'AND',
            'terms-0-field': 'title',
            'terms-0-term': 'foo',
            'date-filter_by': 'specific_year',
            'date-year': '1990'
        })
        form = AdvancedSearchForm(data)
        self.assertFalse(form.validate())

        data = MultiDict({
            'terms-0-operator': 'AND',
            'terms-0-field': 'title',
            'terms-0-term': 'foo',
            'date-filter_by': 'specific_year',
            'date-year': '1991'
        })
        form = AdvancedSearchForm(data)
        self.assertTrue(form.validate())
Example #14
0
    def test_specific_year_must_be_specified(self):
        """If the user selects specific year, they must indicate a year."""
        data = MultiDict({
            'terms-0-operator': 'AND',
            'terms-0-field': 'title',
            'terms-0-term': 'foo',
            'date-filter_by': 'specific_year',
        })
        form = AdvancedSearchForm(data)
        self.assertFalse(form.validate())
        self.assertEqual(len(form.errors), 1)

        data = MultiDict({
            'terms-0-operator': 'AND',
            'terms-0-field': 'title',
            'terms-0-term': 'foo',
            'date-filter_by': 'specific_year',
            'date-year': '2012'
        })
        form = AdvancedSearchForm(data)
        self.assertTrue(form.validate())
Example #15
0
    def test_querystring_has_unbalanced_quotes(self):
        """Querystring has an odd number of quote characters."""
        data = MultiDict({
            "terms-0-operator": "AND",
            "terms-0-field": "title",
            "terms-0-term": '"rhubarb',
        })
        form = AdvancedSearchForm(data)
        self.assertFalse(form.validate(), "Form should be invalid")

        data["terms-0-term"] = '"rhubarb"'
        form = AdvancedSearchForm(data)
        self.assertTrue(form.validate(), "Form should be valid")

        data["terms-0-term"] = '"rhubarb" "pie'
        form = AdvancedSearchForm(data)
        self.assertFalse(form.validate(), "Form should be invalid")

        data["terms-0-term"] = '"rhubarb" "pie"'
        form = AdvancedSearchForm(data)
        self.assertTrue(form.validate(), "Form should be valid")
Example #16
0
    def test_end_date_bounding(self):
        """If a user selects an end date, it must be bounded correctly."""
        data = MultiDict({
            "terms-0-operator": "AND",
            "terms-0-field": "title",
            "terms-0-term": "foo",
            "date-filter_by": "date_range",
            "date-to_date": "2012",
        })
        form = AdvancedSearchForm(data)
        self.assertTrue(form.validate())
        self.assertEqual(form.date.to_date.data,
                         date(year=2012, month=12, day=31))

        data["date-to_date"] = "2012-02"
        form = AdvancedSearchForm(data)
        self.assertTrue(form.validate())
        self.assertEqual(form.date.to_date.data,
                         date(year=2012, month=2, day=29))

        data["date-to_date"] = "2016-06"
        form = AdvancedSearchForm(data)
        self.assertTrue(form.validate())
        self.assertEqual(form.date.to_date.data,
                         date(year=2016, month=6, day=30))

        data["date-to_date"] = "2016-06-30"
        form = AdvancedSearchForm(data)
        self.assertTrue(form.validate())
        self.assertEqual(form.date.to_date.data,
                         date(year=2016, month=6, day=30))

        data["date-to_date"] = "2100-02"
        form = AdvancedSearchForm(data)
        self.assertFalse(form.validate())
Example #17
0
    def test_end_date_bounding(self):
        """If a user selects an end date, it must be bounded correctly."""
        data = MultiDict({
            'terms-0-operator': 'AND',
            'terms-0-field': 'title',
            'terms-0-term': 'foo',
            'date-filter_by': 'date_range',
            'date-to_date': '2012'
        })
        form = AdvancedSearchForm(data)
        self.assertTrue(form.validate())
        self.assertEqual(form.date.to_date.data,
                         date(year=2012, month=12, day=31))

        data['date-to_date'] = '2012-02'
        form = AdvancedSearchForm(data)
        self.assertTrue(form.validate())
        self.assertEqual(form.date.to_date.data,
                         date(year=2012, month=2, day=29))

        data['date-to_date'] = '2016-06'
        form = AdvancedSearchForm(data)
        self.assertTrue(form.validate())
        self.assertEqual(form.date.to_date.data,
                         date(year=2016, month=6, day=30))

        data['date-to_date'] = '2016-06-30'
        form = AdvancedSearchForm(data)
        self.assertTrue(form.validate())
        self.assertEqual(form.date.to_date.data,
                         date(year=2016, month=6, day=30))

        data['date-to_date'] = '2100-02'
        form = AdvancedSearchForm(data)
        self.assertFalse(form.validate())