summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgengchc2 <geng.changcai2@zte.com.cn>2018-11-18 17:18:01 -0800
committergengchc2 <geng.changcai2@zte.com.cn>2018-11-18 18:20:40 -0800
commit8f4a306f3ba3dde4f4fdd244af867dbe61b8151b (patch)
tree81852ef027f7b395bab5d1dba6a199f21d71ba9a
parent15ef8247f8b9a2987c35372bfc1e15ce631b353d (diff)
Add job replace unit test for sqlalchemy
The patch add replace test case for sqlalchemy Change-Id: Ic0e0b6466e1dddc5be3b1e339572467e71df9a91
Notes
Notes (review): Code-Review+2: gecong <ge.cong@zte.com.cn> Code-Review+2: Carl Caihui <cai.hui@zte.com.cn> Workflow+1: Carl Caihui <cai.hui@zte.com.cn> Verified+2: Zuul Submitted-by: Zuul Submitted-at: Mon, 19 Nov 2018 04:58:04 +0000 Reviewed-on: https://review.openstack.org/618659 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_job.py45
2 files changed, 49 insertions, 0 deletions
diff --git a/freezer_api/tests/unit/common.py b/freezer_api/tests/unit/common.py
index 40cf978..0c79280 100644
--- a/freezer_api/tests/unit/common.py
+++ b/freezer_api/tests/unit/common.py
@@ -297,6 +297,10 @@ def get_fake_job_2():
297 return copy.deepcopy(fake_job_2) 297 return copy.deepcopy(fake_job_2)
298 298
299 299
300def get_fake_job_id():
301 return uuid.uuid4().hex
302
303
300fake_job_0_elasticsearch_found = { 304fake_job_0_elasticsearch_found = {
301 "_id": "e7181e5e-2c75-43f8-92c0-c037ae5f11e4", 305 "_id": "e7181e5e-2c75-43f8-92c0-c037ae5f11e4",
302 "_index": "freezer", 306 "_index": "freezer",
diff --git a/freezer_api/tests/unit/sqlalchemy/test_job.py b/freezer_api/tests/unit/sqlalchemy/test_job.py
index a33c279..983a445 100644
--- a/freezer_api/tests/unit/sqlalchemy/test_job.py
+++ b/freezer_api/tests/unit/sqlalchemy/test_job.py
@@ -32,6 +32,7 @@ class DbJobTestCase(base.DbTestCase):
32 self.fake_job_2 = common.get_fake_job_2() 32 self.fake_job_2 = common.get_fake_job_2()
33 self.fake_job_2.pop('job_id') 33 self.fake_job_2.pop('job_id')
34 self.fake_project_id = self.fake_job_0.get('project_id') 34 self.fake_project_id = self.fake_job_0.get('project_id')
35 self.fake_job_id = common.get_fake_job_id()
35 36
36 def test_add_and_get_job(self): 37 def test_add_and_get_job(self):
37 job_doc = copy.deepcopy(self.fake_job_0) 38 job_doc = copy.deepcopy(self.fake_job_0)
@@ -111,3 +112,47 @@ class DbJobTestCase(base.DbTestCase):
111 get('schedule_interval')) 112 get('schedule_interval'))
112 self.assertEqual(result.get('job_actions'), 113 self.assertEqual(result.get('job_actions'),
113 self.fake_job_2.get('job_actions')) 114 self.fake_job_2.get('job_actions'))
115
116 def test_add_and_replace_job(self):
117 job_doc = copy.deepcopy(self.fake_job_0)
118 job_id = self.dbapi.add_job(user_id=self.fake_job_0.get('user_id'),
119 doc=job_doc,
120 project_id=self.fake_project_id)
121 self.assertIsNotNone(job_id)
122
123 patch_doc = copy.deepcopy(self.fake_job_2)
124 result = self.dbapi.replace_job(user_id=self.
125 fake_job_2.get('user_id'),
126 job_id=job_id,
127 doc=patch_doc,
128 project_id=self.fake_project_id)
129
130 self.assertIsNotNone(result)
131 self.assertEqual(result, job_id)
132
133 result = self.dbapi.get_job(project_id=self.fake_project_id,
134 user_id=self.fake_job_2.get('user_id'),
135 job_id=job_id)
136
137 self.assertIsNotNone(result)
138 self.assertEqual(result.get('client_id'),
139 self.fake_job_2.get('client_id'))
140 self.assertEqual(result.get('description'),
141 self.fake_job_2.get('description'))
142 self.assertEqual(result.get('job_schedule').
143 get('schedule_interval'),
144 self.fake_job_2.get('job_schedule').
145 get('schedule_interval'))
146 self.assertEqual(result.get('job_actions'),
147 self.fake_job_2.get('job_actions'))
148
149 patch_doc1 = copy.deepcopy(self.fake_job_0)
150
151 result = self.dbapi.replace_job(user_id=self.
152 fake_job_2.get('user_id'),
153 job_id=self.fake_job_id,
154 doc=patch_doc1,
155 project_id=self.fake_project_id)
156 self.assertIsNotNone(result)
157
158 self.assertEqual(result, self.fake_job_id)