예제 #1
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'])))
예제 #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([])))
예제 #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))
예제 #4
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([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([]))
예제 #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([]))
예제 #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'
                 }])))
예제 #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)
예제 #8
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)
예제 #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)
예제 #10
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))
예제 #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))
예제 #12
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)