Exemplo n.º 1
0
 def test_logical_operations(self):
     self.assertEqual([{u'name': u'The Mind\'s I'}, {u'name': u'GEB'}],
                      WikiPage.wikiquery(u'"GEB" + "The Mind\'s I"'))
     self.assertEqual({u'name': u'The Mind\'s I'},
                      WikiPage.wikiquery(u'schema:"Book" * author:"Douglas Hofstadter" * author:"Daniel Dennett"'))
     self.assertEqual([{'name': u"The Mind's I"}, {'name': u'GEB'}],
                      WikiPage.wikiquery(u'schema:"Book" + author:"Douglas Hofstadter" * author:"Daniel Dennett"'))
Exemplo n.º 2
0
    def test_specifying_attr_order(self):
        result = WikiPage.wikiquery(u'schema:"Book" > author, datePublished+')
        self.assertEqual(u'1979', result[0]['datePublished'].pvalue)
        self.assertEqual(u'1982', result[1]['datePublished'].pvalue)

        result = WikiPage.wikiquery(u'schema:"Book" > author, datePublished-')
        self.assertEqual(u'1982', result[0]['datePublished'].pvalue)
        self.assertEqual(u'1979', result[1]['datePublished'].pvalue)
Exemplo n.º 3
0
    def test_specifying_attr_order(self):
        result = WikiPage.wikiquery(u'schema:"Book" > author, datePublished+')
        self.assertEqual(u'1979', result[0]['datePublished'].pvalue)
        self.assertEqual(u'1982', result[1]['datePublished'].pvalue)

        result = WikiPage.wikiquery(u'schema:"Book" > author, datePublished-')
        self.assertEqual(u'1982', result[0]['datePublished'].pvalue)
        self.assertEqual(u'1979', result[1]['datePublished'].pvalue)
Exemplo n.º 4
0
    def test_specifying_attr(self):
        result = WikiPage.wikiquery(u'"GEB" > author')
        self.assertEqual(u'Douglas Hofstadter', result['author'].pvalue)

        result = WikiPage.wikiquery(u'"GEB" > name, author, datePublished')
        self.assertEqual(u'Douglas Hofstadter', result['author'].pvalue)
        self.assertEqual(u'GEB', result['name'].pvalue)
        self.assertEqual(u'1979', result['datePublished'].pvalue)
Exemplo n.º 5
0
    def test_specifying_attr(self):
        result = WikiPage.wikiquery(u'"GEB" > author')
        self.assertEqual(u'Douglas Hofstadter', result['author'].pvalue)

        result = WikiPage.wikiquery(u'"GEB" > name, author, datePublished')
        self.assertEqual(u'Douglas Hofstadter', result['author'].pvalue)
        self.assertEqual(u'GEB', result['name'].pvalue)
        self.assertEqual(u'1979', result['datePublished'].pvalue)
Exemplo n.º 6
0
 def get(self, path, head=False):
     cache.create_prc()
     query = WikiPage.path_to_title(path)
     user = get_cur_user()
     result = WikiPage.wikiquery(query, user)
     view = self.request.GET.get('view', 'default')
     restype = get_restype(self.request)
     if restype == 'default' or restype == 'html':
         if view == 'bodyonly':
             html = template(self.request, 'bodyonly.html', {
                 'title': u'Search: %s ' % query,
                 'body': obj_to_html(result),
             })
         else:
             html = template(self.request, 'wikiquery.html', {
                 'query': query,
                 'result': obj_to_html(result),
             })
         self.response.headers['Content-Type'] = 'text/html; charset=utf-8'
         set_response_body(self.response, html, head)
     elif restype == 'json':
         self.response.headers[
             'Content-Type'] = 'application/json; charset=utf-8'
         set_response_body(self.response, json.dumps(result), head)
     else:
         self.abort(400, 'Unknown type: %s' % restype)
Exemplo n.º 7
0
 def test_user_with_permission(self):
     user = users.User('*****@*****.**')
     self.assertEqual([{
         u'name': u'A'
     }, {
         u'name': u'B'
     }], WikiPage.wikiquery(u'schema:"Book"', user))
Exemplo n.º 8
0
 def get(self, path, head=False):
     cache.create_prc()
     query = WikiPage.path_to_title(path)
     user = get_cur_user()
     result = WikiPage.wikiquery(query, user)
     view = self.request.GET.get('view', 'default')
     restype = get_restype(self.request)
     if restype == 'default' or restype == 'html':
         if view == 'bodyonly':
             html = template(self.request, 'bodyonly.html', {
                 'title': u'Search: %s ' % query,
                 'body': obj_to_html(result),
             })
         else:
             html = template(self.request, 'wikiquery.html', {
                 'query': query,
                 'result': obj_to_html(result),
             })
         self.response.headers['Content-Type'] = 'text/html; charset=utf-8'
         set_response_body(self.response, html, head)
     elif restype == 'json':
         self.response.headers['Content-Type'] = 'application/json; charset=utf-8'
         set_response_body(self.response, json.dumps(result), head)
     else:
         self.abort(400, 'Unknown type: %s' % restype)
