summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgecong1973 <ge.cong@zte.com.cn>2018-11-19 01:16:00 -0800
committergecong1973 <ge.cong@zte.com.cn>2018-11-19 01:16:00 -0800
commit57835be52913410a8661c55297b7101aae3a8bb7 (patch)
tree3f1978d396a7583f4d1484fee1a585f7003a381d
parentf0086ea2261859edc96d188da3c101a4978439dc (diff)
Add client search unit test for sql
The patch add client search unit testcase for sqlalchemy Change-Id: I53bceb89e54ea3c60e3e088af3c65863b4fd35c3
Notes
Notes (review): Code-Review+2: gengchc2 <geng.changcai2@zte.com.cn> Workflow+1: gengchc2 <geng.changcai2@zte.com.cn> Verified+2: Zuul Submitted-by: Zuul Submitted-at: Mon, 19 Nov 2018 11:22:01 +0000 Reviewed-on: https://review.openstack.org/618713 Project: openstack/freezer-api Branch: refs/heads/master
-rw-r--r--freezer_api/tests/unit/common.py4
-rw-r--r--freezer_api/tests/unit/sqlalchemy/test_client.py28
2 files changed, 32 insertions, 0 deletions
diff --git a/freezer_api/tests/unit/common.py b/freezer_api/tests/unit/common.py
index 6c18087..142fa42 100644
--- a/freezer_api/tests/unit/common.py
+++ b/freezer_api/tests/unit/common.py
@@ -420,6 +420,10 @@ def get_fake_client_0():
420def get_fake_client_1(): 420def get_fake_client_1():
421 return copy.deepcopy(fake_client_entry_1) 421 return copy.deepcopy(fake_client_entry_1)
422 422
423
424def get_fake_client_id():
425 return uuid.uuid4().hex
426
423fake_action_0 = { 427fake_action_0 = {
424 "freezer_action": 428 "freezer_action":
425 { 429 {
diff --git a/freezer_api/tests/unit/sqlalchemy/test_client.py b/freezer_api/tests/unit/sqlalchemy/test_client.py
index 1c23a20..4205aee 100644
--- a/freezer_api/tests/unit/sqlalchemy/test_client.py
+++ b/freezer_api/tests/unit/sqlalchemy/test_client.py
@@ -77,3 +77,31 @@ class DbClientTestCase(base.DbTestCase):
77 client_id=client_id) 77 client_id=client_id)
78 78
79 self.assertEqual(len(result), 0) 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)