summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgecong1973 <ge.cong@zte.com.cn>2018-11-13 19:45:24 -0800
committergecong1973 <ge.cong@zte.com.cn>2018-11-13 19:45:24 -0800
commitc084016deecefdb472dff9d3c3be3c48f031817e (patch)
tree69eb09623dc6fd85bbfec03bf786441619bc98f1
parentc0f34491e91255b186e7351522ab932dcc39cb50 (diff)
Add action replace unit test for sql
The patch add replace test case for sqlalchemy Change-Id: I78c648f6bbf8a05f8357dc9001e420fae74e307b
Notes
Notes (review): Code-Review+2: gengchc2 <geng.changcai2@zte.com.cn> Workflow+1: gengchc2 <geng.changcai2@zte.com.cn> Verified+2: Zuul Submitted-by: Zuul Submitted-at: Wed, 14 Nov 2018 08:29:41 +0000 Reviewed-on: https://review.openstack.org/617868 Project: openstack/freezer-api Branch: refs/heads/master
-rw-r--r--freezer_api/tests/unit/common.py4
-rw-r--r--freezer_api/tests/unit/sqlalchemy/test_action.py48
2 files changed, 52 insertions, 0 deletions
diff --git a/freezer_api/tests/unit/common.py b/freezer_api/tests/unit/common.py
index 27f36ca..1357274 100644
--- a/freezer_api/tests/unit/common.py
+++ b/freezer_api/tests/unit/common.py
@@ -19,6 +19,7 @@ limitations under the License.
19import copy 19import copy
20import io 20import io
21import os 21import os
22import uuid
22 23
23import fixtures 24import fixtures
24from oslo_config import cfg 25from oslo_config import cfg
@@ -386,6 +387,9 @@ def get_fake_action_2():
386 return copy.deepcopy(fake_action_2) 387 return copy.deepcopy(fake_action_2)
387 388
388 389
390def get_fake_action_id():
391 return uuid.uuid4().hex
392
389fake_session_0 = { 393fake_session_0 = {
390 "session_id": 'turistidellademocrazia', 394 "session_id": 'turistidellademocrazia',
391 "session_tag": 5, 395 "session_tag": 5,
diff --git a/freezer_api/tests/unit/sqlalchemy/test_action.py b/freezer_api/tests/unit/sqlalchemy/test_action.py
index ca5a1bf..3b8d8cb 100644
--- a/freezer_api/tests/unit/sqlalchemy/test_action.py
+++ b/freezer_api/tests/unit/sqlalchemy/test_action.py
@@ -30,6 +30,7 @@ class DbActionTestCase(base.DbTestCase):
30 self.freezer_action_0 = self.fake_action_0.get('freezer_action') 30 self.freezer_action_0 = self.fake_action_0.get('freezer_action')
31 self.freezer_action_2 = self.fake_action_2.get('freezer_action') 31 self.freezer_action_2 = self.fake_action_2.get('freezer_action')
32 self.fake_project_id = self.fake_action_0.get('project_id') 32 self.fake_project_id = self.fake_action_0.get('project_id')
33 self.fake_action_id = common.get_fake_action_id()
33 34
34 def test_add_and_get_action(self): 35 def test_add_and_get_action(self):
35 action_doc = copy.deepcopy(self.fake_action_0) 36 action_doc = copy.deepcopy(self.fake_action_0)
@@ -128,3 +129,50 @@ class DbActionTestCase(base.DbTestCase):
128 129
129 self.assertEqual(freezer_action.get('action'), 130 self.assertEqual(freezer_action.get('action'),
130 self.freezer_action_2.get('action')) 131 self.freezer_action_2.get('action'))
132
133 def test_add_and_replace_action(self):
134 action_doc = copy.deepcopy(self.fake_action_0)
135 action_id = self.dbapi.add_action(user_id=self.fake_action_0.
136 get('user_id'),
137 doc=action_doc,
138 project_id=self.fake_project_id)
139 self.assertIsNotNone(action_id)
140
141 patch_doc = copy.deepcopy(self.fake_action_2)
142
143 result = self.dbapi.replace_action(project_id=self.fake_project_id,
144 user_id=self.fake_action_2.
145 get('user_id'),
146 doc=patch_doc,
147 action_id=action_id)
148
149 self.assertIsNotNone(result)
150
151 self.assertEqual(result, action_id)
152
153 result = self.dbapi.get_action(project_id=self.fake_project_id,
154 user_id=self.fake_action_2.
155 get('user_id'),
156 action_id=action_id)
157
158 self.assertEqual(result.get('max_retries'),
159 self.fake_action_2.get('max_retries'))
160
161 self.assertEqual(result.get('max_retries_interval'),
162 self.fake_action_2.get('max_retries_interval'))
163
164 freezer_action = result.get('freezer_action')
165
166 self.assertEqual(freezer_action.get('action'),
167 self.freezer_action_2.get('action'))
168
169 patch_doc1 = copy.deepcopy(self.fake_action_0)
170
171 result = self.dbapi.replace_action(project_id=self.fake_project_id,
172 user_id=self.fake_action_2.
173 get('user_id'),
174 doc=patch_doc1,
175 action_id=self.fake_action_id)
176 self.assertIsNotNone(result)
177
178 self.assertEqual(result, self.fake_action_id)