def setup_class(cls): 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, 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', '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', 'lat':51.04, 'lon':7.9} ] ) 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
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, '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 import pylons engine = db._get_engine( None, {'connection_url': pylons.config['ckan.datastore.write_url']} ) cls.Session = orm.scoped_session(orm.sessionmaker(bind=engine))
def command(self): self._load_config() self._setup_app() # Now we can import from ckan import plugins from ckanext.dgu.testtools.create_test_data import DguCreateTestData try: plugins.load('synchronous_search') # so packages get indexed except: pass self.log = logging.getLogger(__name__) if self.args: cmd = self.args[0] else: cmd = 'basic' if cmd == 'basic': DguCreateTestData.create_dgu_test_data() elif cmd == 'users': DguCreateTestData.create_dgu_test_users() else: print 'Command %s not recognized' % cmd raise NotImplementedError self.log.info('Created DGU test data successfully')
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': 'books2', 'fields': [{'id': 'book', 'type': 'text'}, {'id': 'author', 'type': 'text'}], 'records': [{'book': 'annakarenina', 'author': 'tolstoy'}, {'book': 'warandpeace', 'author': 'tolstoy'}] } #model.repo.rebuild_db() #model.repo.clean_db() import pylons engine = db._get_engine( None, {'connection_url': pylons.config['ckan.datastore.write_url']} ) cls.Session = orm.scoped_session(orm.sessionmaker(bind=engine))
def setup_class(cls): p.load('timeseries') helpers.reset_db() 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)) cls.dataset = model.Package.get('annakarenina') cls.data = { 'resource_id': '', 'force': True, 'method': 'insert', 'records': [{'author': 'tolstoy5', 'published': '2005-03-05'}, {'author': 'tolstoy6'}, {'author': 'tolstoy7', 'published': '2005-03-05'} ] } cls.data['resource_id'] = cls.dataset.resources[0].id result = helpers.call_action('datastore_ts_create', **cls.data) cls.data['resource_id'] = cls.dataset.resources[1].id result = helpers.call_action('datastore_ts_create', **cls.data) datastore_test_helpers.set_url_type( model.Package.get('annakarenina').resources, cls.sysadmin_user)
def setup_class(cls): if not p.plugin_loaded('datastore'): p.load('datastore') if not p.plugin_loaded('datapusher'): p.load('datapusher') helpers.reset_db()
def setup_class(cls): harvest_model.setup() CreateTestData.create() sysadmin_user = ckan.model.User.get('testsysadmin') cls.sysadmin = { 'id': sysadmin_user.id, 'apikey': sysadmin_user.apikey, 'name': sysadmin_user.name, } cls.app = paste.fixture.TestApp(pylons.test.pylonsapp) cls.default_source_dict = { "url": "http://test.action.com", "name": "test-source-action", "title": "Test source action", "notes": "Test source action desc", "source_type": "test-for-action", "frequency": "MANUAL", "config": json.dumps({"custom_option":["a","b"]}) } if not p.plugin_loaded('test_action_harvester'): p.load('test_action_harvester')
def test_auth_plugin_override(self): plugins.load_all(config) package_list_original = new_authz.is_authorized('package_list', {}) plugins.load('auth_plugin') assert new_authz.is_authorized('package_list', {}) != package_list_original plugins.unload('auth_plugin') assert new_authz.is_authorized('package_list', {}) == package_list_original
def test_translation_works_on_flask_and_pylons(self): app = helpers._get_test_app() if not p.plugin_loaded(u'test_routing_plugin'): p.load(u'test_routing_plugin') try: plugin = p.get_plugin(u'test_routing_plugin') app.flask_app.register_extension_blueprint( plugin.get_blueprint()) resp = app.get(u'/flask_translated') eq_(resp.body, u'Dataset') resp = app.get(u'/es/flask_translated') eq_(resp.body, u'Conjunto de datos') resp = app.get(u'/pylons_translated') eq_(resp.body, u'Groups') resp = app.get(u'/es/pylons_translated') eq_(resp.body, u'Grupos') finally: if p.plugin_loaded(u'test_routing_plugin'): p.unload(u'test_routing_plugin')
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, '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 p.plugin_loaded('image_view'): p.load('image_view') if not p.plugin_loaded('recline_view'): p.load('recline_view') helpers.reset_db()
def test_ask_around_pylons_extension_route_post_using_get(self): if not p.plugin_loaded('test_routing_plugin'): p.load('test_routing_plugin') app = self._get_test_app() # We want our CKAN app, not the WebTest one app = app.app environ = { 'PATH_INFO': '/from_pylons_extension_before_map_post_only', 'REQUEST_METHOD': 'GET', } wsgiref.util.setup_testing_defaults(environ) answers = app.ask_around('can_handle_request', environ) # We are going to get an answer from Pylons, but just because it will # match the catch-all template route, hence the `core` origin. eq_(len(answers), 1) eq_(answers[0][0], True) eq_(answers[0][1], 'pylons_app') eq_(answers[0][2], 'core') p.unload('test_routing_plugin')
def test_ask_around_flask_core_and_pylons_extension_route(self): if not p.plugin_loaded('test_routing_plugin'): p.load('test_routing_plugin') app = self._get_test_app() # We want our CKAN app, not the WebTest one app = app.app environ = { 'PATH_INFO': '/pylons_and_flask', 'REQUEST_METHOD': 'GET', } wsgiref.util.setup_testing_defaults(environ) answers = app.ask_around('can_handle_request', environ) answers = sorted(answers, key=lambda a: a[1]) eq_(len(answers), 2) eq_([a[0] for a in answers], [True, True]) eq_([a[1] for a in answers], ['flask_app', 'pylons_app']) # TODO: we still can't distinguish between Flask core and extension # eq_(answers[0][2], 'extension') eq_(answers[1][2], 'extension') p.unload('test_routing_plugin')
def teardown(self): for env_var, _ in self.ENV_VAR_LIST: if os.environ.get(env_var, None): del os.environ[env_var] config.update(self._old_config) # plugin.load() will force the config to update p.load()
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_action_plugin_override(self): plugins.load_all(config) status_show_original = logic.get_action('status_show')(None, {}) plugins.load('action_plugin') assert logic.get_action('status_show')(None, {}) != status_show_original plugins.unload('action_plugin') assert logic.get_action('status_show')(None, {}) == status_show_original
def main(): parser = argparse.ArgumentParser(description = __doc__) parser.add_argument('config', help = 'path of configuration file') parser.add_argument('-v', '--verbose', action = 'store_true', help = 'increase output verbosity') args = parser.parse_args() # logging.basicConfig(level = logging.DEBUG if args.verbose else logging.WARNING, stream = sys.stdout) logging.basicConfig(level = logging.INFO if args.verbose else logging.WARNING, stream = sys.stdout) site_conf = appconfig('config:{}'.format(os.path.abspath(args.config))) load_environment(site_conf.global_conf, site_conf.local_conf) registry = Registry() registry.prepare() registry.register(pylons.translator, MockTranslator()) plugins.load('synchronous_search') model.repo.new_revision() for package_extra in model.Session.query(model.PackageExtra).filter( model.PackageExtra.key == 'territorial_coverage_granularity', model.PackageExtra.value == 'france', ): package = package_extra.package if package.private or package.state != 'active': log.warning(u'Territorial coverage granularity of package {} must be manually corrected'.format( package.name)) continue package_extra.value = 'pays' model.repo.commit_and_remove() return 0
def setup_test_search_index(): from ckan import plugins if not is_search_supported(): raise SkipTest("Search not supported") search.clear() plugins.load("synchronous_search")
def main(): parser = argparse.ArgumentParser(description = __doc__) parser.add_argument('config', help = 'path of configuration file') parser.add_argument('-v', '--verbose', action = 'store_true', help = 'increase output verbosity') args = parser.parse_args() # logging.basicConfig(level = logging.DEBUG if args.verbose else logging.WARNING, stream = sys.stdout) logging.basicConfig(level = logging.INFO if args.verbose else logging.WARNING, stream = sys.stdout) site_conf = appconfig('config:{}'.format(os.path.abspath(args.config))) load_environment(site_conf.global_conf, site_conf.local_conf) registry = Registry() registry.prepare() registry.register(pylons.translator, MockTranslator()) plugins.load('synchronous_search') model.repo.new_revision() for package_extra in model.Session.query(model.PackageExtra).filter( model.PackageExtra.key == 'supplier_id', model.PackageExtra.package_id.in_( model.Session.query(model.Package.id).filter(model.Package.name.like('%-fork-%'))), ): model.Session.delete(package_extra) model.repo.commit_and_remove() return 0
def setup_class(cls): 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, "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 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"published": None, u"_id": 2, u"nested": {u"a": u"b"}, u"b\xfck": u"warandpeace", u"author": u"tolstoy"}, ]
def setup_class(cls): CreateTestData.create('publisher') model.repo.new_revision() usr = model.User(name="ectest", apikey="ectest", password=u'ectest') model.Session.add(usr) model.Session.commit() g = model.Group.get('david') g.type = 'organization' model.Session.add(g) p = model.Package.get('warandpeace') mu = model.Member(table_id=usr.id, table_name='user', group=g) mp = model.Member(table_id=p.id, table_name='package', group=g) model.Session.add(mu) model.Session.add(mp) model.Session.commit() cls.sysadmin_user = model.User.get('testsysadmin') status = create_vocab(u'status', cls.sysadmin_user.name) add_tag_to_vocab(u'http://purl.org/adms/status/Completed', status['id'], cls.sysadmin_user.name) plugins.load('ecportal')
def setup_class(cls): if not p.plugin_loaded("image_view"): p.load("image_view") if not p.plugin_loaded("recline_view"): p.load("recline_view") helpers.reset_db()
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): super(cls, cls).setup_class() if not p.plugin_loaded('image_view'): p.load('image_view') helpers.reset_db()
def test_resource_url(self): app = helpers._get_test_app() p.load(u'example_theme_v15_fanstatic') content = app.get(u'/en/base.html') assert u'example_theme.css' in content assert u'href="/data/fanstatic/example_theme' in content p.unload(u'example_theme_v15_fanstatic')
def test_api_info(self): dataset = factories.Dataset() resource = factories.Resource( id='588dfa82-760c-45a2-b78a-e3bc314a4a9b', package_id=dataset['id'], datastore_active=True) # the 'API info' is seen on the resource_read page, a snippet loaded by # javascript via data_api_button.html url = template_helpers.url_for( controller='api', action='snippet', ver=1, snippet_path='api_info.html', resource_id=resource['id']) if not p.plugin_loaded('datastore'): p.load('datastore') app = self._get_test_app() page = app.get(url, status=200) p.unload('datastore') # check we built all the urls ok expected_urls = ( 'http://test.ckan.net/api/3/action/datastore_create', 'http://test.ckan.net/api/3/action/datastore_upsert', '<code>http://test.ckan.net/api/3/action/datastore_search', 'http://test.ckan.net/api/3/action/datastore_search_sql', 'http://test.ckan.net/api/3/action/datastore_search?resource_id=588dfa82-760c-45a2-b78a-e3bc314a4a9b&limit=5', 'http://test.ckan.net/api/3/action/datastore_search?resource_id=588dfa82-760c-45a2-b78a-e3bc314a4a9b&q=jones', 'http://test.ckan.net/api/3/action/datastore_search_sql?sql=SELECT * from "588dfa82-760c-45a2-b78a-e3bc314a4a9b" WHERE title LIKE 'jones'', "url: 'http://test.ckan.net/api/3/action/datastore_search'", "http://test.ckan.net/api/3/action/datastore_search?resource_id=588dfa82-760c-45a2-b78a-e3bc314a4a9b&limit=5&q=title:jones", ) for url in expected_urls: assert url in page, url
def setup_class(cls): model.repo.rebuild_db() CreateTestData.create() plugins.load('drupal') from ckan.plugins import PluginImplementations from ckan.plugins.interfaces import IConfigurer for plugin in PluginImplementations(IConfigurer): plugin.update_config(config) url = config['drupal.db_url'] cls.engine = create_engine(url, echo=True) cls.metadata = MetaData(cls.engine) cls.node = Table('node', cls.metadata, autoload = True) cls.node = Table('node_revisions', cls.metadata, autoload = True) cls.package_table = Table('ckan_package', cls.metadata, autoload = True) cls.extra_table = Table('ckan_package_extra', cls.metadata, autoload = True) cls.resource_table = Table('ckan_resource', cls.metadata, autoload = True) cls.engine.execute('delete from ckan_package') cls.engine.execute('delete from ckan_resource') cls.engine.execute('delete from ckan_package_extra') cls.engine.execute('delete from ckan_package_tag') cls.engine.execute('delete from node') cls.engine.execute('delete from node_revisions')
def setup_class(cls): plugins.load('test_tag_vocab_plugin') CreateTestData.create(package_type='mock_vocab_tags_plugin') cls.sysadmin_user = model.User.get('testsysadmin') cls.dset = model.Package.get('warandpeace') cls.tag1_name = 'vocab-tag-1' cls.tag2_name = 'vocab-tag-2' # use our custom select class for this test suite cls.old_select = paste.fixture.Field.classes['select'] paste.fixture.Field.classes['select'] = Select # create a test vocab params = json.dumps({'name': TEST_VOCAB_NAME}) extra_environ = {'Authorization' : str(cls.sysadmin_user.apikey)} cls.extra_environ = {'Authorization' : str(cls.sysadmin_user.apikey)} response = cls.app.post('/api/action/vocabulary_create', params=params, extra_environ=extra_environ) assert json.loads(response.body)['success'] vocab_id = json.loads(response.body)['result']['id'] # add tags to the vocab extra_environ = {'Authorization' : str(cls.sysadmin_user.apikey)} params = json.dumps({'name': cls.tag1_name, 'vocabulary_id': vocab_id}) response = cls.app.post('/api/action/tag_create', params=params, extra_environ=extra_environ) assert json.loads(response.body)['success'] params = json.dumps({'name': cls.tag2_name, 'vocabulary_id': vocab_id}) response = cls.app.post('/api/action/tag_create', params=params, extra_environ=extra_environ) assert json.loads(response.body)['success']
def command(self): from ckan import plugins self._load_config() self._setup_app() plugins.load("synchronous_search") # so packages get indexed if self.args: cmd = self.args[0] else: cmd = "basic" if self.verbose: print "Creating %s test data" % cmd if cmd == "basic": self.create_basic_test_data() elif cmd == "user": self.create_test_user() print "Created user %r with password %r and apikey %r" % ("tester", "tester", "tester") elif cmd == "search": self.create_search_test_data() elif cmd == "gov": self.create_gov_test_data() elif cmd == "family": self.create_family_test_data() else: print "Command %s not recognized" % cmd raise NotImplementedError if self.verbose: print "Creating %s test data: Complete!" % cmd
def command(self): self._load_config() self._setup_app() from ckan import plugins plugins.load('synchronous_search') # so packages get indexed from create_test_data import CreateTestData if self.args: cmd = self.args[0] else: cmd = 'basic' if self.verbose: print 'Creating %s test data' % cmd if cmd == 'basic': CreateTestData.create_basic_test_data() elif cmd == 'user': CreateTestData.create_test_user() print 'Created user %r with password %r and apikey %r' % ('tester', 'tester', 'tester') elif cmd == 'search': CreateTestData.create_search_test_data() elif cmd == 'gov': CreateTestData.create_gov_test_data() elif cmd == 'family': CreateTestData.create_family_test_data() elif cmd == 'translations': CreateTestData.create_translations_test_data() elif cmd == 'vocabs': CreateTestData.create_vocabs_test_data() else: print 'Command %s not recognized' % cmd raise NotImplementedError if self.verbose: print 'Creating %s test data: Complete!' % cmd
def test_loading_datastore_last_doesnt_work(self): # This test is complicated because we can't import # ckanext.datastore.plugin before running it. If we did so, the # DatastorePlugin class would be parsed which breaks the reason of our # test. p.load('sample_datastore_plugin') thrown_exception = None try: p.load('datastore') except Exception as e: thrown_exception = e idatastores = [x.__class__.__name__ for x in p.PluginImplementations(interfaces.IDatastore)] p.unload('sample_datastore_plugin') assert thrown_exception is not None, \ ('Loading "datastore" after another IDatastore plugin was' 'loaded should raise DatastoreException') assert_equal(thrown_exception.__class__.__name__, plugin.DatastoreException.__name__) assert plugin.DatastorePlugin.__name__ not in idatastores, \ ('You shouldn\'t be able to load the "datastore" plugin after' 'another IDatastore plugin was loaded')
def test_user_objects_in_c_sysadmin(self): ''' A sysadmin user request will have expected user objects added to request. ''' if not p.plugin_loaded('test_routing_plugin'): p.load('test_routing_plugin') app = self._get_test_app() user = factories.Sysadmin() test_user_obj = model.User.by_name(user['name']) resp = app.get( '/from_pylons_extension_before_map', extra_environ={'REMOTE_USER': user['name'].encode('ascii')}) # tmpl_context available on response eq_(resp.tmpl_context.user, user['name']) eq_(resp.tmpl_context.userobj, test_user_obj) eq_(resp.tmpl_context.author, user['name']) eq_(resp.tmpl_context.remote_addr, 'Unknown IP Address') p.unload('test_routing_plugin')
def test_ask_around_flask_core_and_pylons_extension_route(self): if not p.plugin_loaded('test_routing_plugin'): p.load('test_routing_plugin') app = self._get_test_app() # We want our CKAN app, not the WebTest one app = app.app environ = { 'PATH_INFO': '/pylons_and_flask', 'REQUEST_METHOD': 'GET', } wsgiref.util.setup_testing_defaults(environ) answers = app.ask_around(environ) answers = sorted(answers, key=lambda a: a[1]) eq_(answers, [(True, 'flask_app', 'core'), (True, 'pylons_app', 'extension')]) p.unload('test_routing_plugin')
def test_ask_around_pylons_extension_route_post_using_get(self): if not p.plugin_loaded('test_routing_plugin'): p.load('test_routing_plugin') app = self._get_test_app() # We want our CKAN app, not the WebTest one app = app.app environ = { 'PATH_INFO': '/from_pylons_extension_before_map_post_only', 'REQUEST_METHOD': 'GET', } wsgiref.util.setup_testing_defaults(environ) answers = app.ask_around(environ) # We are going to get an answer from Pylons, but just because it will # match the catch-all template route, hence the `core` origin. eq_(answers, [(False, 'flask_app'), (True, 'pylons_app', 'core')]) p.unload('test_routing_plugin')
def test_register_post_indexerror(self): """ Test that we can't add a package if Solr is down. """ bad_solr_url = 'http://127.0.0.1/badsolrurl' original_settings = SolrSettings.get()[0] try: SolrSettings.init(bad_solr_url) plugins.load('synchronous_search') assert not self.get_package_by_name( self.package_fixture_data['name']) offset = self.package_offset() data = self.dumps(self.package_fixture_data) self.post_json(offset, data, status=500, extra_environ=self.extra_environ) model.Session.remove() finally: plugins.unload('synchronous_search') SolrSettings.init(original_settings)
def test_api_info(self): dataset = factories.Dataset() resource = factories.Resource( id='588dfa82-760c-45a2-b78a-e3bc314a4a9b', package_id=dataset['id'], datastore_active=True) # the 'API info' is seen on the resource_read page, a snippet loaded by # javascript via data_api_button.html url = template_helpers.url_for(controller='api', action='snippet', ver=1, snippet_path='api_info.html', resource_id=resource['id']) if not p.plugin_loaded('datastore'): p.load('datastore') app = self._get_test_app() page = app.get(url, status=200) p.unload('datastore') # check we built all the urls ok expected_urls = ( 'http://test.ckan.net/api/3/action/datastore_create', 'http://test.ckan.net/api/3/action/datastore_upsert', '<code>http://test.ckan.net/api/3/action/datastore_search', 'http://test.ckan.net/api/3/action/datastore_search_sql', 'http://test.ckan.net/api/3/action/datastore_search?resource_id=588dfa82-760c-45a2-b78a-e3bc314a4a9b&limit=5', 'http://test.ckan.net/api/3/action/datastore_search?q=jones&resource_id=588dfa82-760c-45a2-b78a-e3bc314a4a9b', 'http://test.ckan.net/api/3/action/datastore_search_sql?sql=SELECT * from "588dfa82-760c-45a2-b78a-e3bc314a4a9b" WHERE title LIKE 'jones'', "url: 'http://test.ckan.net/api/3/action/datastore_search'", "http://test.ckan.net/api/3/action/datastore_search?resource_id=588dfa82-760c-45a2-b78a-e3bc314a4a9b&limit=5&q=title:jones", ) for url in expected_urls: assert url in page, url
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 = 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): p.load('timeseries') helpers.reset_db() 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)) cls.dataset = model.Package.get('annakarenina') cls.data = { 'resource_id': '', 'force': True, 'method': 'insert', 'records': [{ 'author': 'tolstoy5', 'published': '2005-03-05' }, { 'author': 'tolstoy6' }, { 'author': 'tolstoy7', 'published': '2005-03-05' }] } cls.data['resource_id'] = cls.dataset.resources[0].id result = helpers.call_action('datastore_ts_create', **cls.data) cls.data['resource_id'] = cls.dataset.resources[1].id result = helpers.call_action('datastore_ts_create', **cls.data) datastore_test_helpers.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') 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))
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 test_ask_around_pylons_extension_route_get_after_map(self): if not p.plugin_loaded('test_routing_plugin'): p.load('test_routing_plugin') app = self._get_test_app() # We want our CKAN app, not the WebTest one app = app.app environ = { 'PATH_INFO': '/from_pylons_extension_after_map', 'REQUEST_METHOD': 'GET', } wsgiref.util.setup_testing_defaults(environ) answers = app.ask_around('can_handle_request', environ) eq_(len(answers), 1) eq_(answers[0][0], True) eq_(answers[0][1], 'pylons_app') eq_(answers[0][2], 'extension') p.unload('test_routing_plugin')
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') 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_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): 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': 'books2', 'fields': [{'id': 'book', 'type': 'text'}, {'id': 'author', 'type': 'text'}], 'records': [{'book': 'annakarenina', 'author': 'tolstoy'}, {'book': 'warandpeace', 'author': 'tolstoy'}] } #model.repo.rebuild_db() #model.repo.clean_db() import pylons engine = db._get_engine( None, {'connection_url': pylons.config['ckan.datastore.write_url']} ) cls.Session = orm.scoped_session(orm.sessionmaker(bind=engine))
def command(self): self._load_config() self._setup_app() # Now we can import from ckan import plugins from ckanext.dgu.testtools.create_test_data import DguCreateTestData plugins.load('synchronous_search') # so packages get indexed self.log = logging.getLogger(__name__) if self.args: cmd = self.args[0] else: cmd = 'basic' if cmd == 'basic': DguCreateTestData.create_dgu_test_data() elif cmd == 'users': DguCreateTestData.create_dgu_test_users() else: print 'Command %s not recognized' % cmd raise NotImplementedError self.log.info('Created DGU test data successfully')
def setup_class(self, **kwargs): # Every time the test is run, the database is resetted reset_db() if not plugins.plugin_loaded('image_view'): plugins.load('image_view') if not plugins.plugin_loaded('orgportals'): plugins.load('orgportals') organization_name = id_generator() dataset_name = id_generator() group_name = id_generator() resource_name = id_generator() resource_view_title = id_generator() self.mock_data = create_mock_data( organization_name=organization_name, dataset_name=dataset_name, group_name=group_name, resource_name=resource_name, resource_view_title=resource_view_title) self.subdashboard = create_subdashboard(self.mock_data)
def setup_class(cls): 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, 'fields': [{ 'id': 'book', 'type': 'text' }, { 'id': 'author', 'type': 'text' }], 'records': [{ 'book': 'annakarenina', 'author': 'tolstoy' }, { 'book': 'warandpeace', 'author': 'tolstoy' }] }
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): if not tests.is_datastore_supported(): raise nose.SkipTest("Datastore not supported") plugin = p.load('datastore') if plugin.legacy_mode: 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') resource = model.Package.get('annakarenina').resources[0] cls.data = { 'resource_id': resource.id, '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 cls.expected_records = [{u'_full_text': u"'annakarenina':1 'b':3 'moo':4 'tolstoy':2", 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"'b':3 'tolstoy':2 'warandpeac':1", 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}]
def setup_class(cls): cls.app = helpers._get_test_app() if not p.plugin_loaded('multilingual_dataset'): p.load('multilingual_dataset') if not p.plugin_loaded('multilingual_group'): p.load('multilingual_group') if not p.plugin_loaded('multilingual_tag'): p.load('multilingual_tag') ckan.tests.legacy.setup_test_search_index() _create_test_data.CreateTestData.create_translations_test_data() cls.sysadmin_user = model.User.get('testsysadmin') cls.org = { 'name': 'test_org', 'title': 'russian', 'description': 'Roger likes these books.' } ckan.tests.legacy.call_action_api(cls.app, 'organization_create', apikey=cls.sysadmin_user.apikey, **cls.org) dataset = { 'name': 'test_org_dataset', 'title': 'A Novel By Tolstoy', 'owner_org': cls.org['name'] } ckan.tests.legacy.call_action_api(cls.app, 'package_create', apikey=cls.sysadmin_user.apikey, **dataset) # Add translation terms that match a couple of group names and package # names. Group names and package names should _not_ get translated even # if there are terms matching them, because they are used to form URLs. for term in ('roger', 'david', 'annakarenina', 'warandpeace'): for lang_code in ('en', 'de', 'fr'): data_dict = { 'term': term, 'term_translation': 'this should not be rendered', 'lang_code': lang_code } context = { 'model': ckan.model, 'session': ckan.model.Session, 'user': '******' } ckan.logic.action.update.term_translation_update( context, data_dict)
def setup(self): test_helpers.reset_db() init_tables_ga() setup_user_authority_table() setup_user_authority_dataset_table() setup_featured_charts_table() setup_most_active_organizations_table() rebuild() if not plugins.plugin_loaded('c3charts'): plugins.load('c3charts') if not plugins.plugin_loaded('datagovmk'): plugins.load('datagovmk') if not plugins.plugin_loaded('scheming_organizations'): plugins.load('scheming_organizations') if not plugins.plugin_loaded('fluent'): plugins.load('fluent')
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 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 setup_class(cls): if not p.plugin_loaded('image_view'): p.load('image_view')
def setup_class(cls): if not p.plugin_loaded('image_view'): p.load('image_view') helpers.reset_db()
def setup(cls): cls.observer = plugins.load('test_observer_plugin')
def test_inexistent_plugin_loading(self): plugins.load('inexistent-plugin')
def __init__(self): from ckan import plugins if not is_search_supported(): raise SkipTest("Search not supported") plugins.load('synchronous_search')
def setup_class(cls): p.load('datastore')
def test_loading_datastore_first_works(self): p.load('datastore') p.load('sample_datastore_plugin') p.unload('sample_datastore_plugin') p.unload('datastore')
def setup_class(cls): cls.original_config = config.copy() plugins.load('example_idatasetform_v4')