summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgengchc2 <geng.changcai2@zte.com.cn>2018-11-18 18:22:31 -0800
committergengchc2 <geng.changcai2@zte.com.cn>2018-11-19 02:53:59 +0000
commit3aa1b1dc120fef444dc2f41fc6dff0e1b7204c68 (patch)
treef9ad54fb88b061e7e5d5e86508a52fa908f3126c
parent8f4a306f3ba3dde4f4fdd244af867dbe61b8151b (diff)
Add job search unit test for sqlalchemy
The patch add search unit test Change-Id: Ica563467d859995dfeedaaa6061150780e092626
Notes
Notes (review): Code-Review+2: Carl Caihui <cai.hui@zte.com.cn> 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: Mon, 19 Nov 2018 06:30:45 +0000 Reviewed-on: https://review.openstack.org/618661 Project: openstack/freezer-api Branch: refs/heads/master
-rw-r--r--freezer_api/tests/unit/common.py48
-rw-r--r--freezer_api/tests/unit/sqlalchemy/test_job.py29
2 files changed, 77 insertions, 0 deletions
diff --git a/freezer_api/tests/unit/common.py b/freezer_api/tests/unit/common.py
index 0c79280..02a8c12 100644
--- a/freezer_api/tests/unit/common.py
+++ b/freezer_api/tests/unit/common.py
@@ -282,6 +282,50 @@ fake_job_2 = {
282 "description": "test action 5" 282 "description": "test action 5"
283} 283}
284 284
285fake_job_3 = {
286 "job_actions": [
287 {
288 "freezer_action": {
289 "action": "backup",
290 "mode": "fs",
291 "src_file": "/home/tylerdurden/project_mayhem",
292 "backup_name": "project_mayhem_backup",
293 "container": "my_backup_container1"
294 },
295 "max_retries": 3,
296 "max_retries_interval": 150,
297 "mandatory": False
298 },
299 {
300 "freezer_action": {
301 "action": "restore",
302 "mode": "fs",
303 "restore_abs_path": "/home/tylerdurden/project_mayhem",
304 "restore_from_host": "node_on_which_backup_was_made",
305 "backup_name": "project_mayhem_backup",
306 "container": "my_backup_container1"
307 },
308 "max_retries": 4,
309 "max_retries_interval": 60,
310 "mandatory": True
311 }
312 ],
313 "job_schedule": {
314 "time_created": 1234,
315 "time_started": 1234,
316 "time_ended": 1234,
317 "status": "stop",
318 "result": "success",
319 "schedule_date": "2015-06-02T16:20:00",
320 "schedule_interval": "14 days"
321 },
322 "job_id": "e7181e5e-2c75-43f8-92c0-c037ae5f11e5",
323 "client_id": "mytenantid_myhostname2",
324 "user_id": "f4db4da085f043059441565720b217c7",
325 "project_id": "tecs",
326 "description": "test action 6"
327}
328
285 329
286def get_fake_job_0(): 330def get_fake_job_0():
287 return copy.deepcopy(fake_job_0) 331 return copy.deepcopy(fake_job_0)
@@ -297,6 +341,10 @@ def get_fake_job_2():
297 return copy.deepcopy(fake_job_2) 341 return copy.deepcopy(fake_job_2)
298 342
299 343
344def get_fake_job_3():
345 return copy.deepcopy(fake_job_3)
346
347
300def get_fake_job_id(): 348def get_fake_job_id():
301 return uuid.uuid4().hex 349 return uuid.uuid4().hex
302 350
diff --git a/freezer_api/tests/unit/sqlalchemy/test_job.py b/freezer_api/tests/unit/sqlalchemy/test_job.py
index 983a445..b13b3f5 100644
--- a/freezer_api/tests/unit/sqlalchemy/test_job.py
+++ b/freezer_api/tests/unit/sqlalchemy/test_job.py
@@ -31,6 +31,8 @@ class DbJobTestCase(base.DbTestCase):
31 self.fake_job_0.pop('job_id') 31 self.fake_job_0.pop('job_id')
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_job_3 = common.get_fake_job_3()
35 self.fake_job_3.pop('job_id')
34 self.fake_project_id = self.fake_job_0.get('project_id') 36 self.fake_project_id = self.fake_job_0.get('project_id')
35 self.fake_job_id = common.get_fake_job_id() 37 self.fake_job_id = common.get_fake_job_id()
36 38
@@ -156,3 +158,30 @@ class DbJobTestCase(base.DbTestCase):
156 self.assertIsNotNone(result) 158 self.assertIsNotNone(result)
157 159
158 self.assertEqual(result, self.fake_job_id) 160 self.assertEqual(result, self.fake_job_id)
161
162 def test_add_and_search_job(self):
163 count = 0
164 jobids = []
165 while (count < 20):
166 doc = copy.deepcopy(self.fake_job_3)
167 job_id = self.dbapi.add_job(user_id=self.fake_job_3.
168 get('user_id'),
169 doc=doc,
170 project_id=self.fake_project_id)
171 self.assertIsNotNone(job_id)
172 jobids.append(job_id)
173 count += 1
174
175 result = self.dbapi.search_job(user_id=self.fake_job_3.
176 get('user_id'),
177 project_id=self.fake_project_id,
178 offset=0,
179 limit=10)
180
181 self.assertIsNotNone(result)
182
183 self.assertEqual(len(result), 10)
184
185 for index in range(len(result)):
186 jobmap = result[index]
187 self.assertEqual(jobids[index], jobmap['job_id'])