def setup_class(cls): if engine_is_sqlite(): raise SkipTest("Non-memory database needed for this test") cls.pid = cls._start_ckan_server() ## Don't need to init database, since it is same database as this process uses cls._wait_for_url()
def test_revisions__since_revision_id__latest(self): last_rev, rev = self._get_last_and_penultimate_revisions() offset = "/api/util/revisions?since-revision-id=%s" % rev.id result = self.app.get(offset, status=[200]) res = json.loads(result.body) assert isinstance(res, dict), res assert set(res.keys()) >= set(("since_timestamp", "datasets")), res.keys() assert_equal(res["since_revision_id"], rev.id) assert_equal(res["newest_revision_id"], last_rev.id) assert_equal(res["number_of_revisions"], 2) assert_equal(res["results_limited"], False) pkgs = res["datasets"] pkg = pkgs[0] assert_equal(pkg["name"], "latest") assert_equal(pkg["notes"].strip(), "Latest dataset.") assert pkg["publisher_title"] in ("National Health Service", "Department of Health"), pkg["publisher_title"] assert set(pkg.keys()) >= set( ("title", "dataset_link", "notes", "publisher_title", "publisher_link") ), pkg.keys() # try dataset_link if model.engine_is_sqlite(): raise SkipTest("Link tests need postgres") res = self.app.get(pkg["dataset_link"], status=[200]) assert "latest" in res.body # try publisher_link res = self.app.get(pkg["publisher_link"], status=[200]) assert "National Health Service" in res.body, res
def test_revisions__since_revision_id__latest(self): last_rev, rev = self._get_last_and_penultimate_revisions() offset = '/api/util/revisions?since-revision-id=%s' % rev.id result = self.app.get(offset, status=[200]) res = json.loads(result.body) assert isinstance(res, dict), res assert set(res.keys()) >= set(('since_timestamp', 'datasets')), res.keys() assert_equal(res['since_revision_id'], rev.id) assert_equal(res['newest_revision_id'], last_rev.id) assert_equal(res['number_of_revisions'], 2) assert_equal(res['results_limited'], False) pkgs = res['datasets'] pkg = pkgs[0] assert_equal(pkg['name'], 'latest') assert_equal(pkg['notes'].strip(), 'Latest dataset.') assert pkg['publisher_title'] in ('National Health Service', 'Department of Health'), pkg['publisher_title'] assert set(pkg.keys()) >= set(('title', 'dataset_link', 'notes', 'publisher_title', 'publisher_link')), pkg.keys() # try dataset_link if model.engine_is_sqlite(): raise SkipTest("Link tests need postgres") res = self.app.get(pkg['dataset_link'], status=[200]) assert 'latest' in res.body # try publisher_link res = self.app.get(pkg['publisher_link'], status=[200]) assert 'National Health Service' in res.body, res
def setup_class(cls): if engine_is_sqlite(): raise SkipTest("PostGIS is required for this test") # This will create the PostGIS tables (geometry_columns and # spatial_ref_sys) which were deleted when rebuilding the database table = Table('geometry_columns', meta.metadata) if not table.exists(): setup_postgis_tables()
def test_children(self): if model.engine_is_sqlite(): from nose import SkipTest raise SkipTest("Can't use CTE for sqlite") group_name = 'deletetest' CreateTestData.create_groups([{ 'name': group_name, 'packages': [] }, { 'name': "parent_group", 'packages': [] }], admin_user_name='testsysadmin') parent = model.Group.by_name("parent_group") group = model.Group.by_name(group_name) rev = model.repo.new_revision() rev.author = "none" member = model.Member(group_id=parent.id, table_id=group.id, table_name='group', capacity='member') model.Session.add(member) model.repo.commit_and_remove() offset = url_for(controller='group', action='edit', id=group_name) res = self.app.get(offset, status=200, extra_environ={'REMOTE_USER': '******'}) main_res = self.main_div(res) assert 'Edit: %s' % group.title in main_res, main_res assert 'value="active" selected' in main_res, main_res parent = model.Group.by_name("parent_group") assert_equal(len(parent.get_children_groups()), 1) # delete form = res.forms['group-edit'] form['state'] = 'deleted' res = form.submit('save', status=302, extra_environ={'REMOTE_USER': '******'}) group = model.Group.by_name(group_name) assert_equal(group.state, 'deleted') parent = model.Group.by_name("parent_group") assert_equal(len(parent.get_children_groups()), 0)
def test_status(self): response = self.app.get( url=url_for(controller='api', action='status'), params={}, status=200, ) res = json.loads(response.body) assert_equal(res['ckan_version'], __version__) assert_equal(res['site_url'], 'http://test.ckan.net') assert_equal(res['site_title'], 'CKAN') assert_equal(res['site_description'], '') assert_equal(res['locale_default'], 'en') assert_equal(type(res['extensions']), list) expected_extensions = set() if not model.engine_is_sqlite(): expected_extensions.add('synchronous_search') assert_equal(set(res['extensions']), expected_extensions)
def test_children(self): if model.engine_is_sqlite(): from nose import SkipTest raise SkipTest("Can't use CTE for sqlite") group_name = 'deletetest' CreateTestData.create_groups([{'name': group_name, 'packages': []}, {'name': "parent_group", 'packages': []}], admin_user_name='testsysadmin') parent = model.Group.by_name("parent_group") group = model.Group.by_name(group_name) rev = model.repo.new_revision() rev.author = "none" member = model.Member(group_id=group.id, table_id=parent.id, table_name='group', capacity='member') model.Session.add(member) model.repo.commit_and_remove() offset = url_for(controller='group', action='edit', id=group_name) res = self.app.get(offset, status=200, extra_environ={'REMOTE_USER': '******'}) main_res = self.main_div(res) assert 'Edit: %s' % group.title in main_res, main_res assert 'value="active" selected' in main_res, main_res parent = model.Group.by_name("parent_group") assert_equal(len(parent.get_children_groups()), 1) # delete form = res.forms['group-edit'] form['state'] = 'deleted' res = form.submit('save', status=302, extra_environ={'REMOTE_USER': '******'}) group = model.Group.by_name(group_name) assert_equal(group.state, 'deleted') parent = model.Group.by_name("parent_group") assert_equal(len(parent.get_children_groups()), 0)
def test_children(self): if model.engine_is_sqlite(): from nose import SkipTest raise SkipTest("Can't use CTE for sqlite") group_name = "deletetest" CreateTestData.create_groups( [{"name": group_name, "packages": []}, {"name": "parent_group", "packages": []}], admin_user_name="testsysadmin", ) parent = model.Group.by_name("parent_group") group = model.Group.by_name(group_name) rev = model.repo.new_revision() rev.author = "none" member = model.Member(group_id=parent.id, table_id=group.id, table_name="group", capacity="member") model.Session.add(member) model.repo.commit_and_remove() offset = url_for(controller="group", action="edit", id=group_name) res = self.app.get(offset, status=200, extra_environ={"REMOTE_USER": "******"}) main_res = self.main_div(res) assert "Edit: %s" % group.title in main_res, main_res assert 'value="active" selected' in main_res, main_res parent = model.Group.by_name("parent_group") assert_equal(len(parent.get_children_groups()), 1) # delete form = res.forms["group-edit"] form["state"] = "deleted" res = form.submit("save", status=302, extra_environ={"REMOTE_USER": "******"}) group = model.Group.by_name(group_name) assert_equal(group.state, "deleted") parent = model.Group.by_name("parent_group") assert_equal(len(parent.get_children_groups()), 0)
def setup_class(cls): if engine_is_sqlite(): raise SkipTest("PostGIS is required for this test") # This will create the PostGIS tables (geometry_columns and # spatial_ref_sys) which were deleted when rebuilding the database table = Table('spatial_ref_sys', meta.metadata) if not table.exists(): create_postgis_tables() # When running the tests with the --reset-db option for some # reason the metadata holds a reference to the `package_extent` # table after being deleted, causing an InvalidRequestError # exception when trying to recreate it further on if 'package_extent' in meta.metadata.tables: meta.metadata.remove(meta.metadata.tables['package_extent']) spatial_db_setup() # Setup the harvest tables harvest_model_setup()
def setup_class(cls): ''' ''' if engine_is_sqlite(): raise SkipTest(u'PostGIS is required for this test') # This will create the PostGIS tables (geometry_columns and # spatial_ref_sys) which were deleted when rebuilding the database table = Table(u'spatial_ref_sys', meta.metadata) if not table.exists(): create_postgis_tables() # When running the tests with the --reset-db option for some # reason the metadata holds a reference to the `package_extent` # table after being deleted, causing an InvalidRequestError # exception when trying to recreate it further on if u'package_extent' in meta.metadata.tables: meta.metadata.remove(meta.metadata.tables[u'package_extent']) spatial_db_setup() # Setup the harvest tables harvest_model_setup()
def are_foreign_keys_supported(): return not model.engine_is_sqlite()
def is_search_supported(): is_supported_db = not model.engine_is_sqlite() return is_supported_db
here_dir = os.path.dirname(os.path.abspath(__file__)) conf_dir = os.path.dirname(os.path.dirname(here_dir)) # Invoke websetup with the current config file SetupCommand('setup-app').run([config['__file__']]) # monkey patch paste.fixtures.TestRespose # webtest (successor library) already has this # http://pythonpaste.org/webtest/#parsing-the-body def _getjson(self): return json.loads(self.body) paste.fixture.TestResponse.json = property(_getjson) # Check config is correct for sqlite if model.engine_is_sqlite(): assert ckan_nose_plugin.CkanNose.settings.is_ckan, \ 'You forgot the "--ckan" nosetest setting - see doc/test.rst' class BaseCase(object): def setup(self): pass def teardown(self): pass @staticmethod def _system(cmd): import commands (status, output) = commands.getstatusoutput(cmd)
def is_regex_supported(): is_supported_db = not model.engine_is_sqlite() return is_supported_db
def is_migration_supported(): is_supported_db = not model.engine_is_sqlite() return is_supported_db
def setup_class(cls): if model.engine_is_sqlite(): raise SkipTest("Search not supported") CreateTestData.create()