Exemple #1
0
    def ready(self):
        """
        The ready function is trigger only on events like server start up and server reload
        """
        # print "***************You are in Core Katana App Config Class***************"
        nav_obj = Navigator()

        base_directory = nav_obj.get_katana_dir()
        warrior_dir = nav_obj.get_warrior_dir()
        config_file_name = "wf_config.json"
        config_json_file = join_path(base_directory, "config.json")
        settings_file_path = get_abs_path(join_path("wui", "settings.py"), base_directory)
        core_index_obj = CoreIndex(base_directory, settings_file_path=settings_file_path)

        available_apps = core_index_obj.get_available_apps()
        settings_apps = core_index_obj.get_apps_from_settings_file()

        AppInformation.information = Apps()

        AppInformation.information.set_apps({'base_directory': base_directory,
                                             'config_file_name': config_file_name,
                                             'available_apps': available_apps,
                                             'settings_apps': settings_apps})

        ordered_json = validate_config_json(read_json_data(config_json_file), warrior_dir)
        with open(config_json_file, "w") as f:
            f.write(json.dumps(ordered_json, indent=4))
def read_config_file(request):
    nav_obj = Navigator()
    config_file_path = join_path(nav_obj.get_katana_dir(), "config.json")
    data = read_json_data(config_file_path)
    if data is None:
        data = False
    return JsonResponse(data)
def index(request):
    navigator = Navigator()
    path_to_config = navigator.get_katana_dir() + os.sep + "config.json"
    config = json.loads(open(path_to_config).read())
    fpath = config['projdir']
    template = loader.get_template("./listAllProjects.html")
    files = glob.glob(fpath + "*/*.xml")

    tt = navigator.get_dir_tree_json(fpath)
    tt['state'] = {
        'opened': True
    }
    print(tt)

    fulljsonstring = str(json.loads(json.dumps(tt)))
    fulljsonstring = fulljsonstring.replace('u"', "'").replace("u'",
                                                               '"').replace(
                                                                   "'", '"')
    fulljsonstring = fulljsonstring.replace('None', '""')

    context = {
        'title': 'List of Projects',
        'docSpec': 'projectSpec',
        'treejs': fulljsonstring,
        'listOfFiles': files
    }
    context.update(csrf(request))
    return HttpResponse(template.render(context, request))
Exemple #4
0
 def __init__(self, template, file_path):
     self.navigator = Navigator()
     self.template = template
     self.file_path = file_path
     self.template_data = read_xml_get_json(template, ordered_dict=True)
     self.data = read_xml_get_json(file_path, ordered_dict=True)
     self.output = {"status": True, "message": ""}
     self.root = "TestSuite"
def get_file_explorer_data(request):
    nav_obj = Navigator()
    if "data[start_dir]" in request.POST and request.POST["data[start_dir]"] != "false":
        start_dir = request.POST["data[start_dir]"]
    elif "data[path]" in request.POST and request.POST["data[path]"] != "false":
        start_dir = get_parent_directory(request.POST["data[path]"])
    else:
        start_dir = join_path(nav_obj.get_warrior_dir(), "Warriorspace")
    output = nav_obj.get_dir_tree_json(start_dir_path=start_dir)
    return JsonResponse(output)
Exemple #6
0
 def __init__(self, template, file_path):
     """ Constructor of the VerifyCaseFile class """
     self.navigator = Navigator()
     self.template = template
     self.file_path = file_path
     self.template_data = read_xml_get_json(template, ordered_dict=True)
     self.data = read_xml_get_json(file_path, ordered_dict=True)
     self.output = {"status": True, "message": ""}
     self.root = "TestWrapper"
     self.major = ("Details", "Requirements", "Steps")
Exemple #7
0
 def __init__(self, data_file, ref_data_file):
     self.data_file = data_file
     self.data = read_xml_get_json(data_file)
     self.ref_data_file = ref_data_file
     self.nav_obj = Navigator()
     self.dependency_template = join_path(self.nav_obj.get_katana_dir(),
                                          "native", "settings", "static",
                                          "settings", "base_templates",
                                          "empty.xml")
     self.ref_data = self._get_ref_data()
     self.dependency_dict = self.__get_dependency_dict()
Exemple #8
0
 def __init__(self, filepath):
     self.navigator = Navigator()
     self.app_name = get_sub_folders(
         join_path(filepath, "warriorframework_py3", "katana", "wapps"))[0]
     self.path_to_app = join_path(filepath, "warriorframework_py3",
                                  "katana", "wapps", self.app_name)
     self.wf_config_file = join_path(self.path_to_app, "wf_config.json")
     self.urls_inclusions = []
     self.mandatory_fields = [
         "app", "version", "warrior-compatibility",
         "warrior-incompatibility"
     ]
Exemple #9
0
def save_warhorn_config_file(request):
    nav_obj = Navigator()
    directory = request.POST.get('directory')
    if directory == "default":
        directory = os.path.join(nav_obj.get_katana_dir(), "wapps",
                                 "assembler", ".data")
    filepath = os.path.join(directory, request.POST.get('filename') + ".xml")
    json_data = json.loads(request.POST.get('json_data'))
    json_data["data"]["warriorframework"] = "Test"
    data = xmltodict.unparse(json_data)
    response = _save_file(filepath, data)

    return JsonResponse(response)
 def __init__(self):
     """
     Constructor for execution app
     """
     self.nav = Navigator()
     self.katana_dir = os.path.dirname(native.__path__[0])
     self.wf_dir = os.path.dirname(self.katana_dir)
     self.warrior = os.path.join(self.wf_dir, 'warrior', 'Warrior')
     self.default_ws = os.path.join(self.wf_dir, 'warrior', 'Warriorspace')
     self.templates_dir = os.path.join(templates_dir, 'execution')
     self.jira_settings_file = os.path.join(self.wf_dir, 'warrior', 'Tools',
                                            'jira', 'jira_config.xml')
     self.execution_settings_json = os.path.join(templates_dir, 'execution',
                                                 'execution_settings.json')
     self.config_json = os.path.join(self.katana_dir, 'config.json')
class CoreView(View):
    
    def __init__(self):
        self.navigator = Navigator()

    def get_user_data(self):
        json_file = self.navigator.get_katana_dir() + '/user_profile.json'
        with open(json_file, 'r') as f:
            json_data = json.load(f)
        return json_data

    def get(self, request):
        """
        This get function get information about the installed apps

        Args:
            request: HttpRequest that contains metadata about the request

        Returns:
            HttpResponse: containing an HTML template and data
                HTML template: core/index.html
                Data: [{"url":"/url/of/app", "name": "app_name",
                        "icon": "icon_name", "color": "red"}]

        """

        template = 'core/index.html'

        return render(request, template, {"apps": AppInformation.information.apps, "userData": self.get_user_data()})
