summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgengchc2 <geng.changcai2@zte.com.cn>2018-12-20 22:02:44 -0800
committergengchc2 <geng.changcai2@zte.com.cn>2018-12-20 22:02:44 -0800
commitac48abe7351fd6fca131a72122819dc5b926fe9b (patch)
tree9b255de89367714bc4b21cec2a0f5d1c7df1fc14
parent2dc322497e1b5c6f05694fc225aba6b4d4f64057 (diff)
Add raise unit test for session in sqlalchemy
Notes
Notes (review): Code-Review+2: gecong <ge.cong@zte.com.cn> Workflow+1: gecong <ge.cong@zte.com.cn> Verified+2: Zuul Submitted-by: Zuul Submitted-at: Fri, 21 Dec 2018 09:06:37 +0000 Reviewed-on: https://review.openstack.org/626816 Project: openstack/freezer-api Branch: refs/heads/master
-rw-r--r--freezer_api/tests/unit/sqlalchemy/v1/test_session.py17
-rw-r--r--freezer_api/tests/unit/sqlalchemy/v2/test_session.py20
2 files changed, 37 insertions, 0 deletions
diff --git a/freezer_api/tests/unit/sqlalchemy/v1/test_session.py b/freezer_api/tests/unit/sqlalchemy/v1/test_session.py
index 8b57c90..3a99254 100644
--- a/freezer_api/tests/unit/sqlalchemy/v1/test_session.py
+++ b/freezer_api/tests/unit/sqlalchemy/v1/test_session.py
@@ -18,8 +18,11 @@
18"""Tests for manipulating job via the DB API""" 18"""Tests for manipulating job via the DB API"""
19 19
20import copy 20import copy
21import mock
22from mock import patch
21from oslo_config import cfg 23from oslo_config import cfg
22 24
25from freezer_api.common import exceptions as freezer_api_exc
23from freezer_api.tests.unit import common 26from freezer_api.tests.unit import common
24from freezer_api.tests.unit.sqlalchemy import base 27from freezer_api.tests.unit.sqlalchemy import base
25 28
@@ -31,6 +34,7 @@ class DbSessionTestCase(base.DbTestCase):
31 def setUp(self): 34 def setUp(self):
32 super(DbSessionTestCase, self).setUp() 35 super(DbSessionTestCase, self).setUp()
33 self.fake_session_0 = common.get_fake_session_0() 36 self.fake_session_0 = common.get_fake_session_0()
37 self.fake_user_id = self.fake_session_0.get('user_id')
34 self.fake_session_0.pop('session_id') 38 self.fake_session_0.pop('session_id')
35 self.fake_session_2 = common.get_fake_session_2() 39 self.fake_session_2 = common.get_fake_session_2()
36 self.fake_session_2.pop('session_id') 40 self.fake_session_2.pop('session_id')
@@ -405,3 +409,16 @@ class DbSessionTestCase(base.DbTestCase):
405 for index in range(len(result)): 409 for index in range(len(result)):
406 sessionmap = result[index] 410 sessionmap = result[index]
407 self.assertEqual(100, sessionmap['hold_off']) 411 self.assertEqual(100, sessionmap['hold_off'])
412
413 @patch('freezer_api.db.sqlalchemy.api.get_session')
414 def test_raise_add_session_exist(self, mock_get_session):
415 mock_get_session.return_value = mock.MagicMock()
416 self.assertRaises(freezer_api_exc.DocumentExists,
417 self.dbapi.add_session, self.fake_user_id,
418 self.fake_session_0)
419
420 def test_raise_update_session_noexist(self):
421 self.assertRaises(freezer_api_exc.DocumentNotFound,
422 self.dbapi.update_session, self.fake_user_id,
423 self.fake_session_id,
424 self.fake_session_0)
diff --git a/freezer_api/tests/unit/sqlalchemy/v2/test_session.py b/freezer_api/tests/unit/sqlalchemy/v2/test_session.py
index ef3e6fe..8b28705 100644
--- a/freezer_api/tests/unit/sqlalchemy/v2/test_session.py
+++ b/freezer_api/tests/unit/sqlalchemy/v2/test_session.py
@@ -18,7 +18,10 @@
18"""Tests for manipulating job via the DB API""" 18"""Tests for manipulating job via the DB API"""
19 19
20import copy 20import copy
21import mock
22from mock import patch
21 23
24from freezer_api.common import exceptions as freezer_api_exc
22from freezer_api.tests.unit import common 25from freezer_api.tests.unit import common
23from freezer_api.tests.unit.sqlalchemy import base 26from freezer_api.tests.unit.sqlalchemy import base
24 27
@@ -28,6 +31,8 @@ class DbSessionTestCase(base.DbTestCase):
28 def setUp(self): 31 def setUp(self):
29 super(DbSessionTestCase, self).setUp() 32 super(DbSessionTestCase, self).setUp()
30 self.fake_session_0 = common.get_fake_session_0() 33 self.fake_session_0 = common.get_fake_session_0()
34 self.fake_project_id = self.fake_session_0.get('project_id')
35 self.fake_user_id = self.fake_session_0.get('user_id')
31 self.fake_session_0.pop('session_id') 36 self.fake_session_0.pop('session_id')
32 self.fake_session_2 = common.get_fake_session_2() 37 self.fake_session_2 = common.get_fake_session_2()
33 self.fake_session_2.pop('session_id') 38 self.fake_session_2.pop('session_id')
@@ -461,3 +466,18 @@ class DbSessionTestCase(base.DbTestCase):
461 for index in range(len(result)): 466 for index in range(len(result)):
462 sessionmap = result[index] 467 sessionmap = result[index]
463 self.assertEqual(100, sessionmap['hold_off']) 468 self.assertEqual(100, sessionmap['hold_off'])
469
470 @patch('freezer_api.db.sqlalchemy.api.get_session')
471 def test_raise_add_session_exist(self, mock_get_session):
472 mock_get_session.return_value = mock.MagicMock()
473 self.assertRaises(freezer_api_exc.DocumentExists,
474 self.dbapi.add_session, self.fake_user_id,
475 self.fake_session_0,
476 project_id=self.fake_project_id)
477
478 def test_raise_update_session_noexist(self):
479 self.assertRaises(freezer_api_exc.DocumentNotFound,
480 self.dbapi.update_session, self.fake_user_id,
481 self.fake_session_id,
482 self.fake_session_0,
483 project_id=self.fake_project_id)