Browse Source

Add job search unit test for sqlalchemy

The patch add search unit test

Change-Id: Ica563467d859995dfeedaaa6061150780e092626
tags/7.0.0
gengchc2 6 months ago
parent
commit
3aa1b1dc12
2 changed files with 77 additions and 0 deletions
  1. 48
    0
      freezer_api/tests/unit/common.py
  2. 29
    0
      freezer_api/tests/unit/sqlalchemy/test_job.py

+ 48
- 0
freezer_api/tests/unit/common.py View File

@@ -282,6 +282,50 @@ fake_job_2 = {
282 282
     "description": "test action 5"
283 283
 }
284 284
 
285
+fake_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
 
286 330
 def get_fake_job_0():
287 331
     return copy.deepcopy(fake_job_0)
@@ -297,6 +341,10 @@ def get_fake_job_2():
297 341
     return copy.deepcopy(fake_job_2)
298 342
 
299 343
 
344
+def get_fake_job_3():
345
+    return copy.deepcopy(fake_job_3)
346
+
347
+
300 348
 def get_fake_job_id():
301 349
     return uuid.uuid4().hex
302 350
 

+ 29
- 0
freezer_api/tests/unit/sqlalchemy/test_job.py View File

@@ -31,6 +31,8 @@ class DbJobTestCase(base.DbTestCase):
31 31
         self.fake_job_0.pop('job_id')
32 32
         self.fake_job_2 = common.get_fake_job_2()
33 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 36
         self.fake_project_id = self.fake_job_0.get('project_id')
35 37
         self.fake_job_id = common.get_fake_job_id()
36 38
 
@@ -156,3 +158,30 @@ class DbJobTestCase(base.DbTestCase):
156 158
         self.assertIsNotNone(result)
157 159
 
158 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'])

Loading…
Cancel
Save