From e5dc6836ca7fe8330fcd62f03b04e5cc605da87a Mon Sep 17 00:00:00 2001 From: Joe <joe@autistici.org> Date: Sat, 11 May 2013 15:41:23 +0200 Subject: [PATCH] added a test for names with slashes (WiP) --- configdb/server/wsgiapp.py | 4 ++-- configdb/tests/db_api_test_base.py | 13 ++++++++++--- configdb/tests/test_cli.py | 12 ++++++++++-- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/configdb/server/wsgiapp.py b/configdb/server/wsgiapp.py index 067cdb8..fa7187d 100644 --- a/configdb/server/wsgiapp.py +++ b/configdb/server/wsgiapp.py @@ -55,14 +55,14 @@ def json_response(fn): True, the result will be found in the 'result' attribute, otherwise the 'error' attribute will contain details about the error. - + Any exception in the wrapped method will be caught and wrapped. """ @functools.wraps(fn) def _json_response_wrapper(*args, **kwargs): try: return jsonify( - {'ok': True, + {'ok': True, 'result': fn(*args, **kwargs)}) except Exception, e: log.exception('exception in url=%s' % request.url) diff --git a/configdb/tests/db_api_test_base.py b/configdb/tests/db_api_test_base.py index 271ee41..3fa992f 100644 --- a/configdb/tests/db_api_test_base.py +++ b/configdb/tests/db_api_test_base.py @@ -15,6 +15,8 @@ class DbApiTestBase(object): a.roles.append(r) r = self.db.create('role', {'name': u'role1b'}, s) a.roles.append(r) + r = self.db.create('role', {'name': u'a/i'}, s) + a.roles.append(r) s.add(a) r2 = self.db.create('role', {'name': u'role2'}, s) @@ -51,6 +53,11 @@ class DbApiTestBase(object): self.api.get, 'whrarggh', 'obz', self.ctx) + def test_get_entity_with_slash(self): + result = self.api.get('role', 'a/i', self.ctx) + self.assertTrue(result is not None) + self.assertEquals('a/i', result.name) + def test_find(self): result = list( self.api.find('host', @@ -94,7 +101,7 @@ class DbApiTestBase(object): def test_find_empty_query(self): result = list( self.api.find('role', {}, self.ctx)) - self.assertEquals(3, len(result)) + self.assertEquals(4, len(result)) def test_find_multiple_criteria(self): result = list( @@ -205,7 +212,7 @@ class DbApiTestBase(object): # self.api.get('host', 'utz', self.ctx).name) # self.assertRaises(exceptions.NotFound, # self.api.get, 'host', 'obz', self.ctx) - + def test_update_modify_relation(self): self.assertTrue( self.api.update('host', 'obz', {'roles': ['role2']}, self.ctx)) @@ -241,7 +248,7 @@ class DbApiTestBase(object): self.assertRaises(exceptions.ValidationError, self.api.update, 'user', 'testuser', - {'last_login': 'not_a_valid_iso_timestamp'}, + {'last_login': 'not_a_valid_iso_timestamp'}, self.ctx) def test_update_unknown_entity_error(self): diff --git a/configdb/tests/test_cli.py b/configdb/tests/test_cli.py index 09a8536..5736d1d 100644 --- a/configdb/tests/test_cli.py +++ b/configdb/tests/test_cli.py @@ -55,7 +55,7 @@ class CliTest(mox.MoxTestBase): def setUp(self): mox.MoxTestBase.setUp(self) - self.mox.StubOutWithMock(connection, 'Connection', + self.mox.StubOutWithMock(connection, 'Connection', use_mock_anything=True) self.mox.StubOutWithMock(os, 'getenv') self._tmpdir = tempfile.mkdtemp() @@ -83,6 +83,15 @@ class CliTest(mox.MoxTestBase): self.assertEquals( 0, cli.main(['host', 'get', 'obz'])) + def test_get_object_with_slash(self): + self._connect() + self.conn.get('host', 'a/i e').AndReturn('ok') + self.mox.ReplayAll() + + self.assertEquals( + 0, cli.main(['host', 'get', 'a/i e'])) + + def test_find_object(self): self._connect() self.conn.find('host', query.Query(name=query.Equals('obz')) @@ -236,4 +245,3 @@ class CliTest(mox.MoxTestBase): self.assertEquals( 0, cli.main( ['audit', '--entity=host', '--object=obz'])) - -- GitLab