Mercurial > hg > ltpdarepo
view src/ltpdarepo/tests/test_query.py @ 184:c52ae3f0196f
Make named queries store ordering and work for timeseries searches.
author | Daniele Nicolodi <daniele@grinta.net> |
---|---|
date | Tue, 08 Nov 2011 12:22:17 +0100 |
parents | 5bf7dc63466d |
children | fefbc0193dbe |
line wrap: on
line source
import re import unittest2 as unittest from ltpdarepo.tests.utils import RequestContextTestCase from ltpdarepo.query import Query USERNAME, PASSWORD = 'u1', 'u1' class DatabaseTestCase(RequestContextTestCase): @classmethod def setUpClass(self): from ltpdarepo.admin import wipe, setup wipe() setup() @classmethod def tearDownClass(self): from ltpdarepo.admin import wipe wipe() def test_query(self): # create query = Query(title='Query', db='^(db1)$', query='{"query": [["id", ">", 0]], "order": ["id", 0]}') id = query.create() self.assertEqual(id, 1) # load query = Query.load(id) self.assertEqual(query.title, 'Query') self.assertEqual(query.db, '^(db1)$') self.assertEqual(query.query, '{"query": [["id", ">", 0]], "order": ["id", 0]}') # edit query.title = 'yreuQ' query.db = '^(db1|db2)$' query.query = '{"query": [["id", ">", 0], ["name", "LIKE", "%"]], "order": ["id", 0]}' query.save() # check query = Query.load(id) self.assertEqual(query.title, 'yreuQ') self.assertEqual(query.db, '^(db1|db2)$') self.assertEqual(query.query, '{"query": [["id", ">", 0], ["name", "LIKE", "%"]], "order": ["id", 0]}') # drop query = Query.load(id) query.drop() query = Query.load(id) self.assertIsNone(query) # __str__ query = Query(title='', db='', query='{"query": [["id", ">", 0], ["name", "LIKE", "%"]], "order": ["id", 0]}') self.assertEqual(unicode(query), u"id > '0' AND name LIKE '%' ORDER BY id") query = Query(title='', db='', query='{"query": [["id", ">", 0], ["name", "LIKE", "%"]], "order": ["id", 1]}') self.assertEqual(unicode(query), u"id > '0' AND name LIKE '%' ORDER BY id DESC") query = Query(title='', db='', query='{"query": [["id", ">", 0]], "times": ["1970-01-01", "1970-02-02"], "order": ["id", 0]}') self.assertEqual(unicode(query), u"time BETWEEN '1970-01-01' AND '1970-02-02' AND id > '0' ORDER BY id")