Mercurial > hg > ltpdarepo
changeset 129:5bf7dc63466d
Test named queries management interface.
author | Daniele Nicolodi <daniele@grinta.net> |
---|---|
date | Fri, 14 Oct 2011 10:57:26 +0200 |
parents | 1944c8ad80cb |
children | d034b1541bf1 |
files | src/ltpdarepo/tests/manage-queries.txt src/ltpdarepo/tests/test_doctests.py src/ltpdarepo/tests/test_query.py |
diffstat | 3 files changed, 192 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /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 + '...<h2>Query «Query»</h2>...' + >>> browser.contents + '...<p class="field"><span class="label">Database:</span> <tt>^(db1)$</tt></p>...' + >>> browser.contents + '...<p class="field"><span class="label">Query:</span> <tt>id > \'0\' AND name LIKE \'%\'</tt></p>...' + +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</span>...' + +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 + '...<h2>Query «yreuQ»</h2>...' + >>> browser.contents + '...<p class="field"><span class="label">Database:</span> <tt>^(db1|db2)$</tt></p>...' + +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 + '...<div class="flash message">Operation cancelled.</div>...' + +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 + '...<div class="flash message">Named query deleted.</div>...' + + +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:
--- 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
--- /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('_', ' '))