def get_jstree_dir(request):
    """
        Prepare the json for jstree to use
    """
    config = read_json_data(JSON_CONFIG)
    data = Navigator().get_dir_tree_json(config["idfdir"])
    data["text"] = config["idfdir"]
    # print json.dumps(data, indent=4)
    return JsonResponse(data)
def getProjectDataBack(request):
    print("Got something back in request")
    navigator = Navigator()
    path_to_config = navigator.get_katana_dir() + os.sep + "config.json"
    config = json.loads(open(path_to_config).read())
    fpath = config['projdir']
    fname = request.POST.get('filetosave')
    ijs = request.POST.get('json')  # This is a json string
    print(ijs)
    #print "--------------TREE----------------"
    if fname.find(".xml") < 2: fname = fname + ".xml"

    #fd = open(fpath + os.sep + fname+ ".json",'w');
    #fd.write(ijs);
    #fd.close();

    xml = xmltodict.unparse(json.loads(ijs), pretty=True)
    print("save to ", fpath + os.sep + fname)
    fd = open(fpath + os.sep + fname, 'w')
    fd.write(xml)
    fd.close()
    return redirect(request.META['HTTP_REFERER'])
Exemple #14
0
    def __init__(self):
        self.PYTHON_EXE = sys.executable
        self.WARRIOR_DIR = Navigator().get_warrior_dir()
        self.PLUGINSPACE_DIR = os.path.join(self.WARRIOR_DIR, "plugins", "mef18_plugin", "pluginspace")
        self.PLUGINSPACE_WDF_DIR = os.path.join(self.PLUGINSPACE_DIR, "data")
        self.PLUGINSPACE_TC_DIR = os.path.join(self.PLUGINSPACE_DIR, "testcases")
        self.PLUGINSPACE_TD_VC_DIR = os.path.join(self.PLUGINSPACE_DIR, "config_files")
        self.WARRIOR_EXE = os.path.join(self.WARRIOR_DIR, 'Warrior')
        self.TEMPLATE_WDF = "xml_templates/WDF_mef18_template.xml"
        self.TEMPLATE_WDF_CPE = "xml_templates/WDF_mef18_cpe_template.xml"
        self.TEMPLATE_VC = "xml_templates/VC_mef18_template.xml"
        self.FILENAME_WDF = "WDF_mef18.xml"
        self.FILENAME_WDF_CPE = "WDF_mef18_cpe.xml"
        self.FILENAME_TC_WAKEUP = "TC_mef18_tru_wakeup.xml"
        self.FILENAME_TC_WAKEUP_CPE = "TC_mef18_cpe_wakeup.xml"
        self.FILENAME_TC_NAPTIME = "TC_mef18_tru_naptime.xml"

        self._instance_lock = threading.RLock()
        self.status = self.STATUS_IDLE
Exemple #15
0
class CliDataFileClass(View):
    nav_obj = Navigator()
    app_directory = join_path(nav_obj.get_katana_dir(), "wapps", "cli_data")
    app_static_dir = join_path(app_directory, "static")

    def get(self, request):
        filepath = request.GET.get('path')
        # filepath = join_path(CliDataFileClass.app_static_dir, "base_templates", "test.xml")
        base_filepath = join_path(CliDataFileClass.app_static_dir,
                                  "base_templates", "empty.xml")
        if filepath == "false":
            filepath = base_filepath
            name = "Untitled"
        else:
            name, _ = os.path.splitext(get_dir_from_path(filepath))
        vcdc_obj = VerifyCliDataClass(filepath, base_filepath)
        json_data = vcdc_obj.verify_contents()
        return JsonResponse({
            "contents": json_data,
            "name": name,
            "filepath": get_parent_dir_path(filepath)
        })

    def post(self, request):
        json_data = json.loads(request.POST.get('json_data'))
        data = xmltodict.unparse(json_data)
        directory = request.POST.get('directory')
        filepath = os.path.join(directory,
                                request.POST.get('filename') + ".xml")
        message = ""
        saved = True
        try:
            with open(filepath, 'w') as f:
                f.write(data)
        except Exception as e:
            saved = False
            message = e
        return JsonResponse({"saved": saved, "message": message})
Exemple #16
0
def save_and_run_warhorn_config_file(request):
    nav_obj = Navigator()
    directory = request.POST.get('directory')
    if directory == "default":
        directory = os.path.join(nav_obj.get_katana_dir(), "wapps",
                                 "assembler", ".data")
    filepath = os.path.join(directory, request.POST.get('filename') + ".xml")
    json_data = json.loads(request.POST.get('json_data'))
    json_data["data"]["warriorframework"] = "Test"
    data = xmltodict.unparse(json_data)
    response = _save_file(filepath, data)
    nav_obj = Navigator()
    warhorn_dir = nav_obj.get_warhorn_dir()
    current_dir = os.getcwd()
    output = ""
    if response["saved"]:
        os.chdir(warhorn_dir)
        output = subprocess.Popen(["python3", "warhorn.py", filepath],
                                  stdout=subprocess.PIPE).communicate()[0]
        os.chdir(current_dir)
        os.remove(filepath)
    return JsonResponse({"output": output.decode('utf-8')})
Exemple #17
0
# -*- coding: utf-8 -*-

import json
import os
import subprocess
import xmltodict
from django.http import JsonResponse
from django.shortcuts import render
from django.views import View
from wapps.assembler.assembler_utils.repository_details import KwRepositoryDetails
from wapps.assembler.assembler_utils.verify_file_contents import VerifyFileContents
from utils.directory_traversal_utils import delete_dir
from utils.git_utils import get_repository_name, check_url_is_a_valid_repo
from utils.navigator_util import Navigator
nav_obj = Navigator()
REF_FILE = os.path.join(nav_obj.get_katana_dir(), "wapps", "assembler",
                        "static", "assembler", "base_templates", "empty.xml")


class AssemblerView(View):
    def get(self, request):
        return render(request, 'assembler/assembler.html')


class ConfigurationFileOps(View):
    def post(self, request):
        template = request.POST.get('filepath')
        filename = "Untitled"
        final_data = {}

        if template == "false":
