Browse Source

Add client delete unit test for sql

The patch add client delete unit testcase for sqlalchemy

Change-Id: Ic9025a4be9e54c9d3cea867f9a3c098dfa0a42bb
tags/7.0.0
gecong1973 6 months ago
parent
commit
8a351ccc26
1 changed files with 28 additions and 7 deletions
  1. 28
    7
      freezer_api/tests/unit/sqlalchemy/test_client.py

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

@@ -28,18 +28,18 @@ class DbClientTestCase(base.DbTestCase):
28 28
         super(DbClientTestCase, self).setUp()
29 29
         self.fake_client_0 = common.get_fake_client_0()
30 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 34
     def test_add_and_get_client(self):
33 35
         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
+        client_id = self.dbapi.add_client(user_id=self.fake_user_id,
36 37
                                           doc=client_doc,
37
-                                          project_id="myproject")
38
+                                          project_id=self.fake_project_id)
38 39
         self.assertIsNotNone(client_id)
39 40
 
40
-        result = self.dbapi.get_client(project_id="myproject",
41
-                                       user_id=self.fake_client_0.
42
-                                       get('user_id'),
41
+        result = self.dbapi.get_client(project_id=self.fake_project_id,
42
+                                       user_id=self.fake_user_id,
43 43
                                        client_id=client_id)
44 44
 
45 45
         self.assertIsNotNone(result)
@@ -47,7 +47,7 @@ class DbClientTestCase(base.DbTestCase):
47 47
         self.assertEqual(len(result), 1)
48 48
 
49 49
         self.assertEqual(result[0].get('user_id'),
50
-                         self.fake_client_0.get('user_id'))
50
+                         self.fake_user_id)
51 51
 
52 52
         client = result[0].get('client')
53 53
 
@@ -56,3 +56,24 @@ class DbClientTestCase(base.DbTestCase):
56 56
 
57 57
         self.assertEqual(client.get('description'),
58 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)

Loading…
Cancel
Save