# HG changeset patch # User Daniele Nicolodi # Date 1318582646 -7200 # Node ID 5bf7dc63466d12415dbfa863d18f3ab827f325ad # Parent 1944c8ad80cbe49d3a23de404f2d44cdf4f6cd42 Test named queries management interface. diff -r 1944c8ad80cb -r 5bf7dc63466d src/ltpdarepo/tests/manage-queries.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/ltpdarepo/tests/manage-queries.txt Fri Oct 14 10:57:26 2011 +0200 @@ -0,0 +1,135 @@ +Test setup:: + + >>> from urllib import urlencode + >>> from ltpdarepo.tests.utils import Browser + >>> USERNAME, PASSWORD = 'u1', 'u1' + >>> browser = Browser() + +Login:: + + >>> browser.login(USERNAME, PASSWORD) + +Create query that performs the query "id > 0 AND name LIKE '%'". Skip +Javascript interface to build query: start with an urlencoded form of +the query parameters:: + + >>> params = urlencode((('field', 'id'),('operator', '>'),('value', '0'), + ... ('field', 'name'),('operator', 'LIKE'),('value', '%'))) + >>> data = urlencode({'query': params, 'db': 'db1'}) + +Post to the named query creation form:: + + >>> browser.post('/manage/queries/+', data) + >>> browser.url + 'http://localhost/manage/queries/+' + +The form contains the proper query representation in JSON format:: + + >>> browser.getControl(name='query').value + '[["id", ">", 0], ["name", "LIKE", "%"]]' + +Save query setting title and the databases where it operates:: + + >>> browser.getControl(name='title').value = 'Query' + >>> browser.getControl(name='db').value = 'db1' + >>> browser.getControl(name='submit').click() + >>> browser.url + 'http://localhost/manage/queries/' + +View:: + + >>> browser.getLink('Query').click() + >>> browser.url + 'http://localhost/manage/queries/1/' + >>> browser.contents + '...

Query «Query»

...' + >>> browser.contents + '...

Database: ^(db1)$

...' + >>> browser.contents + '...

Query: id > \'0\' AND name LIKE \'%\'

...' + +Edit:: + + >>> browser.getLink('Edit').click() + >>> browser.url + 'http://localhost/manage/queries/1/edit' + +Test databases regular epxression validation:: + + >>> browser.getControl(name='db').value = 'db1)' + >>> browser.getControl(name='submit').click() + >>> browser.url + 'http://localhost/manage/queries/1/edit' + >>> browser.contents + '...span class="error">Invalid regular expression: unbalanced parenthesis...' + +Enter proper values:: + + >>> browser.getControl(name='title').value = 'yreuQ' + >>> browser.getControl(name='db').value = 'db1, db2' + >>> browser.getControl(name='submit').click() + >>> browser.url + 'http://localhost/manage/queries/1/' + >>> browser.contents + '...

Query «yreuQ»

...' + >>> browser.contents + '...

Database: ^(db1|db2)$

...' + +Drop can be cancelled:: + + >>> browser.getLink('Drop').click() + >>> browser.url + 'http://localhost/manage/queries/1/drop' + + >>> browser.getControl(name='cancel').click() + >>> browser.url + 'http://localhost/manage/queries/1/' + >>> browser.contents + '...
Operation cancelled.
...' + +Drop:: + + >>> browser.getLink('Drop').click() + >>> browser.url + 'http://localhost/manage/queries/1/drop' + >>> browser.getControl(name='ok').click() + >>> browser.url + 'http://localhost/manage/queries/' + >>> browser.contents + '...
Named query deleted.
...' + + +Create a new query for database 'db1':: + + >>> browser.post('/manage/queries/+', data) + >>> browser.getControl(name='title').value = 'Query' + >>> browser.getControl(name='db').value = 'db1' + >>> browser.getControl(name='submit').click() + >>> browser.getLink('Query').click() + >>> browser.url + 'http://localhost/manage/queries/2/' + +Check that it is available on database 'db1' browsing interface:: + + >>> browser.open('/browse/db1/') + >>> browser.getLink('Query').click() + >>> browser.url + 'http://localhost/browse/db1/query/2' + +Edit to make quary available for database 'db2' only:: + + >>> browser.open('http://localhost/manage/queries/2/edit') + >>> browser.getControl(name='db').value = 'db2' + >>> browser.getControl(name='submit').click() + +Check that the query is no longer available on database 'db1' browsing interface:: + + >>> browser.open('/browse/db1/') + >>> browser.getLink('Query').click() + Traceback (most recent call last): + LinkNotFoundError + + +# Local Variables: +# mode: doctest +# End: diff -r 1944c8ad80cb -r 5bf7dc63466d src/ltpdarepo/tests/test_doctests.py --- a/src/ltpdarepo/tests/test_doctests.py Fri Oct 14 10:34:47 2011 +0200 +++ b/src/ltpdarepo/tests/test_doctests.py Fri Oct 14 10:57:26 2011 +0200 @@ -26,6 +26,7 @@ 'browse-database.txt', 'manage-users.txt', 'manage-databases.txt', + 'manage-queries.txt', setUp=doctestSetUp, tearDown=doctestTearDown, optionflags=doctest.ELLIPSIS | doctest.REPORT_ONLY_FIRST_FAILURE)) return suite diff -r 1944c8ad80cb -r 5bf7dc63466d src/ltpdarepo/tests/test_query.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/ltpdarepo/tests/test_query.py Fri Oct 14 10:57:26 2011 +0200 @@ -0,0 +1,56 @@ +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='[["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, '[["id", ">", 0]]') + + # edit + query.title = 'yreuQ' + query.db = '^(db1|db2)$' + query.query = '[["id", ">", 0], ["name", "LIKE", "%"]]' + query.save() + + # check + query = Query.load(id) + self.assertEqual(query.title, 'yreuQ') + self.assertEqual(query.db, '^(db1|db2)$') + self.assertEqual(query.query, '[["id", ">", 0], ["name", "LIKE", "%"]]') + + # drop + query = Query.load(id) + query.drop() + query = Query.load(id) + self.assertIsNone(query) + + # tostring + query = Query(title='Query', db='^(db1)$', query='[["id", ">", 0], ["name", "LIKE", "%"]]') + string = query.tostring() + self.assertEqual(unicode(string), u"id_>_'0' AND_name_LIKE_'%'".replace('_', ' '))