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 teardown_class(cls): plugins.unload(cls.plugin) cls.plugin.active = False from ckan.controllers import package as package_controller package_controller._default_controller_behaviour = cls.old_default_controller paste.fixture.Field.classes['select'] = cls.old_select model.repo.rebuild_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 teardown_class(cls): if p.plugin_loaded('webpage_view'): p.unload('webpage_view') super(TestWebPageView, cls).teardown_class() helpers.reset_db()
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 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_class(cls): p.unload('c3charts') p.unload('datastore') super(TestChartView, cls).teardown_class() helpers.reset_db()
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 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 teardown_class(cls): plugins.unload('example_idatasetform_v4') helpers.reset_db() ckan.lib.search.clear_all() config.clear() config.update(cls.original_config)
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, "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':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}] engine = db._get_engine({"connection_url": pylons.config["ckan.datastore.write_url"]}) cls.Session = orm.scoped_session(orm.sessionmaker(bind=engine))
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_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 test_read_plugin_hook(self): plugin = MockGroupControllerPlugin() plugins.load(plugin) name = u'david' offset = url_for(controller='group', action='read', id=name) res = self.app.get(offset, status=200, extra_environ={'REMOTE_USER': '******'}) assert plugin.calls['read'] == 1, plugin.calls plugins.unload(plugin)
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 teardown_class(cls): '''Nose runs this method once after all the test methods in our class have been run. ''' # We have to unload the plugin we loaded, so it doesn't affect any # tests that run after ours. plugins.unload('example_iauthfunctions')
def test_read_plugin_hook(self): plugins.load("test_group_plugin") name = u"david" offset = url_for(controller="group", action="read", id=name) res = self.app.get(offset, status=200, extra_environ={"REMOTE_USER": "******"}) p = plugins.get_plugin("test_group_plugin") assert p.calls["read"] == 1, p.calls plugins.unload("test_group_plugin")
def teardown_class(cls): rebuild_all_dbs(cls.Session) p.unload('datastore') p.unload('datapusher') # Reenable Solr indexing if (sys.version_info[0] == 2 and sys.version_info[1] == 6 and not p.plugin_loaded('synchronous_search')): p.load('synchronous_search')
def teardown_class(cls): import ckan.plugins as p for plugin in reversed(getattr(cls, '_load_plugins', [])): p.unload(plugin) # Restore the Pylons config to its original values, in case any tests # changed any config settings. config.clear() config.update(cls._original_config)
def test_search_plugin_hooks(self): plugins.load('test_package_controller_plugin') plugin = plugins.get_plugin('test_package_controller_plugin') offset = url_for(controller='package', action='search') res = self.app.get(offset) # get redirected ... assert plugin.calls['before_search'] == 1, plugin.calls assert plugin.calls['after_search'] == 1, plugin.calls plugins.unload('test_package_controller_plugin')
def test_resource_view_factory(self): if not p.plugin_loaded("image_view"): p.load("image_view") resource_view1 = factories.ResourceView() resource_view2 = factories.ResourceView() assert_not_equals(resource_view1["id"], resource_view2["id"]) p.unload("image_view")
def test_read_plugin_hook(self): plugins.load('test_group_plugin') name = u'david' offset = url_for(controller='group', action='read', id=name) res = self.app.get(offset, status=200, extra_environ={'REMOTE_USER': '******'}) p = plugins.get_plugin('test_group_plugin') assert p.calls['read'] == 1, p.calls plugins.unload('test_group_plugin')
def test_resource_view_factory(self): if not p.plugin_loaded('image_view'): p.load('image_view') resource_view1 = factories.ResourceView() resource_view2 = factories.ResourceView() assert_not_equals(resource_view1['id'], resource_view2['id']) p.unload('image_view')
def teardown_class(cls): '''Nose runs this method once after all the test methods in our class have been run. ''' rebuild_all_dbs(cls.Session) # unload plugins p.unload('datastore') p.unload('realtime')
def test_read_plugin_hook(self): plugins.load('test_package_controller_plugin') plugin = plugins.get_plugin('test_package_controller_plugin') name = u'annakarenina' offset = url_for(controller='package', action='read', id=name) res = self.app.get(offset) assert plugin.calls['read'] == 1, plugin.calls assert plugin.calls['after_show'] == 1, plugin.calls plugins.unload('test_package_controller_plugin')
def test_helper_exception_non_existing_helper_as_item(self): '''Calling a non-existing helper on `h` raises a HelperException.''' if not p.plugin_loaded('test_helpers_plugin'): p.load('test_helpers_plugin') app = self._get_test_app() app.get('/broken_helper_as_item') p.unload('test_helpers_plugin')
def test_new_plugin_hook(self): plugin = MockGroupControllerPlugin() plugins.load(plugin) offset = url_for(controller='group', action='new') res = self.app.get(offset, status=200, extra_environ={'REMOTE_USER': '******'}) form = res.forms['group-edit'] form['name'] = "hahaha" form['title'] = "huhuhu" res = form.submit('save', status=302, extra_environ={'REMOTE_USER': '******'}) assert plugin.calls['create'] == 1, plugin.calls plugins.unload(plugin)
def test_edit_plugin_hook(self): plugin = MockGroupControllerPlugin() plugins.load(plugin) offset = url_for(controller='group', action='edit', id=self.groupname) res = self.app.get(offset, status=200, extra_environ={'REMOTE_USER': '******'}) form = res.forms['group-edit'] group = model.Group.by_name(self.groupname) form['title'] = "huhuhu" res = form.submit('save', status=302, extra_environ={'REMOTE_USER': '******'}) assert plugin.calls['edit'] == 1, plugin.calls plugins.unload(plugin)
def test_new_plugin_hook(self): plugins.load("test_group_plugin") offset = url_for(controller="group", action="new") res = self.app.get(offset, status=200, extra_environ={"REMOTE_USER": "******"}) form = res.forms["group-edit"] form["name"] = "hahaha" form["title"] = "huhuhu" res = form.submit("save", status=302, extra_environ={"REMOTE_USER": "******"}) p = plugins.get_plugin("test_group_plugin") assert p.calls["create"] == 1, p.calls plugins.unload("test_group_plugin")
def test_url_for_pylons_request_using_flask_url_for(self): if not p.plugin_loaded('test_routing_plugin'): p.load('test_routing_plugin') res = self.app.get('/pylons_route_flask_url_for') assert u'This URL was generated by Flask' in res.ubody assert u'/api/3' in res.ubody p.unload('test_routing_plugin')
def teardown_class(cls): datastore_test_helpers.clear_db(cls.Session) p.unload('timeseries') helpers.reset_db()
def teardown_class(self): if plugins.plugin_loaded('requestdata'): plugins.unload('requestdata')
def teardown_class(cls): plugins.unload('example_ivalidators')
def setup_class(cls): if not tests.is_datastore_supported(): raise nose.SkipTest("Datastore not supported") cls.app = helpers._get_test_app() 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 teardown_class(cls): plugins.unload('example_igroupform') super(TestGroupController, cls).teardown_class()
def setup(self): if p.plugin_loaded('datastore'): p.unload('datastore') if p.plugin_loaded('sample_datastore_plugin'): p.unload('sample_datastore_plugin')
def teardown_class(cls): import ckan.plugins as p for plugin in reversed(getattr(cls, '_load_plugins', [])): p.unload(plugin) helpers.reset_db()
def teardown_class(cls): p.unload('datastore') helpers.reset_db()
def setup(self): if p.plugin_loaded("datastore"): p.unload("datastore") if p.plugin_loaded("sample_datastore_plugin"): p.unload("sample_datastore_plugin")
def teardown_class(cls): p.unload('piechart')
def teardown(self): if p.plugin_loaded("sample_datastore_plugin"): p.unload("sample_datastore_plugin") if p.plugin_loaded("datastore"): p.unload("datastore")
def teardown_class(cls): p.unload('image_view') helpers.reset_db()
def teardown_class(cls): p.unload('image_view')
def teardown_class(cls): p.unload('datastore')
def teardown_class(cls): model.repo.rebuild_db() p.unload('datastore')
def teardown_class(cls): rebuild_all_dbs(cls.Session) p.unload('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 teardown_class(cls): plugins.unload('example_igroupform_default_group_type') super(TestGroupControllerEdit_DefaultGroupType, cls).teardown_class()
def teardown_class(cls): model.repo.rebuild_db() plugins.unload('test_resource_preview', 'test_json_resource_preview')
def teardown_class(cls): cls.config.reset() cls.df.destroy() p.unload('datastore') p.unload('twitter')
def teardown_class(cls): plugins.unload('example_igroupform_organization') super(TestOrganizationController, cls).teardown_class()
def teardown_class(cls): p.unload('image_view') super(TestImageView, cls).teardown_class() helpers.reset_db()
def teardown_class(cls): p.unload('datapusher') p.unload('datastore') p.unload('recline_grid_view')
def teardown_class(cls): super(TestExampleCustomEmailsPlugin, cls).teardown_class() plugins.unload('example_theme_custom_emails')
def teardown_class(cls): p.unload('barchart')
def test_loading_datastore_first_works(self): p.load("datastore") p.load("sample_datastore_plugin") p.unload("sample_datastore_plugin") p.unload("datastore")
def teardown_class(cls): super(HarvestSourceActionBase, cls).teardown_class() p.unload('test_action_harvester')
def teardown_class(cls): p.unload('test_action_harvester')
def teardown(cls): plugins.unload('test_observer_plugin')
def teardown_class(self): p.unload('test_rdf_harvester')