Exemple #18
0
class AppValidator:
    def __init__(self, filepath):
        self.navigator = Navigator()
        self.app_name = get_sub_folders(
            join_path(filepath, "warriorframework_py3", "katana", "wapps"))[0]
        self.path_to_app = join_path(filepath, "warriorframework_py3",
                                     "katana", "wapps", self.app_name)
        self.wf_config_file = join_path(self.path_to_app, "wf_config.json")
        self.urls_inclusions = []
        self.mandatory_fields = [
            "app", "version", "warrior-compatibility",
            "warrior-incompatibility"
        ]

    def is_valid(self):
        output = {"status": True, "message": ""}
        if os.path.exists(self.wf_config_file):
            data = read_json_data(self.wf_config_file)
            if data is not None:
                for field in self.mandatory_fields:
                    if output["status"] and field not in data:
                        output["status"] = False
                        output[
                            "message"] = "wf_config.json is not in the correct format."
                        print("-- An Error Occurred -- {0}".format(
                            output["message"]))

                if output["status"]:
                    output = self.__verify_app_details(data["app"])

                # validate version compatibility
                if output["status"]:
                    output = self.__is_compatible(data)

                # validate databases if any
                if output["status"] and "database" in data:
                    if isinstance(data["database"], list):
                        for db_details in data["database"]:
                            if output["status"]:
                                output = self.__verify_db_details(db_details)
                    else:
                        output = self.__verify_db_details(data["database"])
            else:
                output["status"] = False
                output[
                    "message"] = "wf_config.json is not in the correct format."
                print("-- An Error Occurred -- {0}".format(output["message"]))

            if output["status"]:
                output = self.__validate_static_directory()
        else:
            output["status"] = False
            output["message"] = "wf_config.json does not exist."
            print("-- An Error Occurred -- {0}".format(output["message"]))
        return output

    def __verify_app_details(self, app_details):
        output = {"status": True, "message": ""}
        if "name" not in app_details or "url" not in app_details or "include" not in app_details:
            print(
                "-- An Error Occurred -- wf_config.json file is not in the correct format."
            )
            output["status"] = False
        else:
            self.urls_inclusions.append("url(r'^" + app_details["url"] +
                                        "', include('" +
                                        app_details["include"] + "')),")
            path_dir = app_details["include"].split(".")
            path_urls = ""
            for d in range(2, len(path_dir)):
                path_urls += os.sep + path_dir[d]
            path_urls = path_urls.strip(os.sep)
            path_urls += ".py"
            path_to_urls_abs = join_path(self.path_to_app, path_urls)
            if not os.path.isfile(path_to_urls_abs):
                output["status"] = False
                output["message"] = "Package {0} does not exist.".format(
                    app_details["include"])
                print("-- An Error Occurred -- {0}".format(output["message"]))
        return output

    def __is_compatible(self, data):
        output = {"status": True, "message": ""}
        warrior_version = self.navigator.get_wf_version()
        all_warrior_versions = self.navigator.get_all_wf_versions()
        allowed, bounds, err_alwd = get_version_list(
            data[self.mandatory_fields[2]], all_warrior_versions)
        disallowed, excluded_bounds, err_disalwd = get_version_list(
            data[self.mandatory_fields[3]], all_warrior_versions)

        in_allowed = check_against_version_list(warrior_version, allowed,
                                                bounds)
        in_disallowed = check_against_version_list(warrior_version, disallowed,
                                                   excluded_bounds)

        if not in_allowed:
            output["status"] = False
            if not err_alwd:
                output["message"] = "-- An Error Occurred -- {0} (Version: {1}) incompatible with " \
                                    "the current WarriorFramework (Version: {2})."\
                    .format(self.app_name, data["version"], warrior_version)
            else:
                output[
                    "message"] = "-- An Error Occurred -- Compatible versions could not be verified."
        elif in_disallowed:
            output["status"] = False
            output["message"] = "-- An Error Occurred -- {0} (Version: {1}) incompatible with " \
                                "the current WarriorFramework (Version: {2})." \
                .format(self.app_name, data["version"], warrior_version)
        elif not in_disallowed and err_disalwd:
            output["status"] = False
            output[
                "message"] = "-- An Error Occurred -- Incompatible versions could not be verified."
        return output

    def __verify_db_details(self, db_details):
        output = {"status": True, "message": ""}
        for key in db_details:
            if not key.startswith(self.app_name):
                output["status"] = False
                output[
                    "message"] = "wf_config.json file is not formatted correctly"
                print("-- An Error Occurred -- {0}".format(output["message"]))
        return output

    def __validate_static_directory(self):
        output = {"status": True, "message": ""}
        if os.path.isdir(join_path(self.path_to_app, "static")):
            subs = get_sub_dirs_and_files(join_path(self.path_to_app,
                                                    "static"))
            if len(subs["files"]) > 0:
                output["status"] = False
                output["message"] = "static directory does not follow the required " \
                                    "directory structure."
                print("-- An Error Occurred -- {0}".format(output["message"]))
            else:
                if not os.path.isdir(
                        join_path(self.path_to_app, "static", self.app_name)):
                    output["status"] = False
                    output["message"] = "static directory does not follow the required " \
                                        "directory structure."
                    print("-- An Error Occurred -- {0}".format(
                        output["message"]))
                else:

                    subs_files = get_paths_of_subfiles(
                        join_path(self.path_to_app, "static", self.app_name),
                        re.compile("\.js$"))
                    path_to_js = join_path(self.path_to_app, "static",
                                           self.app_name, "js")
                    for sub_file in subs_files:
                        if not sub_file.startswith(path_to_js):
                            output["status"] = False
                            output[
                                "message"] = "A .js file cannot be outside the 'js' folder."
                            print("-- An Error Occurred -- {0}".format(
                                output["message"]))
        return output