Exemplo n.º 9
0
 def test_complex(self):
     result = WikiPage.wikiquery(
         u'schema:"Thing/CreativeWork/Book/" > name, author')
     self.assertEqual(u'Douglas Hofstadter', result[0]['author'].pvalue)
     self.assertEqual(u'GEB', result[0]['name'].pvalue)
     self.assertEqual([u'Daniel Dennett', u'Douglas Hofstadter'],
                      [v.pvalue for v in result[1]['author']])
     self.assertEqual(u'The Mind\'s I', result[1]['name'].pvalue)
Exemplo n.º 10
0
 def test_by_schema(self):
     self.assertEqual([{
         u'name': u'GEB'
     }, {
         u'name': u'The Mind\'s I'
     }], WikiPage.wikiquery(u'schema:"Thing/CreativeWork/Book/"'))
Exemplo n.º 11
0
 def test_by_name(self):
     self.assertEqual({u'name': u'GEB'}, WikiPage.wikiquery(u'"GEB"'))
Exemplo n.º 12
0
 def test_anonymous(self):
     self.assertEqual({u'name': u'A'},
                      WikiPage.wikiquery(u'schema:"Book" > name'))
Exemplo n.º 13
0
 def test_complex(self):
     self.assertEqual([{u'name': u'The Mind\'s I', u'author': [u'Daniel Dennett', u'Douglas Hofstadter']},
                       {u'author': u'Douglas Hofstadter', u'name': u'GEB'}],
                      WikiPage.wikiquery(u'schema:"Thing/CreativeWork/Book/" > name, author'))
Exemplo n.º 14
0
 def load(self):
     query = WikiPage.path_to_title(self.path)
     return {'result': WikiPage.wikiquery(query, self.user), 'query': query}
Exemplo n.º 15
0
 def test_normal(self):
     self.assertEqual({u'name': u'A'}, WikiPage.wikiquery(u'schema:"Book"'))
Exemplo n.º 16
0
 def load(self):
     query = WikiPage.path_to_title(self.path)
     return {
         'result': WikiPage.wikiquery(query, self.req.user),
         'query': query
     }
Exemplo n.º 17
0
 def test_by_abbr_schema(self):
     self.assertEqual([{u'name': u'The Mind\'s I'}, {u'name': u'GEB'}],
                      WikiPage.wikiquery(u'schema:"Book"'))
Exemplo n.º 18
0
 def test_by_schema(self):
     self.assertEqual([{u'name': u'The Mind\'s I'}, {u'name': u'GEB'}],
                      WikiPage.wikiquery(u'schema:"Thing/CreativeWork/Book/"'))
Exemplo n.º 19
0
 def test_by_name(self):
     self.assertEqual({u'name': u'GEB'},
                      WikiPage.wikiquery(u'"GEB"'))
Exemplo n.º 20
0
 def test_user_with_permission(self):
     user = users.User('*****@*****.**')
     self.assertEqual([{u'name': u'A'}, {u'name': u'B'}],
                      WikiPage.wikiquery(u'schema:"Book"', user))
Exemplo n.º 21
0
 def test_anonymous(self):
     self.assertEqual({u'name': u'A'},
                      WikiPage.wikiquery(u'schema:"Book"', None))
Exemplo n.º 22
0
 def test_by_abbr_schema(self):
     self.assertEqual([{
         u'name': u'GEB'
     }, {
         u'name': u'The Mind\'s I'
     }], WikiPage.wikiquery(u'schema:"Book"'))
Exemplo n.º 23
0
 def test_by_attr(self):
     self.assertEqual([{
         u'name': u'GEB'
     }, {
         u'name': u'The Mind\'s I'
     }], WikiPage.wikiquery(u'author:"Douglas Hofstadter"'))
Exemplo n.º 24
0
 def test_by_attr(self):
     self.assertEqual([{u'name': u'The Mind\'s I'}, {u'name': u'GEB'}],
                      WikiPage.wikiquery(u'author:"Douglas Hofstadter"'))
Exemplo n.º 25
0
 def load(self):
     query = WikiPage.path_to_title(self.path)
     return {"result": WikiPage.wikiquery(query, self.user), "query": query}
Exemplo n.º 26
0
 def test_normal(self):
     self.assertEqual({u'name': u'A'}, WikiPage.wikiquery(u'schema:"Book"'))
Exemplo n.º 27
0
 def test_complex(self):
     result = WikiPage.wikiquery(u'schema:"Thing/CreativeWork/Book/" > name, author')
     self.assertEqual(u'Douglas Hofstadter', result[0]['author'].pvalue)
     self.assertEqual(u'GEB', result[0]['name'].pvalue)
     self.assertEqual([u'Daniel Dennett', u'Douglas Hofstadter'], [v.pvalue for v in result[1]['author']])
     self.assertEqual(u'The Mind\'s I', result[1]['name'].pvalue)
Exemplo n.º 28
0
 def test_specifying_attr(self):
     self.assertEqual({u'author': u'Douglas Hofstadter'},
                      WikiPage.wikiquery(u'"GEB" > author'))
     self.assertEqual({u'author': u'Douglas Hofstadter', u'name': u'GEB', u'datePublished': u'1979'},
                      WikiPage.wikiquery(u'"GEB" > name, author, datePublished'))