class StarbaseClient01ConnectionTest(unittest.TestCase): """ Starbase Connection tests. """ #@print_info def setUp(self): self.connection = Connection(HOST, PORT, content_type='json') self.table = self.connection.table(TABLE_NAME) @print_info def test_01_version(self): res = self.connection.version self.assertTrue(isinstance(res, dict)) return res @print_info def test_02_cluster_version(self): res = self.connection.cluster_version self.assertTrue(isinstance(res, text_type)) return res @print_info def test_03_cluster_status(self): res = self.connection.cluster_status self.assertTrue(isinstance(res, dict)) return res if TEST_DELETE_TABLE: @print_info def test_04_drop_table_schema(self): """ Delete table schema. Deleting the table if it exists. After that checking if table still exists. """ # First testing for non-existent table non_existent_res = self.connection.table('non-existent-table').drop() self.assertEqual(503, non_existent_res) res = None if self.connection.table_exists(TABLE_NAME): res = self.connection.table(TABLE_NAME).drop() self.assertEqual(200, res) # Checking the status code self.assertTrue(not self.connection.table_exists(TABLE_NAME)) # Checking for physical existence return non_existent_res, res if TEST_CREATE_TABLE: @print_info def test_05_create_table_schema(self): """ Create table schema. After creating the table we just check if it exists. """ # Success tests res = None if not self.connection.table_exists(TABLE_NAME): columns = [COLUMN_FROM_USER, COLUMN_TO_USER, COLUMN_MESSAGE] res = self.connection.table(TABLE_NAME).create(*columns) self.assertTrue(self.connection.table_exists(TABLE_NAME)) # Now trying to create a table even if it exists. columns = [COLUMN_FROM_USER, COLUMN_TO_USER, COLUMN_MESSAGE] res_fail = self.connection.table(TABLE_NAME).create(*columns) self.assertEqual(res_fail, False) return res, res_fail @print_info def test_06_get_table_schema(self): """ Get table schema. """ # First testing for non existent table non_existent_table = self.connection.table('non-existent-table') self.assertTrue(non_existent_table.schema() is None) # Now for existing one res = self.table.schema() self.assertTrue(res is not None) return non_existent_table, res @print_info def test_07_table_list(self): res = self.connection.tables() self.assertTrue(isinstance(res, list)) self.assertTrue(TABLE_NAME in res) return res
class StarbaseClient01ConnectionTest(unittest.TestCase): """ Starbase Connection tests. """ #@print_info def setUp(self): self.connection = Connection(HOST, PORT, content_type='json') self.table = self.connection.table(TABLE_NAME) @print_info def test_01_version(self): res = self.connection.version self.assertTrue(isinstance(res, dict)) return res @print_info def test_02_cluster_version(self): res = self.connection.cluster_version self.assertTrue(isinstance(res, text_type)) return res @print_info def test_03_cluster_status(self): res = self.connection.cluster_status self.assertTrue(isinstance(res, dict)) return res if TEST_DELETE_TABLE: @print_info def test_04_drop_table_schema(self): """ Delete table schema. Deleting the table if it exists. After that checking if table still exists. """ # First testing for non-existent table non_existent_res = self.connection.table( 'non-existent-table').drop() self.assertEqual(503, non_existent_res) res = None if self.connection.table_exists(TABLE_NAME): res = self.connection.table(TABLE_NAME).drop() self.assertEqual(200, res) # Checking the status code self.assertTrue(not self.connection.table_exists(TABLE_NAME) ) # Checking for physical existence return non_existent_res, res if TEST_CREATE_TABLE: @print_info def test_05_create_table_schema(self): """ Create table schema. After creating the table we just check if it exists. """ # Success tests res = None if not self.connection.table_exists(TABLE_NAME): columns = [COLUMN_FROM_USER, COLUMN_TO_USER, COLUMN_MESSAGE] res = self.connection.table(TABLE_NAME).create(*columns) self.assertTrue(self.connection.table_exists(TABLE_NAME)) # Now trying to create a table even if it exists. columns = [COLUMN_FROM_USER, COLUMN_TO_USER, COLUMN_MESSAGE] res_fail = self.connection.table(TABLE_NAME).create(*columns) self.assertEqual(res_fail, False) return res, res_fail @print_info def test_06_get_table_schema(self): """ Get table schema. """ # First testing for non existent table non_existent_table = self.connection.table('non-existent-table') self.assertTrue(non_existent_table.schema() is None) # Now for existing one res = self.table.schema() self.assertTrue(res is not None) return non_existent_table, res @print_info def test_07_table_list(self): res = self.connection.tables() self.assertTrue(isinstance(res, list)) self.assertTrue(TABLE_NAME in res) return res