Exemple #1
0
 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]"))
Exemple #2
0
    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)
Exemple #3
0
 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"))
Exemple #4
0
    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)
Exemple #5
0
    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)
Exemple #6
0
    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)
Exemple #7
0
    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)
Exemple #8
0
    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)
Exemple #9
0
    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)
Exemple #10
0
    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)
Exemple #11
0
    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)
Exemple #12
0
    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)
Exemple #13
0
    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)
Exemple #14
0
    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)
Exemple #15
0
    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)
Exemple #16
0
    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)
Exemple #17
0
    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)
Exemple #18
0
    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)
Exemple #19
0
    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)
Exemple #20
0
    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)
Exemple #21
0
    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)
Exemple #22
0
    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)
Exemple #23
0
    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)
Exemple #24
0
    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)
Exemple #25
0
    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)
Exemple #26
0
    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)
Exemple #27
0
    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)
Exemple #28
0
    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)
Exemple #29
0
    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)
Exemple #30
0
    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)
Exemple #31
0
    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)
Exemple #32
0
    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)
Exemple #33
0
    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)
Exemple #34
0
    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)
Exemple #35
0
 def __init__(self):
     AdminTool.__init__(self)
     self.text = ""
Exemple #36
0
 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'))