def setUp(self): super(TestLoad, self).setUp() data_manager._index = None model = meta_fixture('cra') self.ds = Dataset(model) db.session.add(self.ds) db.session.commit() self.cra_url = csvimport_fixture_path('../data', 'cra.csv')
def import_fixture(name): meta_fp = csvimport_fixture_file(name, 'meta.json') model_fp = csvimport_fixture_file(name, 'model.json') meta = json.load(meta_fp) if model_fp: meta['model'] = json.load(model_fp) dataset = Dataset(meta) db.session.add(dataset) data_path = csvimport_fixture_path(name, 'data.csv') db.session.commit() return dataset, data_path
def create(): require.dataset.create() dataset = request_data() data = validate_dataset(dataset) if Dataset.by_name(data['name']) is not None: raise Invalid(SchemaNode(String(), name='name'), _("A dataset with this identifer already exists!")) dataset = Dataset({'dataset': data, 'model': {}}) dataset.managers.append(current_user) db.session.add(dataset) db.session.commit() return view(dataset.name)
def get_or_create_dataset(model): """ Based on a provided model we get the model (if it doesn't exist we create it). """ dataset = Dataset.by_name(model['dataset']['name']) # If the dataset wasn't found we create it if dataset is None: dataset = Dataset(model) db.session.add(dataset) db.session.commit() log.info("Dataset: %s", dataset.name) return dataset