def create_environmentgroup_with_name(step, stored, name, type_name):
    model = EnvironmentgroupModel()
    name = model.get_stored_or_store_name(stored, name)

    type_resid = EnvironmenttypeModel().get_resid(type_name)[0]

    post_payload = {
                    "name": name,
                    "description": "oh, this old thing...",
                    "companyId": CompanyModel().get_seed_resid()[0],
                    "environmentTypeId": type_resid
                    }
    model.create(post_payload)
def create_environmentgroups(step):
    model = EnvironmentgroupModel()

    for envgrp in step.hashes:

        type_resid = EnvironmenttypeModel().get_resid(envgrp["environmenttype name"],)[0]

        post_payload = {
                        "name": envgrp["name"],
                        "description": envgrp["description"],
                        "companyId": CompanyModel().get_seed_resid()[0],
                        "environmentTypeId": type_resid
                        }
        model.create(post_payload)
def add_envgroups_to_product(step, stored_product, product_name):
    productModel = ProductModel()
    product_name = productModel.get_stored_or_store_name(stored_product, product_name)

    envgrp_ids = []
    for envgrp in step.hashes:
        envgrp_id = EnvironmentgroupModel().get_resid(envgrp["name"])[0]
        envgrp_ids.append(envgrp_id)

    productModel.add_environmentgroups(product_name, envgrp_ids)
def add_envgroups_to_testcycle(step, stored_testcycle, testcycle_name):
    testcycleModel = TestcycleModel()
    testcycle_name = testcycleModel.get_stored_or_store_name(stored_testcycle, testcycle_name)

    envgrp_ids = []
    for envgrp in step.hashes:
        envgrp_id = EnvironmentgroupModel().get_resid(envgrp["name"])[0]
        envgrp_ids.append(envgrp_id)

    testcycleModel.add_environmentgroups(testcycle_name, envgrp_ids)
def add_environment_to_environmentgroup(step, stored_envgrp, envgrp_name):
    envModel = EnvironmentModel()
    envgrpModel = EnvironmentgroupModel()

    envgrp_name = envgrpModel.get_stored_or_store_name(stored_envgrp, envgrp_name)
    envgrp_id, version = envgrpModel.get_resid(envgrp_name)

    env_ids = []
    for env in step.hashes:
        env_id = envModel.get_resid(env["name"])[0]
        env_ids.append(env_id)

    envgrpModel.add_environments(envgrp_id, version, env_ids)
def check_environementgroup_existence(step, stored, name, existence):
    model = EnvironmentgroupModel()
    name = model.get_stored_or_store_name(stored, name)
    model.verify_existence_on_root(name, existence = existence)
def delete_environmentgroup_with_name(step, stored, name):
    envgrpModel = EnvironmentgroupModel()
    name = envgrpModel.get_stored_or_store_name(stored, name)
    envgrpModel.delete(name)
def add_environmentgroup_to_product(step, envgrp_name, product_name):
    productModel = ProductModel()
    envgrp_id = EnvironmentgroupModel().get_resid(envgrp_name)[0]
    productModel.add_environmentgroups(product_name, envgrp_id)