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 at_least_these_environments_exist(step):
    model = EnvironmentModel()
    env_list = model.get_all_list()

    # walk through all the expected roles and make sure it has them all
    # note, it doesn't check that ONLY these roles exist.  That should be a different
    # method.
    for env in step.hashes:
        env_name = env["name"]
        envtype_id = EnvironmenttypeModel().get_resid(env["type"])[0]
        found_env = [x for x in env_list if ((x[ns("name")] == env_name) and (x[ns("environmentTypeId")] == envtype_id))]

        assert (len(found_env) == 1), \
            "Expected to find environment with name %s and environmentTypeId of %s in:\n%s" % \
            (env_name, envtype_id, jstr(env_list))
def create_environment_with_name(step, stored, name, type_name):
    '''
        This creates an environmenttype that applies to an environment object
    '''
    model = EnvironmentModel()
    name = model.get_stored_or_store_name(stored, name)

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

    params = {
              "name": name,
              "companyId": CompanyModel().get_seed_resid()[0],
              "environmentTypeId": type_resid
              }

    model.create(params)
def delete_environment_with_name(step, stored, name):
    envModel = EnvironmentModel()
    name = envModel.get_stored_or_store_name(stored, name)
    envModel.delete(name)
def check_environement_foo_existence(step, stored, name, existence):
    model = EnvironmentModel()
    name = model.get_stored_or_store_name(stored, name)
    model.verify_existence_on_root(name, existence = existence)