def _tx():
     SearchEntry.insert(
         s, SearchClasses.EXACT, u'e', u'i', u'RESULT', u'type', value)
     for mutation in [casefold, spaced, punctuated]:
         self.assertThat(
             list(SearchEntry.search(
                 s, SearchClasses.EXACT, u'e', u'i', mutation(value))),
             Annotate(
                 'Not found for {!r}({!r}) == {!r}'.format(
                     mutation, value, mutation(value)),
                 Equals([u'RESULT'])))
Beispiel #2
0
 def _tx():
     SearchEntry.insert(s, SearchClasses.PREFIX, u'e', u'i', u'RESULT',
                        u'type', u'yo')
     self.assertThat(s.query(SearchEntry).count(), Equals(1))
     self.assertThat([
         list(
             SearchEntry.search(s, SearchClasses.PREFIX, u'e', u'i',
                                u'')),
         list(
             SearchEntry.search(s, SearchClasses.PREFIX, u'e', u'i',
                                u'. .'))
     ], AllMatch(Equals([])))
Beispiel #3
0
 def _tx():
     for x in xrange(50):
         SearchEntry.insert(s, SearchClasses.EXACT, u'e', u'i',
                            u'RESULT', u'type{}'.format(x), u'yo')
     self.assertThat(s.query(SearchEntry).count(), Equals(50))
     self.assertThat(
         list(
             SearchEntry.search(s,
                                SearchClasses.EXACT,
                                u'e',
                                u'i',
                                u'yo',
                                limit=20)), HasLength(20))
        def _tx():
            SearchEntry.insert(
                s, SearchClasses.EXACT, environment, indexType, result,
                searchType, searchValue)
            self.assertThat(
                list(SearchEntry.search(
                    s, SearchClasses.EXACT, environment, indexType,
                    searchValue)),
                Equals([result]))
            self.assertThat(
                list(SearchEntry.search(
                    s, SearchClasses.EXACT, environment, indexType,
                    searchValue, searchType)),
                Equals([result]))

            SearchEntry.remove(
                s, SearchClasses.EXACT, environment, indexType, result,
                searchType)
            self.assertThat(
                list(SearchEntry.search(
                    s, SearchClasses.EXACT, environment, indexType,
                    searchValue)),
                Equals([]))
            self.assertThat(
                list(SearchEntry.search(
                    s, SearchClasses.EXACT, environment, indexType,
                    searchValue, searchType)),
                Equals([]))
Beispiel #5
0
        def _tx():
            SearchEntry.insert(s, SearchClasses.EXACT, environment, indexType,
                               result, searchType, searchValue)
            self.assertThat(
                list(
                    SearchEntry.search(s, SearchClasses.EXACT, environment,
                                       indexType, searchValue)),
                Equals([{
                    u'result': result,
                    u'type': searchType
                }]))
            self.assertThat(
                list(
                    SearchEntry.search(s, SearchClasses.EXACT, environment,
                                       indexType, searchValue, searchType)),
                Equals([{
                    u'result': result,
                    u'type': searchType
                }]))

            SearchEntry.remove(s, SearchClasses.EXACT, environment, indexType,
                               result, searchType)
            self.assertThat(
                list(
                    SearchEntry.search(s, SearchClasses.EXACT, environment,
                                       indexType, searchValue)), Equals([]))
            self.assertThat(
                list(
                    SearchEntry.search(s, SearchClasses.EXACT, environment,
                                       indexType, searchValue, searchType)),
                Equals([]))
Beispiel #6
0
 def _tx():
     SearchEntry.insert(s, SearchClasses.EXACT, u'e', u'i', u'RESULT',
                        u'type', value)
     for mutation in [casefold, spaced, punctuated]:
         self.assertThat(
             list(
                 SearchEntry.search(s, SearchClasses.EXACT, u'e', u'i',
                                    mutation(value))),
             Annotate(
                 'Not found for {!r}({!r}) == {!r}'.format(
                     mutation, value, mutation(value)),
                 Equals([{
                     u'result': u'RESULT',
                     u'type': u'type'
                 }])))
Beispiel #7
0
 def render_GET(self, request):
     with LOG_SEARCH_GET(**self.params) as action:
         results = self.store.transact(lambda: list(
             SearchEntry.search(store=self.store, **self.params)))
         action.add_success_fields(results=results)
         request.setHeader('Content-Type', 'application/json')
         return json.dumps(results)
 def render_GET(self, request):
     with LOG_SEARCH_GET(**self.params) as action:
         results = self.store.transact(
             lambda: list(
                 SearchEntry.search(store=self.store, **self.params)))
         action.add_success_fields(results=results)
         request.setHeader('Content-Type', 'application/json')
         return json.dumps(results)
