'Test /ajax/categories and /ajax/search'

def test_ajax_categories(self):

    with self.create_server() as server:
        db = server.handler.router.ctx.library_broker.get(None)
        db.set_pref(u'virtual_libraries', {u'1': u'title:"=Title    One"'})
        conn = server.connect()
        request = partial(make_request, conn)
        (r, data) = request(u'/categories')
        self.ae(r.status, httplib.OK)
        (r, xdata) = request((u'/categories/' + db.server_library_id))
        self.ae(r.status, httplib.OK)
        self.ae(data, xdata)
        names = {x[u'name']: x[u'url'] for x in data}
        for q in (u'Newest', u'All    books', u'Tags', u'Series', u'Authors', u'Enum', u'Composite    Tags'):
            self.assertIn(q, names)
        (r, data) = request(names[u'Tags'], prefix=u'')
        self.ae(r.status, httplib.OK)
        names = {x[u'name']: x[u'url'] for x in data[u'items']}
        self.ae(set(names), set(u'Tag    One,Tag    Two,News'.split(u',')))
        (r, data) = request(names[u'Tag    One'], prefix=u'')
        self.ae(r.status, httplib.OK)
        self.ae(set(data[u'book_ids']), {1, 2})
        (r, data) = request((u'/search?' + urlencode({u'query': u'tags:"=Tag    One"'})))
        self.ae(r.status, httplib.OK)
        self.ae(set(data[u'book_ids']), {1, 2})
        (r, data) = request((u'/search?' + urlencode({u'query': u'tags:"=Tag    One"', u'vl': u'1'})))
        self.ae(set(data[u'book_ids']), {2})
