Browse Source

Merge "Add client add and get unit test for sql"

tags/7.0.0
Zuul 6 months ago
parent
commit
ee2fc153ef
2 changed files with 66 additions and 0 deletions
  1. 8
    0
      freezer_api/tests/unit/common.py
  2. 58
    0
      freezer_api/tests/unit/sqlalchemy/test_client.py

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

@@ -304,6 +304,14 @@ fake_client_entry_1 = {
304 304
     "user_id": "user_id-is-provided-keystone"
305 305
 }
306 306
 
307
+
308
+def get_fake_client_0():
309
+    return copy.deepcopy(fake_client_entry_0)
310
+
311
+
312
+def get_fake_client_1():
313
+    return copy.deepcopy(fake_client_entry_1)
314
+
307 315
 fake_action_0 = {
308 316
     "freezer_action":
309 317
         {

+ 58
- 0
freezer_api/tests/unit/sqlalchemy/test_client.py View File

@@ -0,0 +1,58 @@
1
+# (c) Copyright 2018 ZTE Corporation.
2
+# All Rights Reserved.
3
+#
4
+#    Licensed under the Apache License, Version 2.0 (the "License"); you may
5
+#    not use this file except in compliance with the License. You may obtain
6
+#    a copy of the License at
7
+#
8
+#         http://www.apache.org/licenses/LICENSE-2.0
9
+#
10
+#    Unless required by applicable law or agreed to in writing, software
11
+#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12
+#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
+#    License for the specific language governing permissions and limitations
14
+#    under the License.
15
+
16
+"""Tests for manipulating  Client via the DB API"""
17
+
18
+
19
+import copy
20
+
21
+from freezer_api.tests.unit import common
22
+from freezer_api.tests.unit.sqlalchemy import base
23
+
24
+
25
+class DbClientTestCase(base.DbTestCase):
26
+
27
+    def setUp(self):
28
+        super(DbClientTestCase, self).setUp()
29
+        self.fake_client_0 = common.get_fake_client_0()
30
+        self.fake_client_doc = self.fake_client_0.get('client')
31
+
32
+    def test_add_and_get_client(self):
33
+        client_doc = copy.deepcopy(self.fake_client_doc)
34
+        client_id = self.dbapi.add_client(user_id=self.fake_client_0.
35
+                                          get('user_id'),
36
+                                          doc=client_doc,
37
+                                          project_id="myproject")
38
+        self.assertIsNotNone(client_id)
39
+
40
+        result = self.dbapi.get_client(project_id="myproject",
41
+                                       user_id=self.fake_client_0.
42
+                                       get('user_id'),
43
+                                       client_id=client_id)
44
+
45
+        self.assertIsNotNone(result)
46
+
47
+        self.assertEqual(len(result), 1)
48
+
49
+        self.assertEqual(result[0].get('user_id'),
50
+                         self.fake_client_0.get('user_id'))
51
+
52
+        client = result[0].get('client')
53
+
54
+        self.assertEqual(client.get('client_id'),
55
+                         self.fake_client_doc.get('client_id'))
56
+
57
+        self.assertEqual(client.get('description'),
58
+                         self.fake_client_doc.get('description'))

Loading…
Cancel
Save