Exemple #19
0
class VerifyFileContents:
    def __init__(self, data_file, ref_data_file):
        self.data_file = data_file
        self.data = read_xml_get_json(data_file)
        self.ref_data_file = ref_data_file
        self.nav_obj = Navigator()
        self.dependency_template = join_path(self.nav_obj.get_katana_dir(),
                                             "native", "settings", "static",
                                             "settings", "base_templates",
                                             "empty.xml")
        self.ref_data = self._get_ref_data()
        self.dependency_dict = self.__get_dependency_dict()

    def _get_ref_data(self):
        data = read_xml_get_json(self.ref_data_file)
        dependency_data = read_xml_get_json(self.dependency_template)
        data["data"]["warhorn"] = copy.deepcopy(
            dependency_data["data"]["warhorn"])
        return data

    def __get_dependency_dict(self):
        output = {}
        for el in self.ref_data["data"]["warhorn"]["dependency"]:
            output[el["@name"]] = {
                "version": el["@version"],
                "description": el["@description"]
            }
        return output

    def verify_file(self):
        output = {"status": True, "message": ""}

        if self.data is None:
            output["status"] = False
            output[
                "message"] = "An error occurred while trying to read {0}".format(
                    self.data_file)
        elif "data" not in self.data:
            output["status"] = False
            output[
                "message"] = "{0} does not seem to be in correct format".format(
                    self.data_file)

        if output["status"]:
            self.verify_dependency_json()
            self.verify_tools_data()
            self.verify_drivers_json()
            self.verify_warriorspace_data()

        return output

    def verify_dependency_json(self, ):
        flag = True
        if "warhorn" not in self.data["data"]:
            self.data["data"]["warhorn"] = copy.deepcopy(
                self.ref_data["data"]["warhorn"])
            flag = False
        if "dependency" not in self.data["data"]["warhorn"]:
            self.data["data"]["warhorn"]["dependency"] = copy.deepcopy(
                self.ref_data["data"]["warhorn"]["dependency"])
            flag = False
        if not isinstance(self.data["data"]["warhorn"]["dependency"], list):
            self.data["data"]["warhorn"]["dependency"] = [
                self.data["data"]["warhorn"]["dependency"]
            ]

        if flag:
            data = copy.deepcopy(self.data["data"]["warhorn"]["dependency"])
            extra_dependencies = set()
            for i in range(0, len(data)):
                for key, value in list(data[i].items()):
                    if key == "@name":
                        if value in self.dependency_dict:
                            data[i]["version"] = self.dependency_dict[value][
                                "version"]
                            data[i]["description"] = self.dependency_dict[
                                value]["description"]
                            try:
                                module_name = __import__(value)
                                some_var = module_name.__version__
                            except ImportError:
                                data[i]["installed"] = False
                                data[i]["matched"] = False
                            except Exception as e:
                                print("-- An Exception Occurred -- while getting details about " \
                                      "{0}: {1}".format(value, e))
                                data[i]["installed"] = False
                                data[i]["matched"] = False
                            else:
                                data[i]["installed"] = some_var
                                if self.dependency_dict[value] == some_var:
                                    data[i]["matched"] = True
                                elif self.dependency_dict[value] > some_var:
                                    data[i]["matched"] = "lower"
                                else:
                                    data[i]["matched"] = "higher"
                            break
                        else:
                            extra_dependencies.add(i)
            dependency_list = []
            for i in range(0, len(data)):
                if i not in extra_dependencies:
                    dependency_list.append(copy.deepcopy(data[i]))
            self.data["data"]["warhorn"]["dependency"] = copy.deepcopy(
                dependency_list)

    def verify_tools_data(self):
        if "tools" not in self.data["data"]:
            self.data["data"]["tools"] = copy.deepcopy(
                self.ref_data["data"]["tools"])
        else:
            for key, value in list(self.ref_data["data"]["tools"].items()):
                if key not in self.data["data"]["tools"]:
                    self.data["data"]["tools"][key] = self.ref_data["data"][
                        "tools"][key]

            url = self.data["data"]["tools"]["@url"]
            if url != "":
                self.data["data"]["tools"]["name"] = get_repository_name(
                    url=url)
                self.data["data"]["tools"][
                    "available"] = check_url_is_a_valid_repo(url=url)
            else:
                self.data["data"]["tools"]["available"] = False

    def verify_drivers_json(self):
        flag = True
        if "drivers" not in self.data["data"]:
            self.data["data"]["drivers"] = copy.deepcopy(
                self.ref_data["data"]["drivers"])
            flag = False

        if "repository" not in self.data["data"]["drivers"]:
            self.data["data"]["drivers"]["repository"] = copy.deepcopy(
                self.ref_data["data"]["drivers"]["repository"])
            flag = False

        if not isinstance(self.data["data"]["drivers"]["repository"], list):
            self.data["data"]["drivers"]["repository"] = [
                self.data["data"]["drivers"]["repository"]
            ]

        if flag:
            for i in range(0, len(self.data["data"]["drivers"]["repository"])):
                for key, value in list(self.ref_data["data"]["drivers"]
                                       ["repository"].items()):
                    if key not in self.data["data"]["drivers"]["repository"][
                            i]:
                        if key != "driver":
                            self.data["data"]["drivers"]["repository"][i][
                                key] = self.ref_data["data"]["drivers"][
                                    "repository"]["key"]
                        else:
                            self.data["data"]["drivers"]["repository"][i][
                                key] = copy.deepcopy(
                                    self.ref_data["data"]["drivers"]
                                    ["repository"][key])

                            if not isinstance(
                                    self.data["data"]["drivers"]["repository"]
                                [i][key], list):
                                self.data["data"]["drivers"]["repository"][i][
                                    key] = [
                                        self.data["data"]["drivers"]
                                        ["repository"][i][key]
                                    ]

                url = self.data["data"]["drivers"]["repository"][i]["@url"]
                if url != "":
                    self.data["data"]["drivers"]["repository"][i][
                        "name"] = get_repository_name(url=url)
                    available = check_url_is_a_valid_repo(url=url)
                    self.data["data"]["drivers"]["repository"][i][
                        "available"] = available
                    if available:
                        drivers_data = []
                        drivers_index = set()
                        temp_directory = os.path.join(
                            self.nav_obj.get_katana_dir(), "wapps",
                            "assembler", ".data")
                        kw_repo_obj = KwRepositoryDetails(url, temp_directory)
                        drivers = set(kw_repo_obj.get_pd_names())

                        if not isinstance(
                                self.data["data"]["drivers"]["repository"][i]
                            ["driver"], list):
                            self.data["data"]["drivers"]["repository"][i][
                                "driver"] = [
                                    self.data["data"]["drivers"]["repository"]
                                    [i]["driver"]
                                ]

                        for j in range(
                                0,
                                len(self.data["data"]["drivers"]["repository"]
                                    [i]["driver"])):
                            if "@name" not in self.data["data"]["drivers"][
                                    "repository"][i]["driver"][j]:
                                self.data["data"]["drivers"]["repository"][i][
                                    "driver"][j]["@name"] = self.ref_data[
                                        "data"]["drivers"]["repository"][
                                            "driver"]["@name"]
                            else:
                                if self.data["data"]["drivers"]["repository"][
                                        i]["driver"][j]["@name"] in drivers:
                                    drivers.remove(self.data["data"]["drivers"]
                                                   ["repository"][i]["driver"]
                                                   [j]["@name"])
                                else:
                                    drivers_index.add(j)
                            if "@clone" not in self.data["data"]["drivers"][
                                    "repository"][i]["driver"][j]:
                                self.data["data"]["drivers"]["repository"][i][
                                    "driver"][j]["@clone"] = self.ref_data[
                                        "data"]["drivers"]["repository"][
                                            "driver"]["@clone"]

                        for j in range(
                                0,
                                len(self.data["data"]["drivers"]["repository"]
                                    [i]["driver"])):
                            if j not in drivers_index:
                                drivers_data.append(
                                    copy.deepcopy(
                                        self.data["data"]["drivers"]
                                        ["repository"][i]["driver"][j]))
                        self.data["data"]["drivers"]["repository"][i][
                            "driver"] = copy.deepcopy(drivers_data)

                        for driver_name in drivers:
                            self.data["data"]["drivers"]["repository"][i][
                                "driver"].append({
                                    "@name": driver_name,
                                    "@clone": "no"
                                })

                        if os.path.isdir(kw_repo_obj.repo_directory):
                            delete_dir(kw_repo_obj.repo_directory)
                else:
                    self.data["data"]["drivers"]["repository"][i][
                        "available"] = False

    def verify_warriorspace_data(self):
        flag = True
        if "warriorspace" not in self.data["data"]:
            flag = False
            self.data["data"]["warriorspace"] = copy.deepcopy(
                self.ref_data["data"]["warriorspace"])

        if "repository" not in self.data["data"]["warriorspace"]:
            flag = False
            self.data["data"]["warriorspace"]["repository"] = copy.copy(
                self.ref_data["data"]["warriorspace"]["repository"])

        if not isinstance(self.data["data"]["warriorspace"]["repository"],
                          list):
            self.data["data"]["warriorspace"]["repository"] = [
                self.data["data"]["warriorspace"]["repository"]
            ]

        if flag:
            for i in range(
                    0, len(self.data["data"]["warriorspace"]["repository"])):
                for key, value in list(self.ref_data["data"]["warriorspace"]
                                       ["repository"].items()):
                    if key not in self.data["data"]["warriorspace"][
                            "repository"][i]:
                        self.data["data"]["warriorspace"]["repository"][i][
                            key] = self.ref_data["data"]["warriorspace"][
                                "repository"][key]

                url = self.data["data"]["warriorspace"]["repository"][i][
                    "@url"]
                if url != "":
                    self.data["data"]["warriorspace"]["repository"][i][
                        "name"] = get_repository_name(url=url)
                    self.data["data"]["warriorspace"]["repository"][i][
                        "available"] = check_url_is_a_valid_repo(url=url)
                else:
                    self.data["data"]["warriorspace"]["repository"][i][
                        "available"] = False
