-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add database and rp implement and usecases
Signed-off-by: heiliuchao <[email protected]> Co-authored-by: ZhangJian He <[email protected]>
- Loading branch information
1 parent
5ae13d2
commit 1100340
Showing
4 changed files
with
175 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import inspect | ||
import unittest | ||
|
||
from opengemini_client import test_utils | ||
|
||
|
||
class DatabaseTest(unittest.TestCase): | ||
|
||
def test_create_databases_success(self): | ||
dbname = inspect.currentframe().f_code.co_name | ||
with test_utils.get_test_default_client() as cli: | ||
qr = cli.create_database(database=dbname) | ||
self.assertEqual(qr.error, None) | ||
qr = cli.drop_database(database=dbname) | ||
self.assertEqual(qr.error, None) | ||
|
||
def test_show_databases_success(self): | ||
dbname = inspect.currentframe().f_code.co_name | ||
with test_utils.get_test_default_client() as cli: | ||
qr = cli.create_database(database=dbname) | ||
self.assertEqual(qr.error, None) | ||
new_db_list = cli.show_databases() | ||
self.assertTrue(dbname in new_db_list) | ||
qr = cli.drop_database(database=dbname) | ||
self.assertEqual(qr.error, None) | ||
|
||
def test_create_databases_with_empty_db(self): | ||
with test_utils.get_test_default_client() as cli: | ||
with self.assertRaises(ValueError): | ||
cli.create_database(database='') | ||
|
||
def test_drop_databases_success(self): | ||
dbname = inspect.currentframe().f_code.co_name | ||
with test_utils.get_test_default_client() as cli: | ||
qr = cli.create_database(database=dbname) | ||
self.assertEqual(qr.error, None) | ||
qr = cli.drop_database(database=dbname) | ||
self.assertEqual(qr.error, None) | ||
|
||
def test_drop_databases_with_empty_db(self): | ||
with test_utils.get_test_default_client() as cli: | ||
with self.assertRaises(ValueError): | ||
cli.drop_database(database='') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import inspect | ||
import unittest | ||
|
||
from opengemini_client import models | ||
from opengemini_client import test_utils | ||
|
||
|
||
class RetentionPolicyTest(unittest.TestCase): | ||
|
||
def test_create_retention_policy_empty_db_parameter(self): | ||
dbname = inspect.currentframe().f_code.co_name | ||
rp_config = models.RpConfig(dbname, '2h', '2h', '2h') | ||
with test_utils.get_test_default_client() as cli: | ||
with self.assertRaises(ValueError): | ||
cli.create_retention_policy(dbname='', rp_config=rp_config, is_default=True) | ||
|
||
def test_create_retention_policy_success(self): | ||
dbname = inspect.currentframe().f_code.co_name | ||
rp_config = models.RpConfig(dbname, '2h', '2h', '2h') | ||
with test_utils.get_test_default_client() as cli: | ||
cli.create_database(dbname) | ||
qr = cli.create_retention_policy(dbname=dbname, rp_config=rp_config, is_default=True) | ||
self.assertEqual(qr.error, None) | ||
cli.drop_retention_policy(dbname=dbname, retention_policy=rp_config.name) | ||
cli.drop_database(dbname) | ||
|
||
def test_show_retention_policy_empty_db_parameter(self): | ||
with test_utils.get_test_default_client() as cli: | ||
with self.assertRaises(ValueError): | ||
cli.show_retention_policies('') | ||
|
||
def test_show_retention_policies_success(self): | ||
dbname = inspect.currentframe().f_code.co_name | ||
rp_config = models.RpConfig(dbname, '2h', '2h', '2h') | ||
with test_utils.get_test_default_client() as cli: | ||
cli.create_database(dbname) | ||
cli.create_retention_policy(dbname=dbname, rp_config=rp_config, is_default=True) | ||
retention_policies = cli.show_retention_policies(dbname=dbname) | ||
rp_config_name = [rp[0] for rp in retention_policies] | ||
self.assertTrue(rp_config.name in rp_config_name) | ||
cli.drop_retention_policy(dbname=dbname, retention_policy=rp_config.name) | ||
cli.drop_database(dbname) | ||
|
||
def test_drop_retention_policy_success(self): | ||
dbname = inspect.currentframe().f_code.co_name | ||
rp_config = models.RpConfig(dbname, '2h', '2h', '2h') | ||
with test_utils.get_test_default_client() as cli: | ||
cli.create_database(dbname) | ||
cli.create_retention_policy(dbname=dbname, rp_config=rp_config, is_default=True) | ||
qr = cli.drop_retention_policy(dbname=dbname, retention_policy=rp_config.name) | ||
self.assertEqual(qr.error, None) | ||
cli.drop_database(dbname) | ||
|
||
def test_drop_retention_policy_no_db_parameters(self): | ||
dbname = inspect.currentframe().f_code.co_name | ||
rp_config = models.RpConfig(dbname, '2h', '2h', '2h') | ||
with test_utils.get_test_default_client() as cli: | ||
cli.create_database(dbname) | ||
cli.create_retention_policy(dbname=dbname, rp_config=rp_config, is_default=True) | ||
with self.assertRaises(ValueError): | ||
cli.drop_retention_policy('', retention_policy=rp_config.name) | ||
cli.drop_retention_policy(dbname=dbname, retention_policy=rp_config.name) | ||
cli.drop_database(dbname) | ||
|
||
def test_drop_retention_policy_no_rp_parameters(self): | ||
dbname = inspect.currentframe().f_code.co_name | ||
rp_config = models.RpConfig(dbname, '2h', '2h', '2h') | ||
with test_utils.get_test_default_client() as cli: | ||
cli.create_database(dbname) | ||
cli.create_retention_policy(dbname=dbname, rp_config=rp_config, is_default=True) | ||
with self.assertRaises(ValueError): | ||
cli.drop_retention_policy(dbname, retention_policy='') | ||
cli.drop_retention_policy(dbname=dbname, retention_policy=rp_config.name) | ||
cli.drop_database(dbname) |