Browse Source

Add action update unit test for sql

The patch add action update unit test case

Change-Id: I42460db62bcee18877b4bcd01984bfaad2d31f5b
tags/7.0.0
gecong1973 6 months ago
parent
commit
c0f34491e9
2 changed files with 66 additions and 5 deletions
  1. 22
    0
      freezer_api/tests/unit/common.py
  2. 44
    5
      freezer_api/tests/unit/sqlalchemy/test_action.py

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

@@ -355,6 +355,24 @@ fake_action_1 = {
355 355
     "project_id": "project_id-is-tecs"
356 356
 }
357 357
 
358
+fake_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
 
359 377
 def get_fake_action_0():
360 378
     return copy.deepcopy(fake_action_0)
@@ -364,6 +382,10 @@ def get_fake_action_1():
364 382
     return copy.deepcopy(fake_action_1)
365 383
 
366 384
 
385
+def get_fake_action_2():
386
+    return copy.deepcopy(fake_action_2)
387
+
388
+
367 389
 fake_session_0 = {
368 390
     "session_id": 'turistidellademocrazia',
369 391
     "session_tag": 5,

+ 44
- 5
freezer_api/tests/unit/sqlalchemy/test_action.py View File

@@ -26,17 +26,20 @@ class DbActionTestCase(base.DbTestCase):
26 26
     def setUp(self):
27 27
         super(DbActionTestCase, self).setUp()
28 28
         self.fake_action_0 = common.get_fake_action_0()
29
+        self.fake_action_2 = common.get_fake_action_2()
29 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 34
     def test_add_and_get_action(self):
32 35
         action_doc = copy.deepcopy(self.fake_action_0)
33 36
         action_id = self.dbapi.add_action(user_id=self.fake_action_0.
34 37
                                           get('user_id'),
35 38
                                           doc=action_doc,
36
-                                          project_id="myproject")
39
+                                          project_id=self.fake_project_id)
37 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 43
                                        user_id=self.fake_action_0.
41 44
                                        get('user_id'),
42 45
                                        action_id=action_id)
@@ -71,10 +74,10 @@ class DbActionTestCase(base.DbTestCase):
71 74
         action_id = self.dbapi.add_action(user_id=self.fake_action_0.
72 75
                                           get('user_id'),
73 76
                                           doc=action_doc,
74
-                                          project_id="myproject")
77
+                                          project_id=self.fake_project_id)
75 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 81
                                           user_id=self.fake_action_0.
79 82
                                           get('user_id'),
80 83
                                           action_id=action_id)
@@ -83,9 +86,45 @@ class DbActionTestCase(base.DbTestCase):
83 86
 
84 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 90
                                        user_id=self.fake_action_0.
88 91
                                        get('user_id'),
89 92
                                        action_id=action_id)
90 93
 
91 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'))

Loading…
Cancel
Save