def datastore_create(context, data_dict): '''Adds a new table to the datastore. The datastore_create action allows a user to post JSON data to be stored against a resource. This endpoint also supports altering tables, aliases and indexes and bulk insertion. See :ref:`fields` and :ref:`records` for details on how to lay out records. :param resource_id: resource id that the data is going to be stored against. :type resource_id: string :param aliases: names for read only aliases of the resource. :type aliases: list or comma separated string :param fields: fields/columns and their extra metadata. :type fields: list of dictionaries :param records: the data, eg: [{"dob": "2005", "some_stuff": ["a", "b"]}] :type records: list of dictionaries :param primary_key: fields that represent a unique key :type primary_key: list or comma separated string :param indexes: indexes on table :type indexes: list or comma separated string :returns: the newly created data object. :rtype: dictionary ''' # model = _get_or_bust(context, 'model') # id = _get_or_bust(data_dict, 'resource_id') # if not model.Resource.get(id): # raise p.toolkit.ObjectNotFound(p.toolkit._( # 'Resource "{0}" was not found.'.format(id) # )) # p.toolkit.check_access('datastore_create', context, data_dict) # data_dict['connection_url'] = pylons.config['ckan.datastore.write_url'] # validate aliases aliases = db._get_list(data_dict.get('aliases', [])) for alias in aliases: if not db._is_valid_table_name(alias): raise ValidationError({ 'alias': ['{0} is not a valid alias name'.format(alias)] }) result = db.create(context, data_dict) if 'id' in result: result.pop('id') result.pop('connection_url') return result
def test_list(self): assert db._get_list(None) is None assert db._get_list([]) == [] assert db._get_list('') == [] assert db._get_list('foo') == ['foo'] assert db._get_list('foo, bar') == ['foo', 'bar'] assert db._get_list('foo_"bar, baz') == ['foo_"bar', 'baz'] assert db._get_list('"foo", "bar"') == ['foo', 'bar'] assert db._get_list(u'foo, bar') == ['foo', 'bar'] assert db._get_list(['foo', 'bar']) == ['foo', 'bar'] assert db._get_list([u'foo', u'bar']) == ['foo', 'bar'] assert db._get_list(['foo', ['bar', 'baz']]) == ['foo', ['bar', 'baz']]