def test_unknown_primary_command(self): tool = AdminTool() tool.run(['unknown'], AdminToolTests.display) self.assertIsNotNone(AdminToolTests.text) self.assertTrue( AdminToolTests.text.startswith( "Unknown primary command [unknown]"))
def test_recursive_copy(self): tmp_dir = self.get_temp_dir() + os.sep + "programy" if os.path.exists(tmp_dir): shutil.rmtree(tmp_dir) os.mkdir(tmp_dir) src_dir = tmp_dir + os.sep + "src" os.mkdir(src_dir) src_sub_dir = tmp_dir + os.sep + "src" + os.sep + "sub" os.mkdir(src_sub_dir) src_sub_dir2 = tmp_dir + os.sep + "src" + os.sep + "sub2" os.mkdir(src_sub_dir2) dest_dir = tmp_dir + os.sep + "dest" os.mkdir(dest_dir) self.create_file(src_dir + os.sep + "file1.txt") self.create_file(src_dir + os.sep + "file2.txt") self.create_file(src_dir + os.sep + "file3.txt") self.create_file(src_dir + os.sep + "sub" + os.sep + "file4.txt") AdminTool.recursive_copy(src_dir, dest_dir) self.assertTrue(os.path.exists(src_dir + os.sep + "file1.txt")) self.assertTrue(os.path.exists(src_dir + os.sep + "file2.txt")) self.assertTrue(os.path.exists(src_dir + os.sep + "file3.txt")) self.assertTrue( os.path.exists(src_dir + os.sep + "sub" + os.sep + "file4.txt")) self.assertTrue(os.path.exists(src_dir + os.sep + "sub2")) if os.path.exists(tmp_dir): shutil.rmtree(tmp_dir)
def test_missing_bot_name(self): tool = AdminTool() tool.run(['download'], AdminToolTests.display) self.assertIsNotNone(AdminToolTests.text) self.assertTrue( AdminToolTests.text.startswith( "Missing bot name from download command"))
def test_create_app(self): temp_folder = self.get_tmp_folder() + os.sep + "prgytest" self.ensure_folder_does_not_exist(temp_folder) args = Mock() args.location = temp_folder args.app = 'console' args.os = 'unix' args.replace = False args.default = True AdminTool.create_app(args) self.assertTrue(os.path.exists(temp_folder)) self.assertTrue(os.path.exists(temp_folder + os.sep + "config")) self.assertTrue(os.path.exists(temp_folder + os.sep + "conversations")) self.assertTrue(os.path.exists(temp_folder + os.sep + "maps")) self.assertTrue(os.path.exists(temp_folder + os.sep + "sets")) self.assertTrue(os.path.exists(temp_folder + os.sep + "rdf")) self.assertTrue(os.path.exists(temp_folder + os.sep + "spelling")) self.assertTrue(os.path.exists(temp_folder + os.sep + "storage")) self.assertTrue(os.path.exists(temp_folder + os.sep + "config.yaml")) self.assertTrue(os.path.exists(temp_folder + os.sep + "logging.yaml")) self.assertTrue( os.path.exists(temp_folder + os.sep + "config" + os.sep + "properties.txt")) self.assertTrue( os.path.exists(temp_folder + os.sep + "aiml" + os.sep + "hello.aiml")) self.ensure_folder_does_not_exist(temp_folder)
def test_create_app(self): temp_folder = self.get_tmp_folder() + os.sep + "prgytest" self.ensure_folder_does_not_exist(temp_folder) args = Mock() args.location = temp_folder args.app = 'console' args.os = 'unix' args.replace = False args.default = True AdminTool.create_app(args) self.assertTrue(os.path.exists(temp_folder)) self.assertTrue(os.path.exists(temp_folder + os.sep + "config")) self.assertTrue(os.path.exists(temp_folder + os.sep + "conversations")) self.assertTrue(os.path.exists(temp_folder + os.sep + "maps")) self.assertTrue(os.path.exists(temp_folder + os.sep + "sets")) self.assertTrue(os.path.exists(temp_folder + os.sep + "rdf")) self.assertTrue(os.path.exists(temp_folder + os.sep + "spelling")) self.assertTrue(os.path.exists(temp_folder + os.sep + "storage")) self.assertTrue(os.path.exists(temp_folder + os.sep + "config.yaml")) self.assertTrue(os.path.exists(temp_folder + os.sep + "logging.yaml")) self.assertTrue(os.path.exists(temp_folder + os.sep + "config" + os.sep + "properties.txt")) self.assertTrue(os.path.exists(temp_folder + os.sep + "aiml" + os.sep + "hello.aiml")) self.ensure_folder_does_not_exist(temp_folder)
def test_create_aiml_folder(self): temp_folder = self.get_tmp_folder() aiml_folder = temp_folder + os.sep + "aiml" self.ensure_folder_does_not_exist(aiml_folder) AdminTool.create_aiml_folder(temp_folder, False) self.assertTrue(os.path.exists(aiml_folder)) self.ensure_folder_does_not_exist(aiml_folder)
def test_create_file_with_content_with_extra(self): temp_folder = self.get_tmp_folder() test_file = temp_folder + os.sep + "test.file" self.ensure_file_does_not_exist(test_file) AdminTool.create_file_with_content(test_file, "test data", extra="Extra") self.assertTrue(os.path.exists(test_file)) self.ensure_file_does_not_exist(test_file)
def test_create_file_with_content(self): temp_folder = self.get_tmp_folder() test_file = temp_folder + os.sep + "test.file" self.ensure_file_does_not_exist(test_file) AdminTool.create_file_with_content(test_file, "test data") self.assertTrue(os.path.exists(test_file)) self.ensure_file_does_not_exist(test_file)
def test_create_shell_script_windows_socket(self): temp_folder = self.get_tmp_folder() shell_script = temp_folder + os.sep + "socket.cmd" self.ensure_file_does_not_exist(shell_script) AdminTool.create_shell_script(temp_folder, 'socket', 'windows') self.assertTrue(os.path.exists(shell_script)) self.ensure_file_does_not_exist(shell_script)
def test_create_shell_script_unix_twitter(self): temp_folder = self.get_tmp_folder() shell_script = temp_folder + os.sep + "twitter.sh" self.ensure_file_does_not_exist(shell_script) AdminTool.create_shell_script(temp_folder, 'twitter', 'unix') self.assertTrue(os.path.exists(shell_script)) self.ensure_file_does_not_exist(shell_script)
def test_create_config_file_unknown(self): temp_folder = self.get_tmp_folder() config_file = temp_folder + os.sep + "config.yaml" self.ensure_file_does_not_exist(config_file) with self.assertRaises(Exception): AdminTool.create_config_file(temp_folder, "unknown") self.ensure_file_does_not_exist(config_file)
def test_create_config_file_socket(self): temp_folder = self.get_tmp_folder() config_file = temp_folder + os.sep + "config.yaml" self.ensure_file_does_not_exist(config_file) AdminTool.create_config_file(temp_folder, "socket") self.assertTrue(os.path.exists(config_file)) self.ensure_file_does_not_exist(config_file)
def test_create_logging_file_unix(self): temp_folder = self.get_tmp_folder() logging_file = temp_folder + os.sep + "logging.yaml" self.ensure_file_does_not_exist(logging_file) AdminTool.create_logging_file(temp_folder, "unix") self.assertTrue(os.path.exists(logging_file)) self.ensure_file_does_not_exist(logging_file)
def test_make_executable(self): temp_folder = self.get_tmp_folder() test_file = temp_folder + os.sep + "test.file" self.ensure_file_does_not_exist(test_file) AdminTool.create_file_with_content(test_file, "test data") AdminTool.make_executable(test_file) self.assertTrue(os.path.exists(test_file)) self.ensure_file_does_not_exist(test_file)
def test_create_shell_script_unknown_unknown(self): temp_folder = self.get_tmp_folder() shell_script = temp_folder + os.sep + "unknown.cmd" self.ensure_file_does_not_exist(shell_script) with self.assertRaises(Exception): AdminTool.create_shell_script(temp_folder, 'unknown', 'unknown') self.ensure_file_does_not_exist(shell_script)
def test_create_sub_folder(self): temp_folder = self.get_tmp_folder() test_folder = temp_folder + os.sep + "prgytest" self.ensure_folder_does_not_exist(test_folder) AdminTool.create_sub_folder(temp_folder, "prgytest") self.assertTrue(os.path.exists(test_folder)) self.ensure_folder_does_not_exist(test_folder)
def test_create_initial_properties(self): temp_folder = self.get_tmp_folder() AdminTool.create_sub_folder(temp_folder, "config") props_file = temp_folder + os.sep + "config" + os.sep + "properties.txt" self.ensure_file_does_not_exist(props_file) AdminTool.create_initial_properties(temp_folder) self.assertTrue(os.path.exists(props_file)) self.ensure_file_does_not_exist(props_file)
def test_create_aiml_folder_with_defaults(self): temp_folder = self.get_tmp_folder() aiml_folder = temp_folder + os.sep + "aiml" self.ensure_folder_does_not_exist(aiml_folder) aiml_file = temp_folder + os.sep + "aiml" + os.sep + "hello.aiml" self.ensure_file_does_not_exist(aiml_file) AdminTool.create_aiml_folder(temp_folder, True) self.assertTrue(os.path.exists(aiml_folder)) self.assertTrue(os.path.exists(aiml_file)) self.ensure_file_does_not_exist(aiml_file) self.ensure_folder_does_not_exist(aiml_folder)
def test_create_script_without_path(self): temp_folder = self.get_tmp_folder() args = Mock() args.location = temp_folder args.app = 'console' args.os = 'unix' shell_script = temp_folder + os.sep + "console.sh" self.ensure_file_does_not_exist(shell_script) AdminTool.create_script(args) self.assertTrue(os.path.exists(shell_script)) self.ensure_file_does_not_exist(shell_script)
def test_make_executable(self): tmp_dir = self.get_temp_dir() + os.sep + "programy" if os.path.exists(tmp_dir): shutil.rmtree(tmp_dir) os.mkdir(tmp_dir) filepath = tmp_dir + os.sep + "file1.txt" self.create_file(filepath) self.assertTrue(os.path.exists(filepath)) AdminTool.make_executable(filepath) if os.path.exists(tmp_dir): shutil.rmtree(tmp_dir)
def test_extract_bot_with_remove(self): tool = AdminTool() tmp_dir = self.get_temp_dir() + os.sep + "programy" if os.path.exists(tmp_dir): shutil.rmtree(tmp_dir) os.mkdir(tmp_dir) shutil.copyfile( os.path.dirname(__file__) + os.sep + "bot.zip", tmp_dir + os.sep + "bot.zip") tool.extract_bot(tmp_dir + os.sep + "bot.zip", path=tmp_dir, remove_after=True) self.assertFalse(os.path.exists(tmp_dir + os.sep + "bot.zip")) self.assertTrue(os.path.exists(tmp_dir + os.sep + "test1.txt")) self.assertTrue(os.path.exists(tmp_dir + os.sep + "test2.txt")) shutil.rmtree(tmp_dir)
def test_delete_folder_contents(self): tmp_dir = self.get_temp_dir() + os.sep + "programy" if os.path.exists(tmp_dir): shutil.rmtree(tmp_dir) os.mkdir(tmp_dir) src_dir = tmp_dir + os.sep + "src" os.mkdir(src_dir) src_sub_dir = tmp_dir + os.sep + "src" + os.sep + "sub" os.mkdir(src_sub_dir) dest_dir = tmp_dir + os.sep + "dest" os.mkdir(dest_dir) self.create_file(src_dir + os.sep + "file1.txt") self.create_file(src_dir + os.sep + "file2.txt") self.create_file(src_dir + os.sep + "file3.txt") self.create_file(src_dir + os.sep + "sub" + os.sep + "file4.txt") self.assertTrue(os.path.exists(src_dir + os.sep + "file1.txt")) self.assertTrue(os.path.exists(src_dir + os.sep + "file2.txt")) self.assertTrue(os.path.exists(src_dir + os.sep + "file3.txt")) self.assertTrue( os.path.exists(src_dir + os.sep + "sub" + os.sep + "file4.txt")) AdminTool.delete_folder_contents(tmp_dir) self.assertFalse(os.path.exists(src_dir + os.sep + "file1.txt")) self.assertFalse(os.path.exists(src_dir + os.sep + "file2.txt")) self.assertFalse(os.path.exists(src_dir + os.sep + "file3.txt")) self.assertFalse( os.path.exists(src_dir + os.sep + "sub" + os.sep + "file4.txt")) if os.path.exists(tmp_dir): shutil.rmtree(tmp_dir)
def test_make_all_executable(self): tmp_dir = self.get_temp_dir() + os.sep + "programy" if os.path.exists(tmp_dir): shutil.rmtree(tmp_dir) os.mkdir(tmp_dir) src_dir = tmp_dir + os.sep + "src" os.mkdir(src_dir) src_sub_dir = tmp_dir + os.sep + "src" + os.sep + "sub" os.mkdir(src_sub_dir) dest_dir = tmp_dir + os.sep + "dest" os.mkdir(dest_dir) self.create_file(src_dir + os.sep + "file1.txt") self.create_file(src_dir + os.sep + "file2.txt") self.create_file(src_dir + os.sep + "file3.txt") self.create_file(src_dir + os.sep + "sub" + os.sep + "file4.txt") AdminTool.make_all_executable(tmp_dir) if os.path.exists(tmp_dir): shutil.rmtree(tmp_dir)
def __init__(self): AdminTool.__init__(self) self.text = ""
def test_zip_dir_name_from_filename(self): self.assertEqual("filename", AdminTool.zip_dir_name_from_filename('filename.zip')) self.assertEqual("filename", AdminTool.zip_dir_name_from_filename('filename'))