def test_stress(self): # 性能 测试 repeat_times = 100 txt = '15呵呵5@#E$$@#gh,。h()_=154中文4*4616' * 10 start_time = time.time() cipher = aes.encryptData(txt, key) end_time = time.time() logging.info(u'单次加密耗时:%.4f秒' % (end_time - start_time)) logging.info('*' * 100) start_time = time.time() for i in range(repeat_times): cipher = aes.encryptData(txt, key) end_time = time.time() logging.info(u'%d次加密耗时:%.4f秒' % (repeat_times, end_time - start_time)) logging.info('*' * 100) start_time = time.time() decr = aes.decryptData(cipher, key) end_time = time.time() logging.info(u'单次解密耗时:%.4f秒' % (end_time - start_time)) logging.info('*' * 100) start_time = time.time() for i in range(repeat_times): decr = aes.decryptData(cipher, key) end_time = time.time() logging.info(u'%d次解密耗时:%.4f秒' % (repeat_times, end_time - start_time)) logging.info('*' * 100)
def test_param(self): # 明文参数为空测试 secret_txt = aes.encryptData('', key) assert not secret_txt secret_txt = aes.encryptData(None, key) assert not secret_txt # 密文参数为空测试 real_text = aes.decryptData('', key) assert not real_text real_text = aes.decryptData(None, key) assert not real_text # 加密 key 为空测试 txt = '13800138000' has_error = False try: secret_txt = aes.encryptData(txt, '') except: has_error = True assert has_error has_error = False try: secret_txt = aes.encryptData(txt, None) except: has_error = True assert has_error # 解密 key 为空测试 has_error = False try: real_text = aes.decryptData(txt, '') except: has_error = True assert has_error has_error = False try: real_text = aes.decryptData(txt, None) except: has_error = True assert has_error
def test_unicode(self): # unicode测试 txt = u'15呵呵5@#E$$@#gh,。h()_=154中文4*4616' secret_txt = aes.encryptData(txt, key) assert secret_txt assert aes.decryptData(secret_txt, key) == txt
def test_chinese(self): # 中文测试 txt = '15呵呵5@#E$$@#gh,。h()_=154中文4*4616' secret_txt = aes.encryptData(txt, key) assert secret_txt assert aes.decryptData(secret_txt, key) == txt
def test_english(self): # 普通英文 + 英文符号测试 txt = 'abc321cc55+-*/,.,.dfdehryz908&^%$#@!~*()_+-=' secret_txt = aes.encryptData(txt, key) assert secret_txt assert aes.decryptData(secret_txt, key) == txt
def test_unicode(self): # unicode测试 key = 'fgjtjirj4o234234' # 必须16、24、32 位 txt = u'15呵呵5@#E$$@#gh,。h()_=154中文4*4616' assert aes.encryptData(key, txt) assert aes.decryptData(key, aes.encryptData(key, txt)) == txt
def test_english(self): # 普通英文 + 英文符号测试 key = 'fgjtjirj4o234234' # 必须16、24、32 位 txt = 'abc321cc55' assert aes.encryptData(key, txt) assert aes.decryptData(key, aes.encryptData(key, txt)) == txt