Browse Source

Add job replace unit test for sqlalchemy

The patch add replace test case for sqlalchemy

Change-Id: Ic0e0b6466e1dddc5be3b1e339572467e71df9a91
tags/7.0.0
gengchc2 6 months ago
parent
commit
8f4a306f3b
2 changed files with 49 additions and 0 deletions
  1. 4
    0
      freezer_api/tests/unit/common.py
  2. 45
    0
      freezer_api/tests/unit/sqlalchemy/test_job.py

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

@@ -297,6 +297,10 @@ def get_fake_job_2():
297 297
     return copy.deepcopy(fake_job_2)
298 298
 
299 299
 
300
+def get_fake_job_id():
301
+    return uuid.uuid4().hex
302
+
303
+
300 304
 fake_job_0_elasticsearch_found = {
301 305
     "_id": "e7181e5e-2c75-43f8-92c0-c037ae5f11e4",
302 306
     "_index": "freezer",

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

@@ -32,6 +32,7 @@ class DbJobTestCase(base.DbTestCase):
32 32
         self.fake_job_2 = common.get_fake_job_2()
33 33
         self.fake_job_2.pop('job_id')
34 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 37
     def test_add_and_get_job(self):
37 38
         job_doc = copy.deepcopy(self.fake_job_0)
@@ -111,3 +112,47 @@ class DbJobTestCase(base.DbTestCase):
111 112
                          get('schedule_interval'))
112 113
         self.assertEqual(result.get('job_actions'),
113 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)

Loading…
Cancel
Save