From 84dde937a1da9abf1d35821815e42149e989b921 Mon Sep 17 00:00:00 2001 From: jiacy-jcy Date: Mon, 20 Jun 2022 13:32:29 +0800 Subject: [PATCH] add test case --- .../1-insert/create_table_comment.py | 113 --------------- tests/system-test/1-insert/table_comment.py | 135 ++++++++++++++++++ 2 files changed, 135 insertions(+), 113 deletions(-) delete mode 100644 tests/system-test/1-insert/create_table_comment.py create mode 100644 tests/system-test/1-insert/table_comment.py diff --git a/tests/system-test/1-insert/create_table_comment.py b/tests/system-test/1-insert/create_table_comment.py deleted file mode 100644 index 92ea083c5a..0000000000 --- a/tests/system-test/1-insert/create_table_comment.py +++ /dev/null @@ -1,113 +0,0 @@ -################################################################### -# Copyright (c) 2016 by TAOS Technologies, Inc. -# All rights reserved. -# -# This file is proprietary and confidential to TAOS Technologies. -# No part of this file may be reproduced, stored, transmitted, -# disclosed or used in any form or by any means other than as -# expressly provided by the written permission from Jianhui Tao -# -################################################################### - -# -*- coding: utf-8 -*- - -import random -import string -from util.log import * -from util.cases import * -from util.sql import * - -class TDTestCase: - def init(self, conn, logSql): - tdLog.debug("start to execute %s" % __file__) - tdSql.init(conn.cursor()) - - def get_long_name(self, length, mode="mixed"): - """ - generate long name - mode could be numbers/letters/letters_mixed/mixed - """ - if mode == "numbers": - population = string.digits - elif mode == "letters": - population = string.ascii_letters.lower() - elif mode == "letters_mixed": - population = string.ascii_letters.upper() + string.ascii_letters.lower() - else: - population = string.ascii_letters.lower() + string.digits - return "".join(random.choices(population, k=length)) - - def __create_tb(self,dbname,stbname,tbname,comment): - tdSql.execute(f'create database if not exists {dbname}') - tdSql.execute(f'use {dbname}') - tdSql.execute( - f'create table {stbname} (ts timestamp,c0 int) tags(t0 int) ') - tdSql.execute( - f'create table {tbname} using {stbname} tags(1) comment "{comment}"') - def __create_normaltb(self,dbname,tbname,comment): - tdSql.execute(f'create database if not exists {dbname}') - tdSql.execute(f'use {dbname}') - tdSql.execute( - f'create table {tbname} (ts timestamp,c0 int) comment "{comment}"') - - def check_comment(self): - dbname = self.get_long_name(length=10, mode="letters") - ntbname = self.get_long_name(length=5, mode="letters") - - # create normal table with comment - comment = self.get_long_name(length=10, mode="letters") - self.__create_normaltb(dbname,ntbname,comment) - ntb_kv_list = tdSql.getResult("show tables") - print(ntb_kv_list) - tdSql.checkEqual(ntb_kv_list[0][8], comment) - tdSql.error('alter table {ntbname} comment "test1"') - tdSql.execute(f'drop database {dbname}') - - # max length(1024) - comment = self.get_long_name(length=1024, mode="letters") - self.__create_normaltb(dbname,ntbname,comment) - ntb_kv_list = tdSql.getResult("show tables") - tdSql.checkEqual(ntb_kv_list[0][8], comment) - tdSql.execute(f'drop database {dbname}') - - # error overlength - comment = self.get_long_name(length=1025, mode="letters") - tdSql.execute(f'create database if not exists {dbname}') - tdSql.execute(f'use {dbname}') - tdSql.error(f"create table ntb (ts timestamp,c0 int) comment '{comment}'") - tdSql.execute(f'drop database {dbname}') - - # create child table with comment - comment = self.get_long_name(length=10, mode="letters") - stbname = self.get_long_name(length=5, mode="letters") - tbname = self.get_long_name(length=3, mode="letters") - self.__create_tb(dbname,stbname,tbname,comment) - ntb_kv_list = tdSql.getResult("show tables") - tdSql.checkEqual(ntb_kv_list[0][8], comment) - tdSql.error(f'alter table {tbname} comment "test1"') - tdSql.execute(f'drop database {dbname}') - - # max length 1024 - comment = self.get_long_name(length=1024, mode="letters") - self.__create_tb(dbname,ntbname,comment) - ntb_kv_list = tdSql.getResult("show tables") - tdSql.checkEqual(ntb_kv_list[0][8], comment) - tdSql.execute(f'drop database {dbname}') - - # error overlength - comment = self.get_long_name(length=1025, mode="letters") - tdSql.execute(f'create database if not exists {dbname}') - tdSql.execute(f'use {dbname}') - tdSql.execute(f"create table stb (ts timestamp,c0 int) tags(t0 int)") - tdSql.error(f'create table stb_1 us stb tags(1) comment "{comment}"') - tdSql.execute(f'drop database {dbname}') - - def run(self): - self.check_comment() - - def stop(self): - tdSql.close() - tdLog.success("%s successfully executed" % __file__) - -tdCases.addWindows(__file__, TDTestCase()) -tdCases.addLinux(__file__, TDTestCase()) \ No newline at end of file diff --git a/tests/system-test/1-insert/table_comment.py b/tests/system-test/1-insert/table_comment.py new file mode 100644 index 0000000000..1e999c5f00 --- /dev/null +++ b/tests/system-test/1-insert/table_comment.py @@ -0,0 +1,135 @@ +################################################################### +# Copyright (c) 2016 by TAOS Technologies, Inc. +# All rights reserved. +# +# This file is proprietary and confidential to TAOS Technologies. +# No part of this file may be reproduced, stored, transmitted, +# disclosed or used in any form or by any means other than as +# expressly provided by the written permission from Jianhui Tao +# +################################################################### + +# -*- coding: utf-8 -*- + +import random +import string + +from tomlkit import comment +from util.log import * +from util.cases import * +from util.sql import * +from util.common import * + +class TDTestCase: + def init(self, conn, logSql): + tdLog.debug("start to execute %s" % __file__) + tdSql.init(conn.cursor()) + # prepare data + self.ntbname = 'ntb' + self.stbname = 'stb' + self.column_dict = { + 'ts':'timestamp', + 'c1':'int', + 'c2':'float', + 'c3':'double', + 'c4':'timestamp' + } + self.tag_dict = { + 't0':'int' + } + self.comment_length = [0,1024] + self.error_comment_length = [1025] + self.table_type_list = ['normal_table','stable','child_table'] + self.comment_flag_list = [True,False] + + def __set_and_alter_comment(self,tb_type='',comment_flag= False): + + column_sql = '' + tag_sql = '' + for k,v in self.column_dict.items(): + column_sql += f"{k} {v}," + for k,v in self.tag_dict.items(): + tag_sql += f"{k} {v}," + if tb_type == 'normal_table' or tb_type == '': + if comment_flag == False: + tdSql.execute(f'create table {self.ntbname} ({column_sql[:-1]})') + self.check_comment_info() + self.alter_comment(self.ntbname) + tdSql.execute(f'drop table {self.ntbname}') + elif comment_flag == True: + for i in self.comment_length: + comment_info = tdCom.getLongName(i) + tdSql.execute(f'create table {self.ntbname} ({column_sql[:-1]}) comment "{comment_info}"') + self.check_comment_info(comment_info) + self.alter_comment(self.ntbname) + tdSql.execute(f'drop table {self.ntbname}') + for i in self.error_comment_length: + comment_info = tdCom.getLongName(i) + tdSql.error(f'create table {self.ntbname} ({column_sql[:-1]}) comment "{comment_info}"') + elif tb_type == 'stable': + for operation in ['table','stable']: + if comment_flag == False: + tdSql.execute(f'create {operation} {self.stbname} ({column_sql[:-1]}) tags({tag_sql[:-1]})') + self.check_comment_info(None,'stable') + self.alter_comment(self.stbname,'stable') + tdSql.execute(f'drop table {self.stbname}') + elif comment_flag == True: + for i in self.comment_length: + comment_info = tdCom.getLongName(i) + tdSql.execute(f'create {operation} {self.stbname} ({column_sql[:-1]}) tags({tag_sql[:-1]}) comment "{comment_info}"') + self.check_comment_info(comment_info,'stable') + self.alter_comment(self.stbname,'stable') + tdSql.execute(f'drop table {self.stbname}') + elif tb_type == 'child_table': + tdSql.execute(f'create table if not exists {self.stbname} ({column_sql[:-1]}) tags({tag_sql[:-1]})') + if comment_flag == False: + tdSql.execute(f'create table if not exists {self.stbname}_ctb using {self.stbname} tags(1)') + self.check_comment_info() + self.alter_comment(f'{self.stbname}_ctb') + tdSql.execute(f'drop table {self.stbname}_ctb') + elif comment_flag == True: + for j in self.comment_length: + comment_info = tdCom.getLongName(j) + tdSql.execute(f'create table if not exists {self.stbname}_ctb using {self.stbname} tags(1) comment "{comment_info}"') + self.check_comment_info(comment_info) + self.alter_comment(f'{self.stbname}_ctb') + tdSql.execute(f'drop table {self.stbname}_ctb') + tdSql.execute(f'drop table {self.stbname}') + def alter_comment(self,tbname,tb_type=''): + for i in self.comment_length: + comment_info = tdCom.getLongName(i) + print(comment_info) + tdSql.execute(f'alter table {tbname} comment "{comment_info}"') + self.check_comment_info(comment_info,tb_type) + for i in self.error_comment_length: + comment_info = tdCom.getLongName(i) + tdSql.error(f'alter table {tbname} comment "{comment_info}"') + def check_comment_info(self,comment_info=None,tb_type=''): + if tb_type == '' or tb_type == 'normal_table' or tb_type == 'child_table': + tdSql.query('show tables') + if comment_info == None: + tdSql.checkEqual(tdSql.queryResult[0][8],None) + else : + tdSql.checkEqual(tdSql.queryResult[0][8],comment_info) + elif tb_type == 'stable': + tdSql.query('show stables') + if comment_info == None: + tdSql.checkEqual(tdSql.queryResult[0][6],None) + else : + tdSql.checkEqual(tdSql.queryResult[0][6],comment_info) + def comment_check_case(self,table_type,comment_flag): + tdSql.prepare() + for tb in table_type: + for flag in comment_flag: + self.__set_and_alter_comment(tb,flag) + tdSql.execute('drop database db') + + def run(self): + self.comment_check_case(self.table_type_list,self.comment_flag_list) + + def stop(self): + tdSql.close() + tdLog.success("%s successfully executed" % __file__) + +tdCases.addWindows(__file__, TDTestCase()) +tdCases.addLinux(__file__, TDTestCase()) \ No newline at end of file