# HG changeset patch # User Daniele Nicolodi # Date 1324058952 -3600 # Node ID 32c4e938787eedea03c562107df00a50b2be3090 # Parent 6b8153a4537ea75c501d4b4c5f42c6759931edfb Extend tests. diff -r 6b8153a4537e -r 32c4e938787e src/ltpdarepo/tests/browse-activity.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/ltpdarepo/tests/browse-activity.txt Fri Dec 16 19:09:12 2011 +0100 @@ -0,0 +1,24 @@ +Test setup:: + + >>> from urllib import urlencode + >>> from ltpdarepo.tests.utils import Browser + >>> USERNAME, PASSWORD = 'u1', 'u1' + >>> browser = Browser() + >>> browser.login(USERNAME, PASSWORD) + +Actiity view:: + + >>> browser.open('/browse/db1/activity') + +Activity view for specific month:: + + >>> browser.open('/browse/db1/activity/2011-11') + +Activity view for specific day:: + + >>> browser.open('/browse/db1/activity/2011-11-11') + + +# Local Variables: +# mode: doctest +# End: diff -r 6b8153a4537e -r 32c4e938787e src/ltpdarepo/tests/browse-database.txt --- a/src/ltpdarepo/tests/browse-database.txt Fri Dec 16 18:55:20 2011 +0100 +++ b/src/ltpdarepo/tests/browse-database.txt Fri Dec 16 19:09:12 2011 +0100 @@ -60,10 +60,10 @@ Activity view:: - # >>> browser.open('/browse/db1') - # >>> browser.getLink('Show activity').click() - # >>> browser.url - # 'http://localhost/browse/db1/activity' + >>> browser.open('/browse/db1') + >>> browser.getLink('Activity').click() + >>> browser.url + 'http://localhost/browse/db1/activity' # Local Variables: diff -r 6b8153a4537e -r 32c4e938787e src/ltpdarepo/tests/browse-search.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/ltpdarepo/tests/browse-search.txt Fri Dec 16 19:09:12 2011 +0100 @@ -0,0 +1,71 @@ +Test setup:: + + >>> from urllib import urlencode + >>> from ltpdarepo.tests.utils import Browser + >>> USERNAME, PASSWORD = 'u1', 'u1' + >>> browser = Browser() + >>> browser.login(USERNAME, PASSWORD) + +Build a simple query without using the web interface:: + + >>> params = urlencode((('field', 'id'),('operator', '<'),('value', '11'), + ... ('field', 'name'),('operator', 'LIKE'),('value', '%'))) + >>> browser.open('/browse/db1/query?' + params) + +We should obtain 10 objects:: + + >>> browser.contents.count('') + 10 + +Try different query builder interface field type parsers:: + + >>> params = urlencode((('field', 'submitted'),('operator', '>'),('value', '1970-01-01 00:00:00 UTC'), # datetime + ... ('field', 'type'),('operator', '='),('value', 'ao'))) # enum + >>> browser.open('/browse/db1/query?' + params) + +We should obtain all 30 objects:: + + >>> browser.contents.count('') + 30 + +Same query through the timespan search interface:: + + >>> params = urlencode((('field', 'id'),('operator', '<'),('value', '11'), + ... ('field', 'name'),('operator', 'LIKE'),('value', '%'))) + >>> browser.open('/browse/db1/timeseries?' + params) + +We should still obtain 10 objects:: + + >>> browser.contents.count('') + 10 + +Add timespan constraints:: + + >>> params = urlencode((('field', 'id'),('operator', '<'),('value', '11'), + ... ('field', 'name'),('operator', 'LIKE'),('value', '%'), + ... ('t1', '1970-01-01 00:00:00 UTC'), + ... ('t2', '1970-01-01 00:10:00 UTC'))) + >>> browser.open('/browse/db1/timeseries?' + params) + +This time we should obtain just 7 objects:: + + >>> browser.contents.count('') + 7 + +Timespan constraints in CET timezone:: + + >>> params = urlencode((('field', 'id'),('operator', '<'),('value', '11'), + ... ('field', 'name'),('operator', 'LIKE'),('value', '%'), + ... ('t1', '1970-01-01 01:00:00 CET'), + ... ('t2', '1970-01-01 01:10:00 CET'))) + >>> browser.open('/browse/db1/timeseries?' + params) + +We should obtain the same 7 objects:: + + >>> browser.contents.count('') + 7 + + +# Local Variables: +# mode: doctest +# End: diff -r 6b8153a4537e -r 32c4e938787e src/ltpdarepo/tests/manage-databases.txt --- a/src/ltpdarepo/tests/manage-databases.txt Fri Dec 16 18:55:20 2011 +0100 +++ b/src/ltpdarepo/tests/manage-databases.txt Fri Dec 16 19:09:12 2011 +0100 @@ -82,7 +82,7 @@ >>> app.privileges('u1', 'database1') {'insert': True, 'update': False, 'select': True, 'delete': False} -that the form is updated accordingly:: +and that the form is updated accordingly:: >>> browser.follow('Permissions') >>> browser.getControl(name='u1:select').value diff -r 6b8153a4537e -r 32c4e938787e src/ltpdarepo/tests/manage-queries.txt --- a/src/ltpdarepo/tests/manage-queries.txt Fri Dec 16 18:55:20 2011 +0100 +++ b/src/ltpdarepo/tests/manage-queries.txt Fri Dec 16 19:09:12 2011 +0100 @@ -128,6 +128,30 @@ Traceback (most recent call last): LinkNotFoundError +Checkj that queries built from the timeseries search interface +properly record the time parameters and link to the correct view. To +do so add 't1' and 't2' parameters to query data:: + + >>> params = urlencode((('field', 'id'),('operator', '>'),('value', '0'), + ... ('field', 'name'),('operator', 'LIKE'),('value', '%'), + ... ('t1', '1970-01-01 00:00:00'), + ... ('t2', '1970-01-01 00:10:00'))) + >>> data = urlencode({'query': params, 'db': 'db1'}) + +Post to the named query creation form:: + + >>> browser.post('/manage/queries/+', data) + >>> browser.url + 'http://localhost/manage/queries/+' + +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/' + # Local Variables: # mode: doctest diff -r 6b8153a4537e -r 32c4e938787e src/ltpdarepo/tests/manage-users.txt --- a/src/ltpdarepo/tests/manage-users.txt Fri Dec 16 18:55:20 2011 +0100 +++ b/src/ltpdarepo/tests/manage-users.txt Fri Dec 16 19:09:12 2011 +0100 @@ -119,11 +119,97 @@ >>> browser.url 'http://localhost/' -Drop just created user:: +Test permissions. The user should have no permissions on existing databases:: + + >>> from ltpdarepo import admin + >>> app = admin.Application() + >>> app.privileges('user1', 'db1') + {'insert': False, 'update': False, 'select': False, 'delete': False} + +Assign permissions:: >>> browser.open('/manage/users/user1') >>> browser.url 'http://localhost/manage/users/user1' + >>> browser.follow('Permissions') + >>> browser.url + 'http://localhost/manage/users/user1/permissions' + + >>> browser.getControl(name='db1:select').value = True + >>> browser.getControl(name='db1:insert').value = True + >>> browser.getControl(name='submit').click() + >>> browser.url + 'http://localhost/manage/users/user1' + +Check that the permissions have been updated:: + + >>> app.privileges('user1', 'db1') + {'insert': True, 'update': False, 'select': True, 'delete': False} + + >>> conn = app.connect() + >>> curs = conn.cursor() + >>> rows = curs.execute("SHOW GRANTS FOR 'user1'@'%'") + >>> privs = [row[0] for row in curs.fetchall()] + >>> "GRANT INSERT ON `db1`.`transactions` TO 'user1'@'%'" in privs + True + +and that the form is updated accordingly:: + + >>> browser.follow('Permissions') + >>> browser.getControl(name='db1:select').value + ['Y'] + >>> browser.getControl(name='db1:insert').value + ['Y'] + >>> browser.getControl(name='db1:update').value + [] + >>> browser.getControl(name='db1:delete').value + [] + +and that we can revoke permissions:: + + >>> browser.getControl(name='db1:insert').value = False + >>> browser.getControl(name='submit').click() + >>> browser.url + 'http://localhost/manage/users/user1' + + >>> app.privileges('user1', 'db1') + {'insert': False, 'update': False, 'select': True, 'delete': False} + +even all permissions:: + + >>> browser.follow('Permissions') + >>> browser.getControl(name='db1:select').value = False + >>> browser.getControl(name='submit').click() + >>> browser.url + 'http://localhost/manage/users/user1' + + >>> app.privileges('user1', 'db1') + {'insert': False, 'update': False, 'select': False, 'delete': False} + + >>> conn = app.connect() + >>> curs = conn.cursor() + >>> rows = curs.execute("SHOW GRANTS FOR 'user1'@'%'") + >>> privs = [row[0] for row in curs.fetchall()] + >>> "GRANT INSERT ON `db1`.`transactions` TO 'user1'@'%'" in privs + False + + +Drop operation can be cancelled:: + + >>> browser.open('/manage/users/user1') + >>> browser.url + 'http://localhost/manage/users/user1' + >>> browser.getLink('Drop').click() + >>> browser.url + 'http://localhost/manage/users/user1/drop' + + >>> browser.getControl(name='cancel').click() + >>> browser.url + 'http://localhost/manage/users/user1' + >>> browser.contents + '...
Operation cancelled.
...' + +Drop just created user:: >>> browser.getLink('Drop').click() >>> browser.url @@ -132,6 +218,8 @@ >>> browser.getControl(name='ok').click() >>> browser.url 'http://localhost/manage/users/' + >>> browser.contents + '...
User deleted.
...' View an unexisting object results in a 404 erorr:: @@ -143,6 +231,10 @@ Traceback (most recent call last): HTTPError: HTTP Error 404: NOT FOUND + >>> browser.open('/manage/users/foo/permissions') + Traceback (most recent call last): + HTTPError: HTTP Error 404: NOT FOUND + >>> browser.open('/manage/users/foo/drop') Traceback (most recent call last): HTTPError: HTTP Error 404: NOT FOUND diff -r 6b8153a4537e -r 32c4e938787e src/ltpdarepo/tests/test_doctests.py --- a/src/ltpdarepo/tests/test_doctests.py Fri Dec 16 18:55:20 2011 +0100 +++ b/src/ltpdarepo/tests/test_doctests.py Fri Dec 16 19:09:12 2011 +0100 @@ -24,12 +24,14 @@ suite = unittest.TestSuite() suite.addTest( doctest.DocFileSuite( - 'browse-user.txt', + 'browse-activity.txt', 'browse-database.txt', 'browse-feed.txt', - 'manage-users.txt', + 'browse-search.txt', + 'browse-user.txt', 'manage-databases.txt', 'manage-queries.txt', + 'manage-users.txt', setUp=doctestSetUp, tearDown=doctestTearDown, optionflags=doctest.ELLIPSIS | doctest.REPORT_ONLY_FIRST_FAILURE)) return suite diff -r 6b8153a4537e -r 32c4e938787e src/ltpdarepo/tests/test_objs.py --- a/src/ltpdarepo/tests/test_objs.py Fri Dec 16 18:55:20 2011 +0100 +++ b/src/ltpdarepo/tests/test_objs.py Fri Dec 16 19:09:12 2011 +0100 @@ -1,8 +1,8 @@ from ltpdarepo.tests.utils import RequestContextTestCase -from ltpdarepo.views.browse import Objs +from ltpdarepo.views.browse import Objs, Timeseries -class TestCase(RequestContextTestCase): +class ObjsTestCase(RequestContextTestCase): @classmethod def setUpClass(self): @@ -35,3 +35,38 @@ def test_where(self): objs = Objs(database='db1').filter('obj_id > %s AND obj_id < %s', (10, 20)) self.assertEqual(objs[0]['id'], 11) + + +class TimeseriesTestCase(RequestContextTestCase): + + @classmethod + def setUpClass(self): + from ltpdarepo import admin + app = admin.Application() + app.wipe() + app.setup() + + def test_simple(self): + objs = Timeseries(database='db1') + self.assertEqual(len(objs), objs.count()) + self.assertEqual(len(objs.all()), objs.count()) + + def test_limit(self): + objs = Timeseries(database='db1').limit(20) + self.assertEqual(objs[0]['id'], 1) + self.assertEqual(len(objs.all()), 20) + + objs = Timeseries(database='db1').limit(20, 2) + self.assertEqual(objs[0]['id'], 21) + self.assertEqual(len(objs.all()), 2) + + def test_orderby(self): + objs = Timeseries(database='db1').orderby('objmeta.obj_id') + self.assertEqual(objs[0]['id'], 1) + + objs = Timeseries(database='db1').orderby('objmeta.obj_id', desc=True) + self.assertEqual(objs[0]['id'], 30) + + def test_where(self): + objs = Timeseries(database='db1').filter('objmeta.obj_id > %s AND objmeta.obj_id < %s', (10, 20)) + self.assertEqual(objs[0]['id'], 11)