Exemple #20
0
import json

import os
import xmltodict
from django.http import JsonResponse
from django.shortcuts import render
from django.template.loader import render_to_string
from django.views import View
from utils.directory_traversal_utils import join_path, get_dir_from_path, get_parent_dir_path
from utils.json_utils import read_json_data
from utils.navigator_util import Navigator
from wapps.testwrapper.testwrapper_utils.defaults import impacts, on_errors, runmodes, iteration_types, contexts
from wapps.testwrapper.testwrapper_utils.get_drivers import GetDriversActions
from wapps.testwrapper.testwrapper_utils.verify_testwrapper_file import VerifyTestWrapperFile

navigator = Navigator()
CONFIG_FILE = join_path(navigator.get_katana_dir(), "config.json")
APP_DIR = join_path(navigator.get_katana_dir(), "wapps", "testwrapper")
STATIC_DIR = join_path(APP_DIR, "static", "testwrapper")
TEMPLATE = join_path(STATIC_DIR, "base_templates", "Untitled.xml")
DROPDOWN_DEFAULTS = read_json_data(join_path(STATIC_DIR, "base_templates", "dropdowns_data.json"))


clas TestWrapperView(View):

    def get(self, request):
        """
        Get Request Method
        """
        return render(request, 'testwrapper/cases.html')
class Execution(object):
    """
    Execution app class
    """
    def __init__(self):
        """
        Constructor for execution app
        """
        self.nav = Navigator()
        self.katana_dir = os.path.dirname(native.__path__[0])
        self.wf_dir = os.path.dirname(self.katana_dir)
        self.warrior = os.path.join(self.wf_dir, 'warrior', 'Warrior')
        self.default_ws = os.path.join(self.wf_dir, 'warrior', 'Warriorspace')
        self.templates_dir = os.path.join(templates_dir, 'execution')
        self.jira_settings_file = os.path.join(self.wf_dir, 'warrior', 'Tools',
                                               'jira', 'jira_config.xml')
        self.execution_settings_json = os.path.join(templates_dir, 'execution',
                                                    'execution_settings.json')
        self.config_json = os.path.join(self.katana_dir, 'config.json')

    def index(self, request):
        """
        Index page for exeution app
        """
        execution_settings_dict = update_jira_proj_list(
            self.jira_settings_file, self.execution_settings_json)
        #json.loads(open(self.execution_settings_json).read())
        start_dir = self.default_ws if execution_settings_dict['defaults']['start_dir'] == 'default' \
        else execution_settings_dict['defaults']['start_dir']
        execution_settings_dict['defaults']['start_dir'] = start_dir
        index_template = os.path.join(self.templates_dir, 'execution.html')

        return render(request, index_template, execution_settings_dict)

    def get_results_index(self, request):
        """
        Render the results index html to the client
        """
        fname = 'live_html_results'
        path = data_live_dir
        fpath = file_utils.get_new_filepath(fname, path, '.html')
        html_file = open(fpath, 'w')
        html_file.write('<div data-currentTable="1"> </div> ')
        html_file.close()

        result_setting = {'fpath': fpath}
        results_template = os.path.join(self.templates_dir,
                                        'execution_results.html')
        return render(request, results_template, result_setting)

    def get_html_results(self, request):
        """
        Update the html results by reading the live html results
        file sent in the request
        """
        data_dict = json.loads(request.GET.get('data'))
        fpath = data_dict['liveHtmlFpath']
        with open(fpath) as htmlfile:
            data = htmlfile.readlines()
        return HttpResponse(data)

    def delete_live_html_file(self, request):
        """
        delete the live html file created
        """
        status = 'success'
        try:
            data_dict = json.loads(request.GET.get('data'))
            fpath = data_dict['liveHtmlFpath']
            os.remove(fpath)
        except Exception as err:
            status = 'failure'

        return HttpResponse(status)

    def get_logfile_contents(self, request):
        """
        Update the html results by reading the live html results
        file sent in the request
        """
        data_dict = json.loads(request.GET.get('data'))
        logpath = data_dict['logpath']
        logtype = data_dict['logtype']
        op_data = {}
        logfile_name = logpath.split(os.sep)[-1]

        if str(logtype.lower()) == 'defects':
            contents = json.loads(open(logpath).read())

        if str(logtype.lower()) == 'console_logs':
            contents = open(logpath).read()
            contents = contents.replace('\n', '<br>')

        op_data['logfile_name'] = logfile_name
        op_data['contents'] = contents

        return JsonResponse(op_data)

    def cleanup_data_live_dir(self, request):
        """
        Update the html results by reading the live html results
        file sent in the request
        """
        status = 'success'
        try:
            for item in os.listdir(data_live_dir):
                path = os.path.join(data_live_dir, item)
                if os.path.isfile(
                        path) and not path.endswith('donotdeletethisfile.txt'):
                    os.remove(path)
                elif os.path.isdir(path):
                    shutil.rmtree(path, 'ignore_errors')
        except Exception as err:
            print("error ceaning up dir {0}".format(data_live_dir))
            print(err)
            status = 'failure'

        return HttpResponse(status)

    def get_ws(self, request):
        """
        return the dir tree json for warriorspace
        """
        data_dict = json.loads(request.GET.get('data'))
        ws_dir = data_dict['start_dir']
        layout = self.nav.get_dir_tree_json(ws_dir)
        return JsonResponse(layout)

    def execute_warrior(self, request):
        """
        Execute warrior command and send console logs to the client in a
        streaming fashion.
        """
        data_dict = json.loads(request.GET.get('data'))
        execution_file_list = data_dict['execution_file_list']
        cmd_string = data_dict['cmd_string']
        live_html_res_file = data_dict['liveHtmlFpath']
        config_json_dict = json.loads(open(self.config_json).read())
        python_path = config_json_dict['pythonpath']

        return StreamingHttpResponse(
            stream_warrior_output(self.warrior, cmd_string,
                                  execution_file_list, live_html_res_file,
                                  python_path))
