Browse Source

Add client search unit test for sql

The patch add client search unit testcase for sqlalchemy

Change-Id: I53bceb89e54ea3c60e3e088af3c65863b4fd35c3
tags/7.0.0
gecong1973 6 months ago
parent
commit
57835be529
2 changed files with 32 additions and 0 deletions
  1. 4
    0
      freezer_api/tests/unit/common.py
  2. 28
    0
      freezer_api/tests/unit/sqlalchemy/test_client.py

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

@@ -420,6 +420,10 @@ def get_fake_client_0():
420 420
 def get_fake_client_1():
421 421
     return copy.deepcopy(fake_client_entry_1)
422 422
 
423
+
424
+def get_fake_client_id():
425
+    return uuid.uuid4().hex
426
+
423 427
 fake_action_0 = {
424 428
     "freezer_action":
425 429
         {

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

@@ -77,3 +77,31 @@ class DbClientTestCase(base.DbTestCase):
77 77
                                        client_id=client_id)
78 78
 
79 79
         self.assertEqual(len(result), 0)
80
+
81
+    def test_add_and_search_client(self):
82
+        count = 0
83
+        clientids = []
84
+        while (count < 20):
85
+            client_doc = copy.deepcopy(self.fake_client_doc)
86
+            clientid = common.get_fake_client_id()
87
+            client_doc['client_id'] = clientid
88
+            client_id = self.dbapi.add_client(user_id=self.fake_user_id,
89
+                                              doc=client_doc,
90
+                                              project_id=self.fake_project_id)
91
+            self.assertIsNotNone(client_id)
92
+            self.assertEqual(clientid, client_id)
93
+            clientids.append(client_id)
94
+            count += 1
95
+
96
+        result = self.dbapi.get_client(project_id=self.fake_project_id,
97
+                                       user_id=self.fake_user_id,
98
+                                       limit=10,
99
+                                       offset=0)
100
+
101
+        self.assertIsNotNone(result)
102
+        self.assertEqual(len(result), 10)
103
+
104
+        for index in range(len(result)):
105
+            clientmap = result[index]
106
+            clientid = clientmap['client'].get('client_id')
107
+            self.assertEqual(clientids[index], clientid)

Loading…
Cancel
Save