Browse Source

Add backup delete unit test for sql

The patch add backup delete unit test case for sqlalchemy

Change-Id: I17d91fe77ecac88f679989c4bd0730d313c835fb
tags/7.0.0
gecong1973 6 months ago
parent
commit
df2993f850
2 changed files with 26 additions and 2 deletions
  1. 1
    0
      freezer_api/tests/unit/common.py
  2. 25
    2
      freezer_api/tests/unit/sqlalchemy/test_backup.py

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

@@ -34,6 +34,7 @@ CONF = cfg.CONF
34 34
 fake_data_0_backup_id = 'b740ed9ad2b646aba304ef54c21c6774'
35 35
 fake_data_0_user_id = 'qwerty1234'
36 36
 fake_data_0_user_name = 'asdffdsa'
37
+fake_data_0_project_id = "tecs"
37 38
 
38 39
 fake_data_0_wrapped_backup_metadata = {
39 40
     'backup_id': 'b740ed9ad2b646aba304ef54c21c6774',

+ 25
- 2
freezer_api/tests/unit/sqlalchemy/test_backup.py View File

@@ -29,16 +29,17 @@ class DbBackupTestCase(base.DbTestCase):
29 29
         self.fake_backup_metadata = common.get_fake_backup_metadata()
30 30
         self.fake_user_id = common.fake_data_0_user_id
31 31
         self.fake_user_name = common.fake_data_0_user_name
32
+        self.fake_project_id = common.fake_data_0_project_id
32 33
 
33 34
     def test_add_and_get_backup(self):
34 35
         backup_doc = copy.deepcopy(self.fake_backup_metadata)
35 36
         backup_id = self.dbapi.add_backup(user_id=self.fake_user_id,
36 37
                                           user_name=self.fake_user_name,
37 38
                                           doc=backup_doc,
38
-                                          project_id="myproject")
39
+                                          project_id=self.fake_project_id)
39 40
         self.assertIsNotNone(backup_id)
40 41
 
41
-        result = self.dbapi.get_backup(project_id="myproject",
42
+        result = self.dbapi.get_backup(project_id=self.fake_project_id,
42 43
                                        user_id=self.fake_user_id,
43 44
                                        backup_id=backup_id)
44 45
         self.assertIsNotNone(result)
@@ -56,3 +57,25 @@ class DbBackupTestCase(base.DbTestCase):
56 57
 
57 58
         self.assertEqual(backup_metadata,
58 59
                          self.fake_backup_metadata)
60
+
61
+    def test_add_and_delete_backup(self):
62
+        backup_doc = copy.deepcopy(self.fake_backup_metadata)
63
+        backup_id = self.dbapi.add_backup(user_id=self.fake_user_id,
64
+                                          user_name=self.fake_user_name,
65
+                                          doc=backup_doc,
66
+                                          project_id=self.fake_project_id)
67
+
68
+        self.assertIsNotNone(backup_id)
69
+
70
+        result = self.dbapi.delete_backup(project_id=self.fake_project_id,
71
+                                          user_id=self.fake_user_id,
72
+                                          backup_id=backup_id)
73
+
74
+        self.assertIsNotNone(result)
75
+
76
+        self.assertEqual(result, backup_id)
77
+
78
+        result = self.dbapi.get_backup(project_id=self.fake_project_id,
79
+                                       user_id=self.fake_user_id,
80
+                                       backup_id=backup_id)
81
+        self.assertEqual(len(result), 0)

Loading…
Cancel
Save