def editProject(request):
    """
    Set up JSON object for editing a project file. 
    """
    navigator = Navigator()
    path_to_config = navigator.get_katana_dir() + os.sep + "config.json"
    config = json.loads(open(path_to_config).read())
    fpath = config['projdir']

    template = loader.get_template("./editProject.html")
    filename = request.GET.get('fname', 'NEW')

    # Create Mandatory empty object.
    xml_r = {}
    xml_r["Project"] = {}
    xml_r["Project"]["Details"] = {}
    xml_r["Project"]["Details"]["Name"] = ""  # ""
    xml_r["Project"]["Details"]["Title"] = ""  #OrderedDict([('$', '')])
    xml_r["Project"]["Details"]["Category"] = ""  #OrderedDict([('$', '')])
    xml_r["Project"]["Details"]["State"] = ""  #OrderedDict([('$', 'New')])
    xml_r["Project"]["Details"]["Date"] = ""  #OrderedDict([('$', '')])
    xml_r["Project"]["Details"]["Time"] = ""  #OrderedDict([('$', '')])
    xml_r["Project"]["Details"]["Datatype"] = ""  #OrderedDict([('$', '')])
    xml_r["Project"]["Details"]["Engineer"] = ""  #OrderedDict([('$', '')])
    xml_r["Project"]["Details"]["ResultsDir"] = ""  #OrderedDict([('$', '')])
    xml_r["Project"]["Details"]["default_onError"] = {
        '@action': '',
        '@value': ''
    }  #OrderedDict([('$', '')])
    xml_r["Project"]["Testsuites"] = []
    xml_r['Project']['filename'] = ""  #OrderedDict([('$', filename)]);

    if filename != 'NEW':
        xlines = open(filename.strip()).read()
        #xml_d = bf.data(fromstring(xlines)); #
        xml_d = xmltodict.parse(xlines, dict_constructor=dict)

        # Map the input to the response collector
        for xstr in ["Name", "Title", "Category", "Date", "Time", "Engineer", \
            "Datatype", "ResultsDir"]:
            try:
                xml_r["Project"]["Details"][xstr] = xml_d["Project"][
                    "Details"][xstr]
            except:
                pass

        try:
            xml_r['Project']['Testsuites'] = copy.copy(
                xml_d['Project']['Testsuites'])
        except:
            xml_r["Project"]["Testsuites"] = []
    else:
        filename = path_to_config + os.sep + "new.xml"

    fulljsonstring = str(json.loads(json.dumps(xml_r['Project'])))
    print(fulljsonstring)
    fulljsonstring = fulljsonstring.replace('u"', "'").replace("u'",
                                                               '"').replace(
                                                                   "'", '"')
    fulljsonstring = fulljsonstring.replace('None', '""')

    context = {
        'savefilename':
        os.path.split(filename)[1],
        'savefilepath':
        fpath,
        'fullpathname':
        filename,
        'myfile':
        filename,
        'docSpec':
        'projectSpec',
        'projectName':
        xml_r["Project"]["Details"]["Name"],
        'projectTitle':
        xml_r["Project"]["Details"]["Title"],
        'projectState':
        xml_r["Project"]["Details"]["State"],
        'projectEngineer':
        xml_r["Project"]["Details"]["Engineer"],
        'projectCategory':
        xml_r["Project"]["Details"]["Category"],
        'projectDate':
        xml_r["Project"]["Details"]["Date"],
        'projectTime':
        xml_r["Project"]["Details"]["Time"],
        'resultsDir':
        xml_r["Project"]["Details"]["ResultsDir"],
        'projectdefault_onError':
        xml_r["Project"]["Details"]["default_onError"].get('@action'),
        'projectdefault_onError_goto':
        xml_r["Project"]["Details"]["default_onError"]['@value'],
        #'fulljson': xml_r['Project']
        'fulljson':
        fulljsonstring,
    }
    #
    # I have to add json objects for every test suite.
    #
    return HttpResponse(template.render(context, request))
import os, sys, glob, copy
from collections import OrderedDict
from django.http import HttpResponse, JsonResponse
from django.template import loader, RequestContext
from xml.sax.saxutils import escape, unescape

from django.core.serializers import serialize
from django.db.models.query import QuerySet
from django.template import Library

import json
#from katana.utils.navigator_util import get_dir_tree_json
import xmltodict
from utils.navigator_util import Navigator

navigator = Navigator()
path_to_src_python_file = navigator.get_katana_dir() + os.sep + "config.json"


def old_index(request):
    return render(request, 'settings/index.html',
                  {"data": controls.get_location()})


