summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgecong1973 <ge.cong@zte.com.cn>2018-11-13 16:38:19 -0800
committergecong1973 <ge.cong@zte.com.cn>2018-11-13 17:08:59 -0800
commitc0f34491e91255b186e7351522ab932dcc39cb50 (patch)
treefc7a2abbd3da0eddf16e4ea3b33f6ecdd08c51b4
parent99ba27b359eb3f51fd03a74b585e0a0291c86643 (diff)
Add action update unit test for sql
The patch add action update unit test case Change-Id: I42460db62bcee18877b4bcd01984bfaad2d31f5b
Notes
Notes (review): Code-Review+2: Carl Caihui <cai.hui@zte.com.cn> 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 03:33:40 +0000 Reviewed-on: https://review.openstack.org/617850 Project: openstack/freezer-api Branch: refs/heads/master
-rw-r--r--freezer_api/tests/unit/common.py22
-rw-r--r--freezer_api/tests/unit/sqlalchemy/test_action.py49
2 files changed, 66 insertions, 5 deletions
diff --git a/freezer_api/tests/unit/common.py b/freezer_api/tests/unit/common.py
index 0e13f86..27f36ca 100644
--- a/freezer_api/tests/unit/common.py
+++ b/freezer_api/tests/unit/common.py
@@ -355,6 +355,24 @@ fake_action_1 = {
355 "project_id": "project_id-is-tecs" 355 "project_id": "project_id-is-tecs"
356} 356}
357 357
358fake_action_2 = {
359 "freezer_action":
360 {
361 "action": "restore",
362 "mode": "fs",
363 "src_file": "/home/tecs/project_tecs",
364 "backup_name": "project_tecs_restore",
365 "container": "my_restore_container",
366 },
367 "exit_status": "success",
368 "max_retries": 5,
369 "max_retries_interval": 70,
370 "mandatory": False,
371 "action_id": "qwerqwerqwerrewq",
372 "user_id": "user_id-is-provided-by-keystone",
373 "project_id": "project_id-is-tecs"
374}
375
358 376
359def get_fake_action_0(): 377def get_fake_action_0():
360 return copy.deepcopy(fake_action_0) 378 return copy.deepcopy(fake_action_0)
@@ -364,6 +382,10 @@ def get_fake_action_1():
364 return copy.deepcopy(fake_action_1) 382 return copy.deepcopy(fake_action_1)
365 383
366 384
385def get_fake_action_2():
386 return copy.deepcopy(fake_action_2)
387
388
367fake_session_0 = { 389fake_session_0 = {
368 "session_id": 'turistidellademocrazia', 390 "session_id": 'turistidellademocrazia',
369 "session_tag": 5, 391 "session_tag": 5,
diff --git a/freezer_api/tests/unit/sqlalchemy/test_action.py b/freezer_api/tests/unit/sqlalchemy/test_action.py
index 8af4897..ca5a1bf 100644
--- a/freezer_api/tests/unit/sqlalchemy/test_action.py
+++ b/freezer_api/tests/unit/sqlalchemy/test_action.py
@@ -26,17 +26,20 @@ class DbActionTestCase(base.DbTestCase):
26 def setUp(self): 26 def setUp(self):
27 super(DbActionTestCase, self).setUp() 27 super(DbActionTestCase, self).setUp()
28 self.fake_action_0 = common.get_fake_action_0() 28 self.fake_action_0 = common.get_fake_action_0()
29 self.fake_action_2 = common.get_fake_action_2()
29 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')
32 self.fake_project_id = self.fake_action_0.get('project_id')
30 33
31 def test_add_and_get_action(self): 34 def test_add_and_get_action(self):
32 action_doc = copy.deepcopy(self.fake_action_0) 35 action_doc = copy.deepcopy(self.fake_action_0)
33 action_id = self.dbapi.add_action(user_id=self.fake_action_0. 36 action_id = self.dbapi.add_action(user_id=self.fake_action_0.
34 get('user_id'), 37 get('user_id'),
35 doc=action_doc, 38 doc=action_doc,
36 project_id="myproject") 39 project_id=self.fake_project_id)
37 self.assertIsNotNone(action_id) 40 self.assertIsNotNone(action_id)
38 41
39 result = self.dbapi.get_action(project_id="myproject", 42 result = self.dbapi.get_action(project_id=self.fake_project_id,
40 user_id=self.fake_action_0. 43 user_id=self.fake_action_0.
41 get('user_id'), 44 get('user_id'),
42 action_id=action_id) 45 action_id=action_id)
@@ -71,10 +74,10 @@ class DbActionTestCase(base.DbTestCase):
71 action_id = self.dbapi.add_action(user_id=self.fake_action_0. 74 action_id = self.dbapi.add_action(user_id=self.fake_action_0.
72 get('user_id'), 75 get('user_id'),
73 doc=action_doc, 76 doc=action_doc,
74 project_id="myproject") 77 project_id=self.fake_project_id)
75 self.assertIsNotNone(action_id) 78 self.assertIsNotNone(action_id)
76 79
77 result = self.dbapi.delete_action(project_id="myproject", 80 result = self.dbapi.delete_action(project_id=self.fake_project_id,
78 user_id=self.fake_action_0. 81 user_id=self.fake_action_0.
79 get('user_id'), 82 get('user_id'),
80 action_id=action_id) 83 action_id=action_id)
@@ -83,9 +86,45 @@ class DbActionTestCase(base.DbTestCase):
83 86
84 self.assertEqual(result, action_id) 87 self.assertEqual(result, action_id)
85 88
86 result = self.dbapi.get_action(project_id="myproject", 89 result = self.dbapi.get_action(project_id=self.fake_project_id,
87 user_id=self.fake_action_0. 90 user_id=self.fake_action_0.
88 get('user_id'), 91 get('user_id'),
89 action_id=action_id) 92 action_id=action_id)
90 93
91 self.assertEqual(len(result), 0) 94 self.assertEqual(len(result), 0)
95
96 def test_add_and_update_action(self):
97 action_doc = copy.deepcopy(self.fake_action_0)
98 action_id = self.dbapi.add_action(user_id=self.fake_action_0.
99 get('user_id'),
100 doc=action_doc,
101 project_id=self.fake_project_id)
102 self.assertIsNotNone(action_id)
103
104 patch_doc = copy.deepcopy(self.fake_action_2)
105
106 result = self.dbapi.update_action(project_id=self.fake_project_id,
107 user_id=self.fake_action_2.
108 get('user_id'),
109 patch_doc=patch_doc,
110 action_id=action_id)
111
112 self.assertIsNotNone(result)
113
114 self.assertEqual(result, action_id)
115
116 result = self.dbapi.get_action(project_id=self.fake_project_id,
117 user_id=self.fake_action_2.
118 get('user_id'),
119 action_id=action_id)
120
121 self.assertEqual(result.get('max_retries'),
122 self.fake_action_2.get('max_retries'))
123
124 self.assertEqual(result.get('max_retries_interval'),
125 self.fake_action_2.get('max_retries_interval'))
126
127 freezer_action = result.get('freezer_action')
128
129 self.assertEqual(freezer_action.get('action'),
130 self.freezer_action_2.get('action'))