Пример #1
0
    def post(self, exec_key):
        """
        Setup a test model in the registry.
        """
        model_name = None
        if 'model_name' in api.payload:
            model_name = api.payload['model_name']

        if model_name is None:
            # exec_key is supposed to match the model id if model_name is
            # not given
            model = get_model_by_id(exec_key, indra_dir)
            if model is None:
                raise (wz.NotFound(f"Model {exec_key} doesn't exist."))
            # check if a test model already exists against the given exec_
            # key which matches the model id
            model = get_model(exec_key)
            if model is not None:
                return {"msg": f'A test model {model.name} already exists'}
            else:
                return model.to_json()
        else:
            model_rec = get_model_by_name(model_name, indra_dir)
            if model_rec is None:
                raise wz.NotFound(f'Model with name {model_name} is not found')
            model = create_model_for_test(model_rec, exec_key)
            return json_converter(model)
Пример #2
0
def create_model(model_id, props, indra_dir):
    """
    We get some props and create a model in response.
    """
    model_rec = get_model_by_id(model_id, indra_dir=indra_dir)
    if model_rec is not None:
        return module_from_model(model_rec).create_model(props=props)
    else:
        return err_return("Model not found: " + str(model_id))
Пример #3
0
def get_props(model_id, indra_dir):
    try:
        model = get_model_by_id(model_id, indra_dir=indra_dir)
        if model is None:
            return err_return(f"Model id {model_id} not found.")
        prop_file = get_prop_path(model["module"], model["package"])
        print("prop_file = ", prop_file)
        with open(prop_file) as file:
            props = json.loads(file.read())
        return props
    except (IndexError, KeyError, ValueError):
        return err_return("Invalid model id " + str(model_id))
    except FileNotFoundError:  # noqa: F821
        return err_return("Models or props file not found")
Пример #4
0
 def test_get_model_by_id(self):
     model = mdb.get_model_by_id(BASIC_ID, indra_dir)
     self.assertTrue(model[mdb.MODEL_ID] == BASIC_ID)