def init(stack=None, project=None): select_stack = stack while not select_stack: select_stack = get_stack() select_project = project while not select_project: select_project = get_project(select_stack) fields = exec_form(select_stack, select_project) data = list() for field in fields["init"]: f_field = eval(str(field["form"])) validate = False while not validate: f_form = eval(str(field["form"])) form = utils.form_generator("Setup {}".format(field["project"]), f_form) for k, v in form.items(): if isinstance(v.value, list): for role in f_field: if role["key"] == k: form[k] = role["values"][v.value[0]] else: form[k] = v.value if field["parent"]: form["parent"] = field["parent"] else: form["parent"] = None form["stack"] = field["stack"] form["template"] = field["project"] """ Check if data is null """ null_data = 0 for k_data, v_data in form.items(): if v_data == "": null_data += 1 if len(field["number"]) > 0: if k_data in field["number"]: if utils.isint(v_data): form[k_data] = int(v_data) elif utils.isfloat(v_data): form[k_data] = float(v_data) else: null_data += 1 if null_data == 0: validate = True data.append(form) utils.yaml_create("neo.yml", dump(data)) return utils.read_file("neo.yml")
def test_create_env_file(self): home = os.path.expanduser("~") env_file = "{}/.neo.env".format(home) env_file_tmp = "{}/.neo.tmp".format(home) # move already existing file os.rename(env_file, env_file_tmp) login.create_env_file("usertest", "passwd", "1") login.add_token("1abc") outs = utils.read_file(env_file) os.remove(env_file) os.rename(env_file_tmp, env_file) assert 'usertest' in outs
def test_read_file(self): current_dir = path.abspath(path.dirname(__file__)) filename = "test_utils.py" assert "test_read_file(self):" in utils.read_file( f"{current_dir}/{filename}")
def init(stack=None, project=None): select_stack = stack if not select_stack: select_stack = get_stack() select_project = project if not select_project: select_project = get_project(select_stack) fields = exec_form(select_stack, select_project) data = list() for field in fields["init"]: validate = False while not validate: f_form = eval(str(field["form"])) name_type = f_form[0] """ Generate form if just_child_val is False """ if name_type["type"] == "TitleSelect": name_values = name_type["values"] form = utils.prompt_generator( "Setup {}".format(field["project"]), [name_type]) if form["name"] in name_values: form["just_child_val"] = True validate = True else: new_form = eval(str(field["form"])) del new_form[0] new_form_val = utils.prompt_generator( "Setup {}".format(field["project"]), new_form) form.update(new_form_val) form["just_child_val"] = False else: form = utils.prompt_generator( "Setup {}".format(field["project"]), f_form) form["just_child_val"] = False if field["parent"]: form["parent"] = field["parent"] else: form["parent"] = None if not form["just_child_val"]: form["stack"] = field["stack"] form["template"] = field["project"] """ Check if data is null """ null_data = 0 for k_data, v_data in form.items(): if v_data == "": null_data += 1 if len(field["number"]) > 0: if k_data in field["number"]: if utils.isint(v_data): form[k_data] = int(v_data) elif utils.isfloat(v_data): form[k_data] = float(v_data) else: null_data += 1 if null_data == 0: validate = True if validate: data.append(form) if os.name == "nt": os.system("cls") else: os.system("clear") utils.yaml_create("neo.yml", dump(data)) return utils.read_file("neo.yml")
def test_read_file(self): assert utils.read_file("tests/neo.yml")[:7] == 'deploy:'