Beispiel #9
0
    def test_prefixSearches(self, environment, indexType, searchValue,
                            searchType, result):
        """
        Test inserting, searching, and removing for the prefix search class.
        """
        assume(SearchEntry._normalize(searchValue[:3]) != u'')
        s = Store()

        def _tx():
            SearchEntry.insert(s, SearchClasses.PREFIX, environment, indexType,
                               result, searchType, searchValue)
            self.assertThat(
                list(
                    SearchEntry.search(s, SearchClasses.PREFIX, environment,
                                       indexType, searchValue[:3])),
                Equals([{
                    u'result': result,
                    u'type': searchType
                }]))
            self.assertThat(
                list(
                    SearchEntry.search(s, SearchClasses.PREFIX, environment,
                                       indexType, 'a' + searchValue)),
                Equals([]))
            self.assertThat(
                list(
                    SearchEntry.search(s, SearchClasses.PREFIX, environment,
                                       indexType, searchValue)),
                Equals([{
                    u'result': result,
                    u'type': searchType
                }]))
            self.assertThat(
                list(
                    SearchEntry.search(s, SearchClasses.PREFIX, environment,
                                       indexType, searchValue, searchType)),
                Equals([{
                    u'result': result,
                    u'type': searchType
                }]))

            SearchEntry.remove(s, SearchClasses.PREFIX, environment, indexType,
                               result, searchType)
            self.assertThat(
                list(
                    SearchEntry.search(s, SearchClasses.PREFIX, environment,
                                       indexType, searchValue)), Equals([]))
            self.assertThat(
                list(
                    SearchEntry.search(s, SearchClasses.PREFIX, environment,
                                       indexType, searchValue, searchType)),
                Equals([]))

        s.transact(_tx)
 def _tx():
     SearchEntry.insert(
         s, SearchClasses.EXACT, u'e', u'i', u'RESULT', u'type', u'. /')
     self.assertThat(s.query(SearchEntry).count(), Equals(0))
     SearchEntry.insert(
         s, SearchClasses.EXACT, u'e', u'i', u'RESULT', u'type', u'yo')
     self.assertThat(s.query(SearchEntry).count(), Equals(1))
     SearchEntry.insert(
         s, SearchClasses.EXACT, u'e', u'i', u'RESULT', u'type', u'. /')
     self.assertThat(s.query(SearchEntry).count(), Equals(0))
Beispiel #11
0
 def _tx():
     SearchEntry.insert(s, SearchClasses.EXACT, u'e', u'i', u'RESULT',
                        u'type', u'. /')
     self.assertThat(s.query(SearchEntry).count(), Equals(0))
     SearchEntry.insert(s, SearchClasses.EXACT, u'e', u'i', u'RESULT',
                        u'type', u'yo')
     self.assertThat(s.query(SearchEntry).count(), Equals(1))
     SearchEntry.insert(s, SearchClasses.EXACT, u'e', u'i', u'RESULT',
                        u'type', u'. /')
     self.assertThat(s.query(SearchEntry).count(), Equals(0))
    def test_prefixSearches(self, environment, indexType, searchValue,
                            searchType, result):
        """
        Test inserting, searching, and removing for the prefix search class.
        """
        assume(SearchEntry._normalize(searchValue) != u'')
        s = Store()
        def _tx():
            SearchEntry.insert(
                s, SearchClasses.PREFIX, environment, indexType, result,
                searchType, searchValue)
            self.assertThat(
                list(SearchEntry.search(
                    s, SearchClasses.PREFIX, environment, indexType,
                    searchValue[:3])),
                Equals([result]))
            self.assertThat(
                list(SearchEntry.search(
                    s, SearchClasses.PREFIX, environment, indexType,
                    'a' + searchValue)),
                Equals([]))
            self.assertThat(
                list(SearchEntry.search(
                    s, SearchClasses.PREFIX, environment, indexType,
                    searchValue)),
                Equals([result]))
            self.assertThat(
                list(SearchEntry.search(
                    s, SearchClasses.PREFIX, environment, indexType,
                    searchValue, searchType)),
                Equals([result]))

            SearchEntry.remove(
                s, SearchClasses.PREFIX, environment, indexType, result,
                searchType)
            self.assertThat(
                list(SearchEntry.search(
                    s, SearchClasses.PREFIX, environment, indexType,
                    searchValue)),
                Equals([]))
            self.assertThat(
                list(SearchEntry.search(
                    s, SearchClasses.PREFIX, environment, indexType,
                    searchValue, searchType)),
                Equals([]))
        s.transact(_tx)