summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgecong1973 <ge.cong@zte.com.cn>2018-11-18 23:32:48 -0800
committergecong1973 <ge.cong@zte.com.cn>2018-11-18 23:32:48 -0800
commit8a351ccc26df5a3bc258f44c64b0db73bda385e4 (patch)
tree8c103eee417997c84b9ca27a0fbba88fb75325e6
parent25376c413315356c18781404340f1b3ae41ab7aa (diff)
Add client delete unit test for sql
The patch add client delete unit testcase for sqlalchemy Change-Id: Ic9025a4be9e54c9d3cea867f9a3c098dfa0a42bb
Notes
Notes (review): Code-Review+2: gengchc2 <geng.changcai2@zte.com.cn> Workflow+1: gengchc2 <geng.changcai2@zte.com.cn> Code-Review+2: Carl Caihui <cai.hui@zte.com.cn> Verified+2: Zuul Submitted-by: Zuul Submitted-at: Mon, 19 Nov 2018 09:06:07 +0000 Reviewed-on: https://review.openstack.org/618703 Project: openstack/freezer-api Branch: refs/heads/master
-rw-r--r--freezer_api/tests/unit/sqlalchemy/test_client.py35
1 files changed, 28 insertions, 7 deletions
diff --git a/freezer_api/tests/unit/sqlalchemy/test_client.py b/freezer_api/tests/unit/sqlalchemy/test_client.py
index 3f018d6..1c23a20 100644
--- a/freezer_api/tests/unit/sqlalchemy/test_client.py
+++ b/freezer_api/tests/unit/sqlalchemy/test_client.py
@@ -28,18 +28,18 @@ class DbClientTestCase(base.DbTestCase):
28 super(DbClientTestCase, self).setUp() 28 super(DbClientTestCase, self).setUp()
29 self.fake_client_0 = common.get_fake_client_0() 29 self.fake_client_0 = common.get_fake_client_0()
30 self.fake_client_doc = self.fake_client_0.get('client') 30 self.fake_client_doc = self.fake_client_0.get('client')
31 self.fake_user_id = self.fake_client_0.get('user_id')
32 self.fake_project_id = self.fake_client_doc.get('project_id')
31 33
32 def test_add_and_get_client(self): 34 def test_add_and_get_client(self):
33 client_doc = copy.deepcopy(self.fake_client_doc) 35 client_doc = copy.deepcopy(self.fake_client_doc)
34 client_id = self.dbapi.add_client(user_id=self.fake_client_0. 36 client_id = self.dbapi.add_client(user_id=self.fake_user_id,
35 get('user_id'),
36 doc=client_doc, 37 doc=client_doc,
37 project_id="myproject") 38 project_id=self.fake_project_id)
38 self.assertIsNotNone(client_id) 39 self.assertIsNotNone(client_id)
39 40
40 result = self.dbapi.get_client(project_id="myproject", 41 result = self.dbapi.get_client(project_id=self.fake_project_id,
41 user_id=self.fake_client_0. 42 user_id=self.fake_user_id,
42 get('user_id'),
43 client_id=client_id) 43 client_id=client_id)
44 44
45 self.assertIsNotNone(result) 45 self.assertIsNotNone(result)
@@ -47,7 +47,7 @@ class DbClientTestCase(base.DbTestCase):
47 self.assertEqual(len(result), 1) 47 self.assertEqual(len(result), 1)
48 48
49 self.assertEqual(result[0].get('user_id'), 49 self.assertEqual(result[0].get('user_id'),
50 self.fake_client_0.get('user_id')) 50 self.fake_user_id)
51 51
52 client = result[0].get('client') 52 client = result[0].get('client')
53 53
@@ -56,3 +56,24 @@ class DbClientTestCase(base.DbTestCase):
56 56
57 self.assertEqual(client.get('description'), 57 self.assertEqual(client.get('description'),
58 self.fake_client_doc.get('description')) 58 self.fake_client_doc.get('description'))
59
60 def test_add_and_delete_client(self):
61 client_doc = copy.deepcopy(self.fake_client_doc)
62 client_id = self.dbapi.add_client(user_id=self.fake_user_id,
63 doc=client_doc,
64 project_id=self.fake_project_id)
65 self.assertIsNotNone(client_id)
66
67 result = self.dbapi.delete_client(project_id=self.fake_project_id,
68 user_id=self.fake_user_id,
69 client_id=client_id)
70
71 self.assertIsNotNone(result)
72
73 self.assertEqual(result, client_id)
74
75 result = self.dbapi.get_client(project_id=self.fake_project_id,
76 user_id=self.fake_user_id,
77 client_id=client_id)
78
79 self.assertEqual(len(result), 0)