def setup_class(cls): wsgiapp = middleware.make_app(config['global_conf'], **config) cls.app = paste.fixture.TestApp(wsgiapp) if not tests.is_datastore_supported(): raise nose.SkipTest("Datastore not supported") p.load('datastore') ctd.CreateTestData.create() cls.sysadmin_user = model.User.get('testsysadmin') cls.normal_user = model.User.get('annafan') resource = model.Package.get('annakarenina').resources[0] cls.data = { 'resource_id': resource.id, 'force': True, 'aliases': 'books', 'fields': [{ 'id': u'b\xfck', 'type': 'text' }, { 'id': 'author', 'type': 'text' }, { 'id': 'published' }, { 'id': u'characters', u'type': u'_text' }, { 'id': 'random_letters', 'type': 'text[]' }], 'records': [{ u'b\xfck': 'annakarenina', 'author': 'tolstoy', 'published': '2005-03-01', 'nested': ['b', { 'moo': 'moo' }], u'characters': [u'Princess Anna', u'Sergius'], 'random_letters': ['a', 'e', 'x'] }, { u'b\xfck': 'warandpeace', 'author': 'tolstoy', 'nested': { 'a': 'b' }, 'random_letters': [] }] } postparams = '%s=1' % json.dumps(cls.data) auth = {'Authorization': str(cls.sysadmin_user.apikey)} res = cls.app.post('/api/action/datastore_create', params=postparams, extra_environ=auth) res_dict = json.loads(res.body) assert res_dict['success'] is True engine = db.get_write_engine() cls.Session = orm.scoped_session(orm.sessionmaker(bind=engine))
def setup_class(cls): if not tests.is_datastore_supported(): raise nose.SkipTest("Datastore not supported") p.load('timeseries') helpers.reset_db() # Creating 3 resources with 3 retention policies: # to remove 10, 20 and 90% of data when the # resource gets to its size limit cls.retention = [10, 90, 20, 50] cls.resource_ids = [] package = factories.Dataset() for i, ret in enumerate(cls.retention): data = { 'resource': { 'retention': cls.retention[i], 'package_id': package['id'] }, } result = helpers.call_action('datastore_ts_create', **data) cls.resource_ids.append(result['resource_id']) engine = db._get_engine( {'connection_url': pylons.config['ckan.datastore.write_url']}) cls.Session = orm.scoped_session(orm.sessionmaker(bind=engine))
def setup_class(cls): if not tests.is_datastore_supported(): raise nose.SkipTest("Datastore not supported") p.load('timeseries') ctd.CreateTestData.create() cls.sysadmin_user = model.User.get('testsysadmin') cls.normal_user = model.User.get('annafan') cls.dataset = model.Package.get('annakarenina') cls.resource = cls.dataset.resources[0] cls.data = { 'resource_id': cls.resource.id, 'force': True, } postparams = '%s=1' % json.dumps(cls.data) auth = {'Authorization': str(cls.sysadmin_user.apikey)} res = cls.app.post('/api/action/datastore_ts_create', params=postparams, extra_environ=auth) res_dict = json.loads(res.body) assert res_dict['success'] is True engine = db._get_engine( {'connection_url': pylons.config['ckan.datastore.write_url']}) cls.Session = orm.scoped_session(orm.sessionmaker(bind=engine))
def setup_class(cls): if not tests.is_datastore_supported(): raise nose.SkipTest("Datastore not supported") plugin = p.load('datastore') if plugin.legacy_mode: # make sure we undo adding the plugin p.unload('datastore') raise nose.SkipTest("SQL tests are not supported in legacy mode") ctd.CreateTestData.create() cls.sysadmin_user = model.User.get('testsysadmin') cls.normal_user = model.User.get('annafan') cls.dataset = model.Package.get('annakarenina') resource = cls.dataset.resources[0] cls.data = { 'resource_id': resource.id, 'force': True, 'aliases': 'books4', 'fields': [{'id': u'b\xfck', 'type': 'text'}, {'id': 'author', 'type': 'text'}, {'id': 'published'}], 'records': [{u'b\xfck': 'annakarenina', 'author': 'tolstoy', 'published': '2005-03-01', 'nested': ['b', {'moo': 'moo'}]}, {u'b\xfck': 'warandpeace', 'author': 'tolstoy', 'nested': {'a': 'b'}}] } postparams = '%s=1' % json.dumps(cls.data) auth = {'Authorization': str(cls.sysadmin_user.apikey)} res = cls.app.post('/api/action/datastore_create', params=postparams, extra_environ=auth) res_dict = json.loads(res.body) assert res_dict['success'] is True # Make an organization, because private datasets must belong to one. cls.organization = tests.call_action_api( cls.app, 'organization_create', name='test_org', apikey=cls.sysadmin_user.apikey) cls.expected_records = [{u'_full_text': [u"'annakarenina'", u"'b'", u"'moo'", u"'tolstoy'", u"'2005'"], u'_id': 1, u'author': u'tolstoy', u'b\xfck': u'annakarenina', u'nested': [u'b', {u'moo': u'moo'}], u'published': u'2005-03-01T00:00:00'}, {u'_full_text': [u"'tolstoy'", u"'warandpeac'", u"'b'"], u'_id': 2, u'author': u'tolstoy', u'b\xfck': u'warandpeace', u'nested': {u'a': u'b'}, u'published': None}] cls.expected_join_results = [{u'first': 1, u'second': 1}, {u'first': 1, u'second': 2}] engine = db.get_write_engine() cls.Session = orm.scoped_session(orm.sessionmaker(bind=engine))
def setup_class(cls): if not tests.is_datastore_supported(): raise nose.SkipTest("Datastore not supported") p.load('datastore') ctd.CreateTestData.create() cls.sysadmin_user = model.User.get('testsysadmin') cls.normal_user = model.User.get('annafan') resource = model.Package.get('annakarenina').resources[0] cls.data = { 'resource_id': resource.id, 'aliases': u'b\xfck2', 'fields': [{'id': 'book', 'type': 'text'}, {'id': 'author', 'type': 'text'}, {'id': 'rating with %', 'type': 'text'}], 'records': [{'book': 'annakarenina', 'author': 'tolstoy', 'rating with %': '90%'}, {'book': 'warandpeace', 'author': 'tolstoy', 'rating with %': '42%'}] } engine = db._get_engine( {'connection_url': pylons.config['ckan.datastore.write_url']}) cls.Session = orm.scoped_session(orm.sessionmaker(bind=engine)) set_url_type( model.Package.get('annakarenina').resources, cls.sysadmin_user)
def setup_class(cls): if not tests.is_datastore_supported(): raise nose.SkipTest("Datastore not supported") p.load('datastore') ctd.CreateTestData.create() cls.sysadmin_user = model.User.get('testsysadmin') cls.normal_user = model.User.get('annafan') set_url_type( model.Package.get('annakarenina').resources, cls.sysadmin_user) resource = model.Package.get('annakarenina').resources[0] cls.data = { 'resource_id': resource.id, 'fields': [{'id': u'b\xfck', 'type': 'text'}, {'id': 'author', 'type': 'text'}, {'id': 'nested', 'type': 'json'}, {'id': 'characters', 'type': 'text[]'}, {'id': 'published'}], 'primary_key': u'b\xfck', 'records': [{u'b\xfck': 'annakarenina', 'author': 'tolstoy', 'published': '2005-03-01', 'nested': ['b', {'moo': 'moo'}]}, {u'b\xfck': 'warandpeace', 'author': 'tolstoy', 'nested': {'a':'b'}} ] } postparams = '%s=1' % json.dumps(cls.data) auth = {'Authorization': str(cls.sysadmin_user.apikey)} res = cls.app.post('/api/action/datastore_create', params=postparams, extra_environ=auth) res_dict = json.loads(res.body) assert res_dict['success'] is True engine = db._get_engine( {'connection_url': config['ckan.datastore.write_url']}) cls.Session = orm.scoped_session(orm.sessionmaker(bind=engine))
def setup_class(cls): if not tests.is_datastore_supported(): raise nose.SkipTest("Datastore not supported") p.load('timeseries') helpers.reset_db() # Creating 3 resources with 3 retention policies: # to remove 10, 20 and 90% of data when the # resource gets to its size limit cls.retention = [10, 90, 20, 50] cls.resource_ids = [] package = factories.Dataset() for i, ret in enumerate(cls.retention): data = { 'resource': { 'retention': cls.retention[i], 'package_id': package['id'] }, } result = helpers.call_action('datastore_ts_create', **data) cls.resource_ids.append(result['resource_id']) engine = db._get_engine( {'connection_url': pylons.config['ckan.datastore.write_url']} ) cls.Session = orm.scoped_session(orm.sessionmaker(bind=engine))
def test_pg_version_check(self): if not tests.is_datastore_supported(): raise nose.SkipTest("Datastore not supported") engine = db._get_engine_from_url(config['sqlalchemy.url']) connection = engine.connect() assert db._pg_version_is_at_least(connection, '8.0') assert not db._pg_version_is_at_least(connection, '20.0')
def setup_class(cls): if not tests.is_datastore_supported(): raise nose.SkipTest("Datastore not supported") cls.app = helpers._get_test_app() p.load('datastore') ctd.CreateTestData.create() cls.sysadmin_user = model.User.get('testsysadmin') cls.normal_user = model.User.get('annafan') set_url_type( model.Package.get('annakarenina').resources, cls.sysadmin_user) resource = model.Package.get('annakarenina').resources[0] cls.data = { 'resource_id': resource.id, 'fields': [{'id': u'b\xfck', 'type': 'text'}, {'id': 'author', 'type': 'text'}, {'id': 'nested', 'type': 'json'}, {'id': 'characters', 'type': 'text[]'}, {'id': 'published'}], 'primary_key': u'b\xfck', 'records': [{u'b\xfck': 'annakarenina', 'author': 'tolstoy', 'published': '2005-03-01', 'nested': ['b', {'moo': 'moo'}]}, {u'b\xfck': 'warandpeace', 'author': 'tolstoy', 'nested': {'a':'b'}} ] } postparams = '%s=1' % json.dumps(cls.data) auth = {'Authorization': str(cls.sysadmin_user.apikey)} res = cls.app.post('/api/action/datastore_create', params=postparams, extra_environ=auth) res_dict = json.loads(res.body) assert res_dict['success'] is True engine = db.get_write_engine() cls.Session = orm.scoped_session(orm.sessionmaker(bind=engine))
def test_pg_version_check(): if not tests.is_datastore_supported(): pytest.skip("Datastore not supported") engine = db._get_engine_from_url(config["sqlalchemy.url"]) connection = engine.connect() assert db._pg_version_is_at_least(connection, "8.0") assert not db._pg_version_is_at_least(connection, "20.0")
def setup_class(cls): if not tests.is_datastore_supported(): raise nose.SkipTest("Datastore not supported") cls.app = helpers._get_test_app() p.load('datastore') ctd.CreateTestData.create() cls.sysadmin_user = model.User.get('testsysadmin') cls.normal_user = model.User.get('annafan') resource = model.Package.get('annakarenina').resources[0] cls.data = { 'resource_id': resource.id, 'aliases': u'b\xfck2', 'fields': [{'id': 'book', 'type': 'text'}, {'id': 'author', 'type': 'text'}, {'id': 'rating with %', 'type': 'text'}], 'records': [{'book': 'annakarenina', 'author': 'tolstoy', 'rating with %': '90%'}, {'book': 'warandpeace', 'author': 'tolstoy', 'rating with %': '42%'}] } engine = db.get_write_engine() cls.Session = orm.scoped_session(orm.sessionmaker(bind=engine)) set_url_type( model.Package.get('annakarenina').resources, cls.sysadmin_user)
def setup_class(cls): if not is_datastore_supported(): raise nose.SkipTest("Datastore not supported") plugin = p.load('datastore') if plugin.legacy_mode: # make sure we undo adding the plugin p.unload('datastore') raise nose.SkipTest("Info is not supported in legacy mode")
def setup_class(cls): if not is_datastore_supported(): raise nose.SkipTest("Datastore not supported") plugin = p.load('timeseries') if plugin.legacy_mode: # make sure we undo adding the plugin p.unload('timeseries') raise nose.SkipTest("Info is not supported in legacy mode")
def setup_class(cls): if not tests.is_datastore_supported(): raise nose.SkipTest("Datastore not supported") p.load('datastore') ctd.CreateTestData.create() cls.sysadmin_user = model.User.get('testsysadmin') cls.normal_user = model.User.get('annafan') cls.dataset = model.Package.get('annakarenina') cls.resource = cls.dataset.resources[0] cls.data = { 'resource_id': cls.resource.id, 'force': True, 'aliases': 'books3', 'fields': [{'id': u'b\xfck', 'type': 'text'}, {'id': 'author', 'type': 'text'}, {'id': 'published'}, {'id': u'characters', u'type': u'_text'}, {'id': 'rating with %'}], 'records': [{u'b\xfck': 'annakarenina', 'author': 'tolstoy', 'published': '2005-03-01', 'nested': ['b', {'moo': 'moo'}], u'characters': [u'Princess Anna', u'Sergius'], 'rating with %': '60%'}, {u'b\xfck': 'warandpeace', 'author': 'tolstoy', 'nested': {'a': 'b'}, 'rating with %': '99%'} ] } postparams = '%s=1' % json.dumps(cls.data) auth = {'Authorization': str(cls.sysadmin_user.apikey)} res = cls.app.post('/api/action/datastore_create', params=postparams, extra_environ=auth) res_dict = json.loads(res.body) assert res_dict['success'] is True # Make an organization, because private datasets must belong to one. cls.organization = tests.call_action_api( cls.app, 'organization_create', name='test_org', apikey=cls.sysadmin_user.apikey) cls.expected_records = [{u'published': u'2005-03-01T00:00:00', u'_id': 1, u'nested': [u'b', {u'moo': u'moo'}], u'b\xfck': u'annakarenina', u'author': u'tolstoy', u'characters': [u'Princess Anna', u'Sergius'], u'rating with %': u'60%'}, {u'published': None, u'_id': 2, u'nested': {u'a': u'b'}, u'b\xfck': u'warandpeace', u'author': u'tolstoy', u'characters': None, u'rating with %': u'99%'}] engine = db._get_engine( {'connection_url': pylons.config['ckan.datastore.write_url']} ) cls.Session = orm.scoped_session(orm.sessionmaker(bind=engine))
def initial_data(self, clean_db, clean_index): if not tests.is_datastore_supported(): pytest.skip("Datastore not supported") ctd.CreateTestData.create() self.sysadmin_user = model.User.get("testsysadmin") self.normal_user = model.User.get("annafan") engine = db.get_write_engine() self.Session = orm.scoped_session(orm.sessionmaker(bind=engine)) set_url_type( model.Package.get("annakarenina").resources, self.sysadmin_user)
def setup_class(self, clean_db): if not tests.is_datastore_supported(): pytest.skip("Datastore not supported") resource = factories.Resource(url_type="datastore") self.dataset = factories.Dataset(resources=[resource]) self.sysadmin_user = factories.User(name="testsysadmin", sysadmin=True) self.normal_user = factories.User(name="annafan") engine = db.get_write_engine() self.Session = orm.scoped_session(orm.sessionmaker(bind=engine))
def setup_class(cls): if not is_datastore_supported(): raise nose.SkipTest('Datastore not supported') if not p.plugin_loaded('datastore'): p.load('datastore') if not p.plugin_loaded('datapusher'): p.load('datapusher') if not p.plugin_loaded('recline_grid_view'): p.load('recline_grid_view') helpers.reset_db()
def setup_class(cls): cls.app = helpers._get_test_app() if not tests.is_datastore_supported(): raise nose.SkipTest("Datastore not supported") p.load('datastore') p.load('datapusher') ctd.CreateTestData.create() cls.sysadmin_user = model.User.get('testsysadmin') cls.normal_user = model.User.get('annafan') engine = db.get_write_engine() cls.Session = orm.scoped_session(orm.sessionmaker(bind=engine)) set_url_type( model.Package.get('annakarenina').resources, cls.sysadmin_user)
def setup_class(cls): wsgiapp = middleware.make_app(config['global_conf'], **config) cls.app = paste.fixture.TestApp(wsgiapp) if not tests.is_datastore_supported(): raise nose.SkipTest("Datastore not supported") p.load('datastore') p.load('datapusher') ctd.CreateTestData.create() cls.sysadmin_user = model.User.get('testsysadmin') cls.normal_user = model.User.get('annafan') engine = db.get_write_engine() cls.Session = orm.scoped_session(orm.sessionmaker(bind=engine)) set_url_type( model.Package.get('annakarenina').resources, cls.sysadmin_user)
def setup_class(cls): cls.app = _get_test_app() if not tests.is_datastore_supported(): raise nose.SkipTest("Datastore not supported") p.load('datastore') p.load('datapusher') p.load('test_datapusher_plugin') resource = factories.Resource(url_type='datastore') cls.dataset = factories.Dataset(resources=[resource]) cls.sysadmin_user = factories.User(name='testsysadmin', sysadmin=True) cls.normal_user = factories.User(name='annafan') engine = db.get_write_engine() cls.Session = orm.scoped_session(orm.sessionmaker(bind=engine))
def test_resource_data(app): if not tests.is_datastore_supported(): pytest.skip(u"Datastore not supported") user = factories.User() dataset = factories.Dataset(creator_user_id=user["id"]) resource = factories.Resource(package_id=dataset["id"], creator_user_id=user["id"]) auth = {u"Authorization": str(user["apikey"])} app.get( url=u"/dataset/{id}/resource_data/{resource_id}".format( id=str(dataset["name"]), resource_id=str(resource["id"])), extra_environ=auth, )
def setup_class(cls): wsgiapp = middleware.make_app(config['global_conf'], **config) cls.app = paste.fixture.TestApp(wsgiapp) if not tests.is_datastore_supported(): raise nose.SkipTest("Datastore not supported") p.load('datastore') p.load('datapusher') p.load('test_datapusher_plugin') resource = factories.Resource(url_type='datastore') cls.dataset = factories.Dataset(resources=[resource]) cls.sysadmin_user = factories.User(name='testsysadmin', sysadmin=True) cls.normal_user = factories.User(name='annafan') engine = db.get_write_engine() cls.Session = orm.scoped_session(orm.sessionmaker(bind=engine))
def test_resource_data(app, monkeypatch): if not tests.is_datastore_supported(): pytest.skip(u"Datastore not supported") user = factories.User() dataset = factories.Dataset(creator_user_id=user["id"]) resource = factories.Resource(package_id=dataset["id"], creator_user_id=user["id"]) auth = {u"REMOTE_USER": user["name"]} url = u"/dataset/{id}/resource_data/{resource_id}".format( id=str(dataset["name"]), resource_id=str(resource["id"])) func = mock.Mock() monkeypatch.setitem(_actions, 'datapusher_submit', func) app.post(url=url, environ_overrides=auth, status=200) func.assert_called() func.reset_mock() app.get(url=url, environ_overrides=auth, status=200) func.assert_not_called()
def setup_class(cls): wsgiapp = middleware.make_app(config['global_conf'], **config) cls.app = paste.fixture.TestApp(wsgiapp) if not tests.is_datastore_supported(): raise nose.SkipTest("Datastore not supported") p.load('datastore') p.load('datapusher') ctd.CreateTestData.create() cls.sysadmin_user = model.User.get('testsysadmin') cls.normal_user = model.User.get('annafan') engine = db._get_engine( {'connection_url': pylons.config['ckan.datastore.write_url']}) cls.Session = orm.scoped_session(orm.sessionmaker(bind=engine)) set_url_type( model.Package.get('annakarenina').resources, cls.sysadmin_user) # Httpretty crashes with Solr on Python 2.6, # skip the tests if (sys.version_info[0] == 2 and sys.version_info[1] == 6): raise nose.SkipTest()
def setup_class(cls): wsgiapp = middleware.make_app(config["global_conf"], **config) cls.app = paste.fixture.TestApp(wsgiapp) if not tests.is_datastore_supported(): raise nose.SkipTest("Datastore not supported") p.load("datastore") ctd.CreateTestData.create() cls.sysadmin_user = model.User.get("testsysadmin") cls.normal_user = model.User.get("annafan") resource = model.Package.get("annakarenina").resources[0] cls.data = { "resource_id": resource.id, "force": True, "aliases": "books", "fields": [ {"id": u"b\xfck", "type": "text"}, {"id": "author", "type": "text"}, {"id": "published"}, {"id": u"characters", u"type": u"_text"}, ], "records": [ { u"b\xfck": "annakarenina", "author": "tolstoy", "published": "2005-03-01", "nested": ["b", {"moo": "moo"}], u"characters": [u"Princess Anna", u"Sergius"], }, {u"b\xfck": "warandpeace", "author": "tolstoy", "nested": {"a": "b"}}, ], } postparams = "%s=1" % json.dumps(cls.data) auth = {"Authorization": str(cls.sysadmin_user.apikey)} res = cls.app.post("/api/action/datastore_create", params=postparams, extra_environ=auth) res_dict = json.loads(res.body) assert res_dict["success"] is True engine = db._get_engine({"connection_url": config["ckan.datastore.write_url"]}) cls.Session = orm.scoped_session(orm.sessionmaker(bind=engine))
def setup_class(cls): if not tests.is_datastore_supported(): raise nose.SkipTest("Datastore not supported") cls.app = helpers._get_test_app() p.load('datastore') ctd.CreateTestData.create() cls.sysadmin_user = model.User.get('testsysadmin') cls.normal_user = model.User.get('annafan') resource = model.Package.get('annakarenina').resources[0] cls.data = dict( resource_id=resource.id, force=True, fields=[ {'id': 'id'}, {'id': 'date', 'type':'date'}, {'id': 'x'}, {'id': 'y'}, {'id': 'z'}, {'id': 'country'}, {'id': 'title'}, {'id': 'lat'}, {'id': 'lon'} ], records=[ {'id': 0, 'date': '2011-01-01', 'x': 1, 'y': 2, 'z': 3, 'country': 'DE', 'title': 'first 99', 'lat':52.56, 'lon':13.40}, {'id': 1, 'date': '2011-02-02', 'x': 2, 'y': 4, 'z': 24, 'country': 'UK', 'title': 'second', 'lat':54.97, 'lon':-1.60}, {'id': 2, 'date': '2011-03-03', 'x': 3, 'y': 6, 'z': 9, 'country': 'US', 'title': 'third', 'lat':40.00, 'lon':-75.5}, {'id': 3, 'date': '2011-04-04', 'x': 4, 'y': 8, 'z': 6, 'country': 'UK', 'title': 'fourth', 'lat':57.27, 'lon':-6.20}, {'id': 4, 'date': '2011-05-04', 'x': 5, 'y': 10, 'z': 15, 'country': 'UK', 'title': 'fifth', 'lat':51.58, 'lon':0}, {'id': 5, 'date': '2011-06-02', 'x': 6, 'y': 12, 'z': 18, 'country': 'DE', 'title': 'sixth 53.56', 'lat':51.04, 'lon':7.9} ] ) postparams = '%s=1' % json.dumps(cls.data) auth = {'Authorization': str(cls.normal_user.apikey)} res = cls.app.post('/api/action/datastore_create', params=postparams, extra_environ=auth) res_dict = json.loads(res.body) assert res_dict['success'] is True
def setup_class(cls): wsgiapp = middleware.make_app(config['global_conf'], **config) cls.app = paste.fixture.TestApp(wsgiapp) if not tests.is_datastore_supported(): raise nose.SkipTest("Datastore not supported") p.load('timeseries') ctd.CreateTestData.create() cls.sysadmin_user = model.User.get('testsysadmin') cls.normal_user = model.User.get('annafan') resource = model.Package.get('annakarenina').resources[0] cls.data = { 'resource_id': resource.id, 'force': True, 'aliases': 'books', 'fields': [{'id': u'b\xfck', 'type': 'text'}, {'id': 'author', 'type': 'text'}, {'id': 'published'}, {'id': u'characters', u'type': u'_text'}], 'records': [{u'b\xfck': 'annakarenina', 'author': 'tolstoy', 'published': '2005-03-01', 'nested': ['b', {'moo': 'moo'}], u'characters': [u'Princess Anna', u'Sergius']}, {u'b\xfck': 'warandpeace', 'author': 'tolstoy', 'nested': {'a': 'b'}}] } postparams = '%s=1' % json.dumps(cls.data) auth = {'Authorization': str(cls.sysadmin_user.apikey)} res = cls.app.post('/api/action/datastore_ts_create', params=postparams, extra_environ=auth) res_dict = json.loads(res.body) assert res_dict['success'] is True engine = db._get_engine({ 'connection_url': config['ckan.datastore.write_url']}) cls.Session = orm.scoped_session(orm.sessionmaker(bind=engine))
def setup_class(cls): if not is_datastore_supported(): raise nose.SkipTest("Datastore not supported") plugin = p.load('datastore')
def setup_class(cls): cls.app = cls._get_test_app() if not tests.is_datastore_supported(): raise nose.SkipTest(u'Datastore not supported') super(TestController, cls).setup_class()
def setup_class(cls): if not tests.is_datastore_supported(): raise nose.SkipTest("Datastore not supported") p.load('timeseries') helpers.reset_db() ctd.CreateTestData.create() cls.sysadmin_user = model.User.get('testsysadmin') cls.normal_user = model.User.get('annafan') cls.dataset = model.Package.get('annakarenina') cls.resource = cls.dataset.resources[0] cls.data = { 'resource_id': cls.resource.id, 'force': True, 'aliases': 'books3', 'fields': [{'id': 'author', 'type': 'text'}, {'id': 'published'}], 'records': [{'author': 'tolstoy1', 'published': '2005-03-01'}, {'author': 'tolstoy2'} ] } cls.data2 = { 'resource_id': cls.resource.id, 'force': True, 'method': 'insert', 'records': [{'author': 'tolstoy3', 'published': '2005-03-03'}, {'author': 'tolstoy4'} ] } cls.data3 = { 'resource_id': cls.resource.id, 'force': True, 'method': 'insert', 'records': [{'author': 'tolstoy5', 'published': '2005-03-05'}, {'author': 'tolstoy6'}, {'author': 'tolstoy7', 'published': '2005-03-05'} ] } cls.startdata = utcnow() postparams = '%s=1' % json.dumps(cls.data) auth = {'Authorization': str(cls.sysadmin_user.apikey)} res = cls.app.post('/api/action/datastore_ts_create', params=postparams, extra_environ=auth) res_dict = json.loads(res.body) assert res_dict['success'] is True cls.enddata = utcnow() cls.startdata2 = utcnow() time.sleep(2) postparams = '%s=1' % json.dumps(cls.data2) res = cls.app.post('/api/action/datastore_ts_create', params=postparams, extra_environ=auth) res_dict = json.loads(res.body) assert res_dict['success'] is True cls.enddata2 = utcnow() cls.startdata3 = utcnow() time.sleep(2) postparams = '%s=1' % json.dumps(cls.data3) res = cls.app.post('/api/action/datastore_ts_create', params=postparams, extra_environ=auth) res_dict = json.loads(res.body) assert res_dict['success'] is True cls.enddata3 = utcnow() # Make an organization, because private datasets must belong to one. cls.organization = tests.call_action_api( cls.app, 'organization_create', name='test_org', apikey=cls.sysadmin_user.apikey) cls.expected_records = [{u'published': u'2005-03-01T00:00:00', u'_id': 1, u'author': u'tolstoy1'}, {u'published': None, u'_id': 2, u'author': u'tolstoy2'}, {u'published': u'2005-03-03T00:00:00', u'_id': 3, u'author': u'tolstoy3'}, {u'published': None, u'_id': 4, u'author': u'tolstoy4'}, {u'published': u'2005-03-05T00:00:00', u'_id': 5, u'author': u'tolstoy5'}, {u'published': None, u'_id': 6, u'author': u'tolstoy6'}, {u'published': u'2005-03-05T00:00:00', u'_id': 7, u'author': u'tolstoy7'}] cls.expected_records1 = [{u'published': u'2005-03-01T00:00:00', u'_id': 1, u'author': u'tolstoy1'}, {u'published': None, u'_id': 2, u'author': u'tolstoy2'}] cls.expected_records12 = [{u'published': u'2005-03-01T00:00:00', u'_id': 1, u'author': u'tolstoy1'}, {u'published': None, u'_id': 2, u'author': u'tolstoy2'}, {u'published': u'2005-03-03T00:00:00', u'_id': 3, u'author': u'tolstoy3'}, {u'published': None, u'_id': 4, u'author': u'tolstoy4'}] cls.expected_records23 = [{u'published': u'2005-03-03T00:00:00', u'_id': 3, u'author': u'tolstoy3'}, {u'published': None, u'_id': 4, u'author': u'tolstoy4'}, {u'published': u'2005-03-05T00:00:00', u'_id': 5, u'author': u'tolstoy5'}, {u'published': None, u'_id': 6, u'author': u'tolstoy6'}, {u'published': u'2005-03-05T00:00:00', u'_id': 7, u'author': u'tolstoy7'}] cls.expected_records3 = [{u'published': u'2005-03-05T00:00:00', u'_id': 5, u'author': u'tolstoy5'}, {u'published': None, u'_id': 6, u'author': u'tolstoy6'}, {u'published': u'2005-03-05T00:00:00', u'_id': 7, u'author': u'tolstoy7'}] engine = db._get_engine( {'connection_url': pylons.config['ckan.datastore.write_url']} ) cls.Session = orm.scoped_session(orm.sessionmaker(bind=engine))
def setup_class(cls): if not tests.is_datastore_supported(): raise nose.SkipTest("Datastore not supported") p.load('timeseries') helpers.reset_db() ctd.CreateTestData.create() cls.sysadmin_user = model.User.get('testsysadmin') cls.normal_user = model.User.get('annafan') cls.dataset = model.Package.get('annakarenina') cls.resource = cls.dataset.resources[0] cls.data = { 'resource_id': cls.resource.id, 'force': True, 'aliases': 'books3', 'fields': [{ 'id': 'author', 'type': 'text' }, { 'id': 'published' }], 'records': [{ 'author': 'tolstoy1', 'published': '2005-03-01' }, { 'author': 'tolstoy2' }] } cls.data2 = { 'resource_id': cls.resource.id, 'force': True, 'method': 'insert', 'records': [{ 'author': 'tolstoy3', 'published': '2005-03-03' }, { 'author': 'tolstoy4' }] } cls.data3 = { 'resource_id': cls.resource.id, 'force': True, 'method': 'insert', 'records': [{ 'author': 'tolstoy5', 'published': '2005-03-05' }, { 'author': 'tolstoy6' }, { 'author': 'tolstoy7', 'published': '2005-03-05' }] } cls.startdata = utcnow() postparams = '%s=1' % json.dumps(cls.data) auth = {'Authorization': str(cls.sysadmin_user.apikey)} res = cls.app.post('/api/action/datastore_ts_create', params=postparams, extra_environ=auth) res_dict = json.loads(res.body) assert res_dict['success'] is True cls.enddata = utcnow() cls.startdata2 = utcnow() postparams = '%s=1' % json.dumps(cls.data2) res = cls.app.post('/api/action/datastore_ts_create', params=postparams, extra_environ=auth) res_dict = json.loads(res.body) assert res_dict['success'] is True cls.enddata2 = utcnow() cls.startdata3 = utcnow() postparams = '%s=1' % json.dumps(cls.data3) res = cls.app.post('/api/action/datastore_ts_create', params=postparams, extra_environ=auth) res_dict = json.loads(res.body) assert res_dict['success'] is True cls.enddata3 = utcnow() # Make an organization, because private datasets must belong to one. cls.organization = tests.call_action_api( cls.app, 'organization_create', name='test_org', apikey=cls.sysadmin_user.apikey) cls.expected_records = [{ u'published': u'2005-03-01T00:00:00', u'_id': 1, u'author': u'tolstoy1' }, { u'published': None, u'_id': 2, u'author': u'tolstoy2' }, { u'published': u'2005-03-03T00:00:00', u'_id': 3, u'author': u'tolstoy3' }, { u'published': None, u'_id': 4, u'author': u'tolstoy4' }, { u'published': u'2005-03-05T00:00:00', u'_id': 5, u'author': u'tolstoy5' }, { u'published': None, u'_id': 6, u'author': u'tolstoy6' }, { u'published': u'2005-03-05T00:00:00', u'_id': 7, u'author': u'tolstoy7' }] cls.expected_records1 = [{ u'published': u'2005-03-01T00:00:00', u'_id': 1, u'author': u'tolstoy1' }, { u'published': None, u'_id': 2, u'author': u'tolstoy2' }] cls.expected_records12 = [{ u'published': u'2005-03-01T00:00:00', u'_id': 1, u'author': u'tolstoy1' }, { u'published': None, u'_id': 2, u'author': u'tolstoy2' }, { u'published': u'2005-03-03T00:00:00', u'_id': 3, u'author': u'tolstoy3' }, { u'published': None, u'_id': 4, u'author': u'tolstoy4' }] cls.expected_records23 = [{ u'published': u'2005-03-03T00:00:00', u'_id': 3, u'author': u'tolstoy3' }, { u'published': None, u'_id': 4, u'author': u'tolstoy4' }, { u'published': u'2005-03-05T00:00:00', u'_id': 5, u'author': u'tolstoy5' }, { u'published': None, u'_id': 6, u'author': u'tolstoy6' }, { u'published': u'2005-03-05T00:00:00', u'_id': 7, u'author': u'tolstoy7' }] cls.expected_records3 = [{ u'published': u'2005-03-05T00:00:00', u'_id': 5, u'author': u'tolstoy5' }, { u'published': None, u'_id': 6, u'author': u'tolstoy6' }, { u'published': u'2005-03-05T00:00:00', u'_id': 7, u'author': u'tolstoy7' }] engine = db._get_engine( {'connection_url': pylons.config['ckan.datastore.write_url']}) cls.Session = orm.scoped_session(orm.sessionmaker(bind=engine))