summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgecong1973 <ge.cong@zte.com.cn>2018-11-14 23:11:42 -0800
committergecong1973 <ge.cong@zte.com.cn>2018-11-14 23:11:42 -0800
commitdf2993f850774cf965905a153c8d2362e444036c (patch)
tree9a959c12a713a0d27ccabc34f048bcd547364626
parente3b53539602892d50f11b28623f7741144c92296 (diff)
Add backup delete unit test for sql
The patch add backup delete unit test case for sqlalchemy Change-Id: I17d91fe77ecac88f679989c4bd0730d313c835fb
Notes
Notes (review): Code-Review+2: Carl Caihui <cai.hui@zte.com.cn> Code-Review+2: gengchc2 <geng.changcai2@zte.com.cn> Workflow+1: gengchc2 <geng.changcai2@zte.com.cn> Code-Review+1: Brin Zhang <zhangbailin@inspur.com> Verified+2: Zuul Submitted-by: Zuul Submitted-at: Mon, 19 Nov 2018 01:17:47 +0000 Reviewed-on: https://review.openstack.org/618090 Project: openstack/freezer-api Branch: refs/heads/master
-rw-r--r--freezer_api/tests/unit/common.py1
-rw-r--r--freezer_api/tests/unit/sqlalchemy/test_backup.py27
2 files changed, 26 insertions, 2 deletions
diff --git a/freezer_api/tests/unit/common.py b/freezer_api/tests/unit/common.py
index 920d573..ac00439 100644
--- a/freezer_api/tests/unit/common.py
+++ b/freezer_api/tests/unit/common.py
@@ -34,6 +34,7 @@ CONF = cfg.CONF
34fake_data_0_backup_id = 'b740ed9ad2b646aba304ef54c21c6774' 34fake_data_0_backup_id = 'b740ed9ad2b646aba304ef54c21c6774'
35fake_data_0_user_id = 'qwerty1234' 35fake_data_0_user_id = 'qwerty1234'
36fake_data_0_user_name = 'asdffdsa' 36fake_data_0_user_name = 'asdffdsa'
37fake_data_0_project_id = "tecs"
37 38
38fake_data_0_wrapped_backup_metadata = { 39fake_data_0_wrapped_backup_metadata = {
39 'backup_id': 'b740ed9ad2b646aba304ef54c21c6774', 40 'backup_id': 'b740ed9ad2b646aba304ef54c21c6774',
diff --git a/freezer_api/tests/unit/sqlalchemy/test_backup.py b/freezer_api/tests/unit/sqlalchemy/test_backup.py
index 20acf84..0e79de6 100644
--- a/freezer_api/tests/unit/sqlalchemy/test_backup.py
+++ b/freezer_api/tests/unit/sqlalchemy/test_backup.py
@@ -29,16 +29,17 @@ class DbBackupTestCase(base.DbTestCase):
29 self.fake_backup_metadata = common.get_fake_backup_metadata() 29 self.fake_backup_metadata = common.get_fake_backup_metadata()
30 self.fake_user_id = common.fake_data_0_user_id 30 self.fake_user_id = common.fake_data_0_user_id
31 self.fake_user_name = common.fake_data_0_user_name 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 def test_add_and_get_backup(self): 34 def test_add_and_get_backup(self):
34 backup_doc = copy.deepcopy(self.fake_backup_metadata) 35 backup_doc = copy.deepcopy(self.fake_backup_metadata)
35 backup_id = self.dbapi.add_backup(user_id=self.fake_user_id, 36 backup_id = self.dbapi.add_backup(user_id=self.fake_user_id,
36 user_name=self.fake_user_name, 37 user_name=self.fake_user_name,
37 doc=backup_doc, 38 doc=backup_doc,
38 project_id="myproject") 39 project_id=self.fake_project_id)
39 self.assertIsNotNone(backup_id) 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 user_id=self.fake_user_id, 43 user_id=self.fake_user_id,
43 backup_id=backup_id) 44 backup_id=backup_id)
44 self.assertIsNotNone(result) 45 self.assertIsNotNone(result)
@@ -56,3 +57,25 @@ class DbBackupTestCase(base.DbTestCase):
56 57
57 self.assertEqual(backup_metadata, 58 self.assertEqual(backup_metadata,
58 self.fake_backup_metadata) 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)