def getEmpty():
    edata = {
        "Project": {
            "Testsuites": {
                "Testsuite": [{
                    "onError": {
                        "@action": "goto",
 def __init__(self):
     self.navigator = Navigator()
     self.static_dir = join_path(self.navigator.get_katana_dir(), "native",
                                 "settings", "static", "settings")
class Settings:
    def __init__(self):
        self.navigator = Navigator()
        self.static_dir = join_path(self.navigator.get_katana_dir(), "native",
                                    "settings", "static", "settings")

    def get_location(self):
        pass

    def smart_analysis_handler(self, request):
        mainFile = self.navigator.get_warrior_dir(
        ) + os.sep + 'Tools' + os.sep + 'connection' + os.sep + 'connect_settings.xml'
        if request.method == 'POST':
            val = xmltodict.unparse(
                {
                    'credentials': {
                        'system': json.loads(request.POST.get('data'))
                    }
                },
                pretty=True)
            with open(mainFile, 'w') as f:
                f.write(val)
        else:
            with open(mainFile, 'r') as f:
                mainDict = xmltodict.parse(f)['credentials']
            if mainDict is not None and not isinstance(mainDict['system'],
                                                       list):
                mainDict['system'] = [mainDict['system']]

            return mainDict

    def general_setting_handler(self, request):
        json_file = self.navigator.get_katana_dir() + os.sep + 'config.json'
        w_settings = self.navigator.get_warrior_dir(
        ) + 'Tools' + os.sep + 'w_settings.xml'
        elem_file = xml_controler.parse(w_settings)
        elem_file = elem_file.getroot()
        elem = self.search_by_name('def_dir', elem_file)
        def_dir_string = xml_controler.tostring(elem)
        def_dir_xml_obj = elem

        if request.method == 'POST':
            w_settings_data = {
                'Setting': {
                    'Logsdir': '',
                    'Resultsdir': '',
                    '@name': ''
                }
            }
            returned_json = json.loads(request.POST.get('data'))
            for k, v in list(w_settings_data['Setting'].items()):
                w_settings_data['Setting'][k] = returned_json[0][k]
                del returned_json[0][k]

            elem_file.remove(def_dir_xml_obj)
            val = xmltodict.unparse(w_settings_data, pretty=True)
            elem_file.insert(0, xml_controler.fromstring(val))
            with open(w_settings, 'wb') as f:
                f.write(xml_controler.tostring(elem_file))
            with open(json_file, 'w') as f:
                f.write(
                    json.dumps(returned_json[0],
                               indent=4,
                               separators=(',', ': ')))
        else:
            with open(json_file, 'r') as f:
                json_data = json.load(f)
            data = {
                'fromXml':
                xmltodict.parse(def_dir_string).get('Setting'),
                'fromJson':
                validate_config_json(json_data,
                                     self.navigator.get_warrior_dir())
            }
            return data

    def profile_setting_handler(self, request):
        json_file = self.navigator.get_katana_dir(
        ) + os.sep + 'user_profile.json'
        config_json_file = self.navigator.get_katana_dir(
        ) + os.sep + 'config.json'
        if request.method == 'POST':
            data = json.loads(request.POST.get('data'))
            with open(json_file, 'w') as f:
                f.write(
                    json.dumps(data[0],
                               sort_keys=True,
                               indent=4,
                               separators=(',', ': ')))
            with open(config_json_file, 'r+') as a:
                new_json = json.load(a)
                new_json['engineer'] = data[0]['firstName']
                a.seek(0)
                a.truncate()
                a.write(
                    json.dumps(new_json,
                               sort_keys=True,
                               indent=4,
                               separators=(',', ': ')))
        else:
            with open(json_file, 'r') as f:
                json_data = json.load(f)

            return json_data

    def search_by_name(self, name, file):
        for elem in file.findall('Setting'):
            if elem.get('name') == name:
                return elem

    def email_setting_handler(self, request):
        w_settings = self.navigator.get_warrior_dir(
        ) + 'Tools' + os.sep + 'w_settings.xml'
        elem_file = xml_controler.parse(w_settings)
        elem_file = elem_file.getroot()
        elem = self.search_by_name('mail_to', elem_file)
        email_string = xml_controler.tostring(elem)
        email_xml_obj = elem

        if request.method == 'POST':
            elem_file.remove(email_xml_obj)
            val = xmltodict.unparse(
                {'Setting': json.loads(request.POST.get('data'))}, pretty=True)
            elem_file.append(xml_controler.fromstring(val))
            with open(w_settings, 'w') as f:
                f.write(xml_controler.tostring(elem_file))
        else:
            xmldoc = xmltodict.parse(email_string)
            return xmldoc

    def jira_setting_handler(self, request):
        jira_config = self.navigator.get_warrior_dir(
        ) + 'Tools' + os.sep + 'jira' + os.sep + 'jira_config.xml'
        elem_file = xml_controler.parse(jira_config)
        elem_file = elem_file.getroot()
        xml_string = xml_controler.tostring(elem_file)
        if request.method == 'POST':
            val = xmltodict.unparse(
                {'jira': {
                    'system': json.loads(request.POST.get('data'))
                }},
                pretty=True)
            with open(jira_config, 'w') as f:
                f.write(val)
        else:
            xmldoc = xmltodict.parse(xml_string)
            if xmldoc is not None and xmldoc['jira'] is not None:
                if not isinstance(xmldoc['jira']['system'], list):
                    xmldoc['jira']['system'] = [xmldoc['jira']['system']]
                for system in xmldoc['jira']['system']:
                    for k, v in list(system.items()):
                        if k == 'issue_type':
                            v = json.dumps(v)
                            system[k] = v
            return xmldoc

    def secret_handler(self, request):
        keyDoc = self.navigator.get_warrior_dir(
        ) + os.sep + 'Tools' + os.sep + 'admin' + os.sep + 'secret.key'
        if request.method == 'POST':
            val = request.POST.get("data[0][value]")
            elem_file = open(keyDoc, 'w')
            elem_file.write(val)
            elem_file.close()
        else:
            elem_file = open(keyDoc, 'r')
            key_data = elem_file.read()
            elem_file.close()
            return key_data

    def prerequisites_handler(self, request):
        ref_file = join_path(self.static_dir, "base_templates", "empty.xml")
        prereqs = read_xml_get_json(ref_file)["data"]["warhorn"]["dependency"]
        prereq_data = []
        for prereq in prereqs:
            temp = {}
            for key, value in list(prereq.items()):
                temp[key.strip('@')] = value

            temp["status"] = "install"
            try:
                module_name = __import__(temp["name"])
                some_var = module_name.__version__
            except ImportError:
                temp["available_version"] = "--"
                temp["installBtnText"] = "Install"
            except Exception as e:
                print(
                    "-- An Exception Occurred -- while getting details about {0}: {1}"
                    .format(temp["name"], e))
                temp["available_version"] = "--"
                temp["installBtnText"] = "Install"
            else:
                temp["available_version"] = some_var
                if LooseVersion(str(temp["version"])) <= LooseVersion(
                        str(temp["available_version"])):
                    temp["installBtnText"] = "Installed"
                    temp["status"] = "installed"
                else:
                    temp["installBtnText"] = "Upgrade"
                    temp["status"] = "upgrade"

            prereq_data.append(copy.deepcopy(temp))
        return prereq_data

    def prereq_installation_handler(self, request):
        name = request.POST.get('name')
        admin = request.POST.get('admin')
        version = request.POST.get('version')
        status = False
        return_code = -9
        command = ["pip", "install", "{0}=={1}".format(name, version)]
        if admin == "true":
            if not hasattr(sys, 'real_prefix'):
                command.insert(0, "sudo")
        else:
            command.append("--user")
        p = subprocess.Popen(command,
                             stdout=subprocess.PIPE,
                             stderr=subprocess.PIPE)
        kill = lambda process: process.kill()
        my_timer = Timer(10, kill, [p])
        try:
            my_timer.start()
            out, err = p.communicate()
            return_code = p.returncode
            if return_code == 0:
                status = True
        finally:
            if return_code == -9:
                err = "Command could not be completed."
                out = "Command could not be completed in 30 seconds - may be the user is not authorized to install {0}".format(
                    name)
            my_timer.cancel()
        return {
            "status": status,
            "return_code": return_code,
            "errors": err,
            "output": out
        }
 def __init__(self):
     self.navigator = Navigator()
# -*- coding: utf-8 -*-

import json, xmltodict, os, copy
from utils.navigator_util import Navigator
from utils.json_utils import read_json_data
from collections import OrderedDict
from django.template.defaulttags import register

from django.shortcuts import render
from django.http import JsonResponse

JSON_CONFIG = Navigator().get_katana_dir() + os.sep + "config.json"


# Create your views here.
def process_xml(data):
    # The first and only key in xml file should be the only root tag
    root = list(data.keys())[0]

    if not isinstance(data[root]["system"], list):
        # The whole xml only has one system
        data[root]["system"] = [data[root]["system"]]
    for sys in data[root]["system"]:
        if "subsystem" in sys:
            if isinstance(sys["subsystem"], list):
                # Multiple subsystems
                for subsys in sys["subsystem"]:
                    for k, v in list(subsys.items()):
                        subsys[k] = "" if subsys[k] is None else subsys[k]
                        if k.startswith(
                                "@") and k != "@name" and k != "@default":
Exemple #28
0
def get_data_directory(request):
    nav_obj = Navigator()
    directory = os.path.join(nav_obj.get_katana_dir(), "wapps", "assembler",
                             ".data")
    return JsonResponse({"data_directory": directory})
Exemple #29
0
import shutil
import zipfile
from django.http import JsonResponse
from django.shortcuts import render
from django.views import View
import xml.etree.cElementTree as ET
from native.wapp_management.wapp_management_utils.app_validator import AppValidator
from native.wapp_management.wapp_management_utils.installer import Installer
from native.wapp_management.wapp_management_utils.uninstaller import Uninstaller
from utils.directory_traversal_utils import join_path, get_sub_files, get_parent_directory, \
    create_dir, get_dir_from_path
from utils.file_utils import copy_dir
from utils.navigator_util import Navigator
from utils.string_utils import get_repository_name
from wui.core.core_utils.app_info_class import AppInformation
nav_obj = Navigator()


class WappManagementView(View):

    template = 'wapp_management/wapp_management.html'
    dot_data_directory = join_path(nav_obj.get_katana_dir(), "native",
                                   "wapp_management", ".data")

    def get(self, request):
        """
        Get Request Method
        """
        files = get_sub_files(WappManagementView.dot_data_directory)
        preferences = []
        for subfile in files:
Exemple #30
0
class VerifySuiteFile:

    def __init__(self, template, file_path):
        self.navigator = Navigator()
        self.template = template
        self.file_path = file_path
        self.template_data = read_xml_get_json(template, ordered_dict=True)
        self.data = read_xml_get_json(file_path, ordered_dict=True)
        self.output = {"status": True, "message": ""}
        self.root = "TestSuite"

    def verify_file(self):
        """ This function verifies the suite file """
        self.__verify_root()
        if self.output["status"]:
            self.__verify_details()
            self.__verify_requirements()
            self.__verify_cases()
        return self.output, self.data

    def __verify_root(self):
        """ Verifies the root of the suite file """
        for key in self.data:
            if key != self.root:
                self.output["status"] = False
                self.output["message"] = "{0} is not is the correct format."
                print("-- An Error Occurred -- {0}".format(self.output["message"]))
            break

    def __verify_details(self):
        """ Verifies details section of the suite """
        top_key = "Details"
        if top_key not in self.data[self.root] or self.data[self.root][top_key] is None:
            self.data[self.root][top_key] = {}
        for key, value in self.template_data[self.root][top_key].items():
            key, value = self.__verified_details_key_value(key, value)
            self.data[self.root][top_key][key] = self.__verify_values(key, value, self.data[self.root][top_key])

    def __verify_requirements(self):
        """ Verifies the requirements section of the suite file """
        top_key = "Requirements"
        if top_key not in self.data[self.root] or self.data[self.root][top_key] is None:
            self.data[self.root][top_key] = {"Requirement": []}
        elif "Requirement" not in self.data[self.root][top_key] or self.data[self.root][top_key]["Requirement"] is None:
            self.data[self.root][top_key]["Requirement"] = []
        elif not isinstance(self.data[self.root][top_key]["Requirement"], list):
            self.data[self.root][top_key]["Requirement"] = [self.data[self.root][top_key]["Requirement"]]

    def __verify_cases(self):
        """ Verifies the cases section of the suite file """
        top_key = "Testcases"
        if top_key not in self.data[self.root] or self.data[self.root][top_key] is None:
            self.data[self.root][top_key] = {"Testcase": []}
        elif "Testcase" not in self.data[self.root][top_key] or self.data[self.root][top_key]["Testcase"] is None:
            self.data[self.root][top_key]["Testcase"] = []
        elif not isinstance(self.data[self.root][top_key]["Testcase"], list):
            self.data[self.root][top_key]["Testcase"] = [self.data[self.root][top_key]["Testcase"]]

    @staticmethod
    def __verified_steps_key_value(key, value, verify_data):
        """ Verifies specific keys in each step """
        if value is None:
            value = ""

        if key == "Execute":
            if key not in verify_data or verify_data[key] is None:
                verify_data[key] = {}
            if "Rule" not in verify_data[key] or verify_data[key]["Rule"] is None:
                verify_data[key]["Rule"] = [{}]
            elif not isinstance(verify_data[key]["Rule"], list):
                verify_data[key]["Rule"] = [verify_data[key]["Rule"]]

        return key, value, verify_data

    def __verified_details_key_value(self, key, value):
        """ Verifies specific keys in details """
        if value is None:
            value = ""
        if value == "":
            if key == "Engineer":
                value = self.navigator.get_engineer_name()
            if key == "Date":
                now = datetime.now()
                value = "{0}-{1}-{2}".format(now.year, now.month, now.day)
            if key == "Time":
                now = datetime.now()
                value = "{0}:{1}".format(now.hour, now.minute)
        return key, value

    def __verify_values(self, tmpl_key, tmpl_value, parent):
        """ Verifies key value in each step with the case template file """
        output = ""
        if tmpl_key not in parent:
            output = tmpl_value
        elif parent[tmpl_key] is None:
            output = tmpl_value
        else:
            if isinstance(parent[tmpl_key], list):
                for i in range(0, len(parent[tmpl_key])):
                    for k, v in tmpl_value.items():
                        parent[tmpl_key][i][k] = self.__verify_values(k, v, parent[tmpl_key][i])
                    output = parent[tmpl_key]
            elif isinstance(tmpl_value, OrderedDict):
                for k, v in list(tmpl_value.items()):
                    parent[tmpl_key][k] = self.__verify_values(k, v, parent[tmpl_key])
                output = parent[tmpl_key]
            else:
                output = parent[tmpl_key] if parent[tmpl_key].strip() != "" else tmpl_value
        return output