summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgecong1973 <ge.cong@zte.com.cn>2018-11-12 19:11:33 -0800
committergecong1973 <ge.cong@zte.com.cn>2018-11-12 19:14:24 -0800
commit18d0df67d1abada8747bc8ec309880df43acd1ec (patch)
tree5660b7fffca21da1ee0906f1652ece54f821481b
parent76bd75c371b391d886c1f8eea1d598e48d2cc725 (diff)
Add client add and get unit test for sql
The patch add client add and get unit test for sqlalchemy Change-Id: I21370d5ed90ade872fdf3299741e522a2e28f060
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: Tue, 13 Nov 2018 07:07:38 +0000 Reviewed-on: https://review.openstack.org/617428 Project: openstack/freezer-api Branch: refs/heads/master
-rw-r--r--freezer_api/tests/unit/common.py8
-rw-r--r--freezer_api/tests/unit/sqlalchemy/test_client.py58
2 files changed, 66 insertions, 0 deletions
diff --git a/freezer_api/tests/unit/common.py b/freezer_api/tests/unit/common.py
index 9ca9459..5f7acb3 100644
--- a/freezer_api/tests/unit/common.py
+++ b/freezer_api/tests/unit/common.py
@@ -304,6 +304,14 @@ fake_client_entry_1 = {
304 "user_id": "user_id-is-provided-keystone" 304 "user_id": "user_id-is-provided-keystone"
305} 305}
306 306
307
308def get_fake_client_0():
309 return copy.deepcopy(fake_client_entry_0)
310
311
312def get_fake_client_1():
313 return copy.deepcopy(fake_client_entry_1)
314
307fake_action_0 = { 315fake_action_0 = {
308 "freezer_action": 316 "freezer_action":
309 { 317 {
diff --git a/freezer_api/tests/unit/sqlalchemy/test_client.py b/freezer_api/tests/unit/sqlalchemy/test_client.py
new file mode 100644
index 0000000..3f018d6
--- /dev/null
+++ b/freezer_api/tests/unit/sqlalchemy/test_client.py
@@ -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
19import copy
20
21from freezer_api.tests.unit import common
22from freezer_api.tests.unit.sqlalchemy import base
23
24
25class 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'))