Browse Source

Add action replace unit test for sql

The patch add replace test case for sqlalchemy

Change-Id: I78c648f6bbf8a05f8357dc9001e420fae74e307b
tags/7.0.0
gecong1973 6 months ago
parent
commit
c084016dee
2 changed files with 52 additions and 0 deletions
  1. 4
    0
      freezer_api/tests/unit/common.py
  2. 48
    0
      freezer_api/tests/unit/sqlalchemy/test_action.py

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

@@ -19,6 +19,7 @@ limitations under the License.
19 19
 import copy
20 20
 import io
21 21
 import os
22
+import uuid
22 23
 
23 24
 import fixtures
24 25
 from oslo_config import cfg
@@ -386,6 +387,9 @@ def get_fake_action_2():
386 387
     return copy.deepcopy(fake_action_2)
387 388
 
388 389
 
390
+def get_fake_action_id():
391
+    return uuid.uuid4().hex
392
+
389 393
 fake_session_0 = {
390 394
     "session_id": 'turistidellademocrazia',
391 395
     "session_tag": 5,

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

@@ -30,6 +30,7 @@ class DbActionTestCase(base.DbTestCase):
30 30
         self.freezer_action_0 = self.fake_action_0.get('freezer_action')
31 31
         self.freezer_action_2 = self.fake_action_2.get('freezer_action')
32 32
         self.fake_project_id = self.fake_action_0.get('project_id')
33
+        self.fake_action_id = common.get_fake_action_id()
33 34
 
34 35
     def test_add_and_get_action(self):
35 36
         action_doc = copy.deepcopy(self.fake_action_0)
@@ -128,3 +129,50 @@ class DbActionTestCase(base.DbTestCase):
128 129
 
129 130
         self.assertEqual(freezer_action.get('action'),
130 131
                          self.freezer_action_2.get('action'))
132
+
133
+    def test_add_and_replace_action(self):
134
+        action_doc = copy.deepcopy(self.fake_action_0)
135
+        action_id = self.dbapi.add_action(user_id=self.fake_action_0.
136
+                                          get('user_id'),
137
+                                          doc=action_doc,
138
+                                          project_id=self.fake_project_id)
139
+        self.assertIsNotNone(action_id)
140
+
141
+        patch_doc = copy.deepcopy(self.fake_action_2)
142
+
143
+        result = self.dbapi.replace_action(project_id=self.fake_project_id,
144
+                                           user_id=self.fake_action_2.
145
+                                           get('user_id'),
146
+                                           doc=patch_doc,
147
+                                           action_id=action_id)
148
+
149
+        self.assertIsNotNone(result)
150
+
151
+        self.assertEqual(result, action_id)
152
+
153
+        result = self.dbapi.get_action(project_id=self.fake_project_id,
154
+                                       user_id=self.fake_action_2.
155
+                                       get('user_id'),
156
+                                       action_id=action_id)
157
+
158
+        self.assertEqual(result.get('max_retries'),
159
+                         self.fake_action_2.get('max_retries'))
160
+
161
+        self.assertEqual(result.get('max_retries_interval'),
162
+                         self.fake_action_2.get('max_retries_interval'))
163
+
164
+        freezer_action = result.get('freezer_action')
165
+
166
+        self.assertEqual(freezer_action.get('action'),
167
+                         self.freezer_action_2.get('action'))
168
+
169
+        patch_doc1 = copy.deepcopy(self.fake_action_0)
170
+
171
+        result = self.dbapi.replace_action(project_id=self.fake_project_id,
172
+                                           user_id=self.fake_action_2.
173
+                                           get('user_id'),
174
+                                           doc=patch_doc1,
175
+                                           action_id=self.fake_action_id)
176
+        self.assertIsNotNone(result)
177
+
178
+        self.assertEqual(result, self.fake_action_id)

Loading…
Cancel
Save