diff --git a/ckanext/odsh/helpers.py b/ckanext/odsh/helpers.py index 0dac0cfba4bc6eab333cd2d2eacb1a72568c6ad3..785e9c2d0b46ec8ed7c5bbd3e76eb3b6fd6d1fa7 100644 --- a/ckanext/odsh/helpers.py +++ b/ckanext/odsh/helpers.py @@ -250,6 +250,7 @@ def odsh_public_resource_url(res): else: return res['url'] + def odsh_get_version_id(): try: home = config.get('ckanext.odsh.home', None) @@ -262,15 +263,10 @@ def odsh_get_version_id(): return 'unknown' return 'unknown' + def odsh_show_testbanner(): return config.get('ckanext.odsh.showtestbanner', 'False') == 'True' -def odsh_is_slave(): - c = config.get('ckanext.odsh.slave', None) - if c is None or (c != 'True' and c != 'False'): - return -1 - return 1 if c == 'True' else 0 - def odsh_get_facet_items_dict(name, limit=None): ''' diff --git a/ckanext/odsh/precondition.py b/ckanext/odsh/precondition.py index eda5a961a5a8d2e555beebe0e28c59283d1032a0..5314133f7735723645ebc99ebc8bf2f19a0f94eb 100644 --- a/ckanext/odsh/precondition.py +++ b/ckanext/odsh/precondition.py @@ -3,14 +3,3 @@ import ckan.plugins.toolkit as tk class PreconditionViolated(Exception): def __init__(self, message): super(PreconditionViolated, self).__init__(message) - - -def not_on_slave(func): - def wrapped(*args, **kwargs): - if tk.config.get('ckanext.odsh.slave', False): - raise PreconditionViolated('not allowed on slave') - return func(*args, **kwargs) - - if tk.config.get('ckanext.odsh.debug', False): - return wrapped - return func diff --git a/ckanext/odsh/templates/base.html b/ckanext/odsh/templates/base.html index 5e2a2ac29dff6458256ebdfad63f216a772b6952..fdc7cbe465311eb0508c71e8c0f79fb684fec1ee 100644 --- a/ckanext/odsh/templates/base.html +++ b/ckanext/odsh/templates/base.html @@ -9,10 +9,10 @@ {% endblock styles %} {% block head_extras %} -{{ super() }} -<meta data-name="type" content="{{h.odsh_is_slave()}}"> - + {{ super() }} {% endblock %} + {% block bodytag %} data-site-root="{{ h.odsh_public_url() }}" data-locale-root="{{ h.odsh_public_url() }}" {% endblock %} + {% block page %} {% endblock %} diff --git a/ckanext/odsh/tests/ckan_selenium.py b/ckanext/odsh/tests/ckan_selenium.py index 3bacd10f910c67790f5b4ea5a5e2ca98f3dda215..239f35b1c76cce6293a059ef6fa02ba356b24416 100644 --- a/ckanext/odsh/tests/ckan_selenium.py +++ b/ckanext/odsh/tests/ckan_selenium.py @@ -52,9 +52,6 @@ class SeleniumCkanApp: def close(): driver.close() - def get_slave_flag(self): - return self.findElementByXPath("//meta[@data-name='type']").get_attribute("content") - def findElementByXPath(self, xpath): return self.driver.find_element(By.XPATH, xpath) @@ -88,7 +85,3 @@ class SeleniumCkanApp: def currentUrl(self): return self.driver.current_url - - def onMaster(self): - cont = self.get_slave_flag() - return cont == '0' diff --git a/ckanext/odsh/tests/test_env.py b/ckanext/odsh/tests/test_env.py index 978fdfde07442c0316988a09c9da9a487b840590..70e2bf126e9ac42b275aff07b190fbd271ca2e76 100644 --- a/ckanext/odsh/tests/test_env.py +++ b/ckanext/odsh/tests/test_env.py @@ -12,8 +12,6 @@ from urllib.parse import urlsplit expected_commit = '8cd9576884cae6abe50a27c891434cb9fe87ced2' -# run with nosetests --ckan --nologcapture --with-pylons=<config to test> ckanext/odsh/tests/test_env.py - def checkConfig(key, expected=None, minLength=None): value = config.get(key, None) @@ -64,16 +62,6 @@ def checkJsonFile(key, expectedKey=None, expectedLength=None): assert len(data) >= expectedLength -def isSlave(): - value = checkConfig('ckanext.odsh.slave') - assert value == 'True' or value == 'False' - return checkConfig('ckanext.odsh.slave') == 'True' - - -def isMaster(): - return not isSlave() - - class MultiOrderedDict(OrderedDict): def __setitem__(self, key, value): if isinstance(value, list) and key in self: @@ -113,24 +101,19 @@ class TestEnv: checkConfig('ckan.site_intro_text', '#Willkommen auf Open Data Portal Schleswig-Holstein.') - if isMaster(): - checkConfigDir('ckan.storage_path') - checkConfig('ckanext-archiver.user_agent_string', - 'Open Data Schleswig-Holstein') - checkConfig('ckan.harvest.mq.type', 'redis') - - if isSlave(): - checkConfig('ckanext.odsh.upload_formats', minLength=2) - checkConfig('ckanext.spatial.search_backend', 'solr-spatial-field') - checkConfig('ckanext.spatial.common_map.type', 'wms') - checkConfig('ckanext.spatial.common_map.wms.url', - 'https://sg.geodatenzentrum.de/wms_webatlasde.light_grau') - checkConfig('ckanext.spatial.common_map.wms.layers', - 'webatlasde.light_grau') - - if isMaster(): - checkJsonFile( - 'qa.resource_format_openness_scores_json', expectedLength=60) + checkConfigDir('ckan.storage_path') + checkConfig('ckanext-archiver.user_agent_string', + 'Open Data Schleswig-Holstein') + checkConfig('ckan.harvest.mq.type', 'redis') + checkConfig('ckanext.odsh.upload_formats', minLength=2) + checkConfig('ckanext.spatial.search_backend', 'solr-spatial-field') + checkConfig('ckanext.spatial.common_map.type', 'wms') + checkConfig('ckanext.spatial.common_map.wms.url', + 'https://sg.geodatenzentrum.de/wms_webatlasde.light_grau') + checkConfig('ckanext.spatial.common_map.wms.layers', + 'webatlasde.light_grau') + checkJsonFile( + 'qa.resource_format_openness_scores_json', expectedLength=60) checkConfig('ckanext.odsh.language.mapping', '/usr/lib/ckan/default/src/ckanext-odsh/languages.json') @@ -140,16 +123,9 @@ class TestEnv: def test_plugins(self): value = config.get('ckan.plugins', []) - for p in ['odsh']: + for p in ['odsh', 'odsh_dcat_harvest', 'odsh_autocomplete']: assert p in value, 'missing plugin:' + p - if isMaster(): - for p in ['odsh_icap', 'odsh_dcat_harvest']: - assert p in value, 'missing plugin:' + p - if isSlave(): - for p in ['odsh_autocomplete datarequests']: - assert p in value, 'missing plugin:' + p - # pdb.set_trace() def test_licenses(self): @@ -167,92 +143,92 @@ class TestEnv: profiles.resource_formats() assert len(profiles._RESOURCE_FORMATS_IMPORT) > 120 - def test_routes(self): - if isMaster(): - return - - expexted_rules = \ - """ ProxyPass /dataset/new http://10.61.47.219/dataset/new - ProxyPassReverse /dataset/new http://10.61.47.219/dataset/new - ProxyPassMatch ^/(dataset/delete/[^/]+)$ http://10.61.47.219/$1 - ProxyPassReverse ^/(dataset/delete/[^/]+)$ http://10.61.47.219/$1 - ProxyPassMatch ^/(dataset/edit/[^/]+)$ http://10.61.47.219/$1 - ProxyPassReverse ^/(dataset/edit/[^/]+)$ http://10.61.47.219/$1 - ProxyPassReverse /dataset http://141.91.184.90/dataset - ProxyPassReverse /dataset http://141.91.184.90/dataset - ProxyPass /dataset/new_resource http://10.61.47.219/dataset/new_resource - ProxyPassReverse /dataset/new_resource http://141.91.184.90/dataset/new_resource - ProxyPassReverse /dataset/new_resource http://141.91.184.90/dataset/new_resource - #ProxyPass /api/i18n/de http://141.91.184.90/api/i18n/de - ProxyPassReverse ^/uploads/group/(.*)$ http://10.61.47.219/uploads/group/$1 - ProxyPassMatch ^/uploads/group/(.*)$ http://10.61.47.219/uploads/group/$1 - ProxyPassReverse ^/(dataset/[^/]+/resource/[^/]+/download/[^/]+)$ http://141.91.184.90/$1 - ProxyPassMatch ^/(dataset/[^/]+/resource/[^/]+/download/[^/]+)$ http://141.91.184.90/$1 - ProxyPassReverse ^/(dataset/[^/]+/resource/[^/]+)$ http://10.61.47.219/$1 - ProxyPassMatch ^/(dataset/[^/]+/resource/[^/]+/)$ http://10.61.47.219/$1 - ProxyPassMatch ^/(dataset/[^/]+/resource_data/[^/]+)$ http://10.61.47.219/$1 - ProxyPassReverse ^/(dataset/[^/]+/resource_data/[^/]+)$ http://10.61.47.219/$1 - ProxyPassMatch ^/(dataset/[^/]+/resource_edit/[^/]+)$ http://10.61.47.219/$1 - ProxyPassReverse ^/(dataset/[^/]+/resource_edit/[^/]+)$ http://10.61.47.219/$1 - ProxyPassMatch ^/(dataset/[^/]+/resource/[^/]+/new_view[^/]*)$ http://10.61.47.219/$1 - ProxyPassReverse ^/(dataset/[^/]+/resource/[^/]+/new_view[^/]*)$ http://10.61.47.219/$1 - ProxyPassMatch ^/(harvest.*)$ http://141.91.184.90/$1 - ProxyPassReverse /harvest http://141.91.184.90/harvest - ProxyPass /harvest http://141.91.184.90/harvest - ProxyPassReverse ^/(harvest.*)$ http://141.91.184.90/$1 - ProxyPassReverse ^/(api/3/action/package.*)$ http://10.61.47.219/$1 - ProxyPassMatch ^/(api/3/action/package.*)$ http://10.61.47.219/$1 - ProxyPass /api/action/package_create http://10.61.47.219/api/action/package_create - ProxyPassReverse /api/action/package_create http://10.61.47.219/api/action/package_create - ProxyPass /api/action/resource_create http://10.61.47.219/api/action/resource_create - ProxyPassReverse /api/action/resource_create http://10.61.47.219/api/action/resource_create - ProxyPassMatch ^/(organization/edit/[^/]+)$ http://10.61.47.219/$1 - ProxyPassReverse ^/(organization/edit/[^/]+)$ http://10.61.47.219/$1 - ProxyPass /organization/new http://<interne-IP-Master>/organization/new - ProxyPassReverse /organization/new http://<interne-IP-Master>/organization/new - ProxyPassReverse /organization http://<interne-IP-Master>/organization - ProxyPassReverse ^/(organization/edit/[^/]+)$ http://<interne-IP-Master>/$1 - - # ProxyPass /datarequest http://10.61.47.219/datarequest - # ProxyPassReverse /datarequest http://10.61.47.219/datarequest - """ - - expected = self._parse_rules(expexted_rules.splitlines()) - - # with open('ckan_default.conf', 'r') as aconfig: - with open('/etc/apache2/sites-enabled/ckan_default.conf', 'r') as aconfig: - lines = aconfig.readlines() - # pdb.set_trace() - current = self._parse_rules(lines, check_host=True) - if len(expected.symmetric_difference(current)) > 0: - diff = expected.difference(current) - if len(diff) > 0: - print('WARNING: missing routes:') - for r in sorted(diff, key=lambda tup: tup[1]): - print(('{cmd} {source} {target}'.format( - cmd=r[0], source=r[1], target='http://<interne-IP-Master>'+r[2]))) - diff = current.difference(expected) - if len(diff) > 0: - print('WARNING: found unexpected routes:') - for r in sorted(diff, key=lambda tup: tup[1]): - print(('{cmd} {source} {target}'.format( - cmd=r[0], source=r[1], target='<target>'+r[2]))) - - def _parse_rules(self, lines, check_host=False): - rules = set(['ProxyPassMatch', 'ProxyPassReverse', 'ProxyPass']) - ret = [] - hosts = set() - for line in lines: - tokens = [t for t in line.strip().split(' ') if t.strip()] - if not tokens or tokens[0] not in rules: - continue - assert len(tokens) == 3 - # for token in tokens: - # print(token) - f = urlsplit(tokens[2]) - ret.append((tokens[0], tokens[1], f.path)) - hosts.add(f.netloc) - if check_host and len(hosts) > 1: - print(('WARNING: found multiple target hosts: {hosts}'.format( - hosts=', '.join(hosts)))) - return set(ret) + # def test_routes(self): + # if isMaster(): + # return + + # expexted_rules = \ + # """ ProxyPass /dataset/new http://10.61.47.219/dataset/new + # ProxyPassReverse /dataset/new http://10.61.47.219/dataset/new + # ProxyPassMatch ^/(dataset/delete/[^/]+)$ http://10.61.47.219/$1 + # ProxyPassReverse ^/(dataset/delete/[^/]+)$ http://10.61.47.219/$1 + # ProxyPassMatch ^/(dataset/edit/[^/]+)$ http://10.61.47.219/$1 + # ProxyPassReverse ^/(dataset/edit/[^/]+)$ http://10.61.47.219/$1 + # ProxyPassReverse /dataset http://141.91.184.90/dataset + # ProxyPassReverse /dataset http://141.91.184.90/dataset + # ProxyPass /dataset/new_resource http://10.61.47.219/dataset/new_resource + # ProxyPassReverse /dataset/new_resource http://141.91.184.90/dataset/new_resource + # ProxyPassReverse /dataset/new_resource http://141.91.184.90/dataset/new_resource + # #ProxyPass /api/i18n/de http://141.91.184.90/api/i18n/de + # ProxyPassReverse ^/uploads/group/(.*)$ http://10.61.47.219/uploads/group/$1 + # ProxyPassMatch ^/uploads/group/(.*)$ http://10.61.47.219/uploads/group/$1 + # ProxyPassReverse ^/(dataset/[^/]+/resource/[^/]+/download/[^/]+)$ http://141.91.184.90/$1 + # ProxyPassMatch ^/(dataset/[^/]+/resource/[^/]+/download/[^/]+)$ http://141.91.184.90/$1 + # ProxyPassReverse ^/(dataset/[^/]+/resource/[^/]+)$ http://10.61.47.219/$1 + # ProxyPassMatch ^/(dataset/[^/]+/resource/[^/]+/)$ http://10.61.47.219/$1 + # ProxyPassMatch ^/(dataset/[^/]+/resource_data/[^/]+)$ http://10.61.47.219/$1 + # ProxyPassReverse ^/(dataset/[^/]+/resource_data/[^/]+)$ http://10.61.47.219/$1 + # ProxyPassMatch ^/(dataset/[^/]+/resource_edit/[^/]+)$ http://10.61.47.219/$1 + # ProxyPassReverse ^/(dataset/[^/]+/resource_edit/[^/]+)$ http://10.61.47.219/$1 + # ProxyPassMatch ^/(dataset/[^/]+/resource/[^/]+/new_view[^/]*)$ http://10.61.47.219/$1 + # ProxyPassReverse ^/(dataset/[^/]+/resource/[^/]+/new_view[^/]*)$ http://10.61.47.219/$1 + # ProxyPassMatch ^/(harvest.*)$ http://141.91.184.90/$1 + # ProxyPassReverse /harvest http://141.91.184.90/harvest + # ProxyPass /harvest http://141.91.184.90/harvest + # ProxyPassReverse ^/(harvest.*)$ http://141.91.184.90/$1 + # ProxyPassReverse ^/(api/3/action/package.*)$ http://10.61.47.219/$1 + # ProxyPassMatch ^/(api/3/action/package.*)$ http://10.61.47.219/$1 + # ProxyPass /api/action/package_create http://10.61.47.219/api/action/package_create + # ProxyPassReverse /api/action/package_create http://10.61.47.219/api/action/package_create + # ProxyPass /api/action/resource_create http://10.61.47.219/api/action/resource_create + # ProxyPassReverse /api/action/resource_create http://10.61.47.219/api/action/resource_create + # ProxyPassMatch ^/(organization/edit/[^/]+)$ http://10.61.47.219/$1 + # ProxyPassReverse ^/(organization/edit/[^/]+)$ http://10.61.47.219/$1 + # ProxyPass /organization/new http://<interne-IP-Master>/organization/new + # ProxyPassReverse /organization/new http://<interne-IP-Master>/organization/new + # ProxyPassReverse /organization http://<interne-IP-Master>/organization + # ProxyPassReverse ^/(organization/edit/[^/]+)$ http://<interne-IP-Master>/$1 + + # # ProxyPass /datarequest http://10.61.47.219/datarequest + # # ProxyPassReverse /datarequest http://10.61.47.219/datarequest + # """ + + # expected = self._parse_rules(expexted_rules.splitlines()) + + # # with open('ckan_default.conf', 'r') as aconfig: + # with open('/etc/apache2/sites-enabled/ckan_default.conf', 'r') as aconfig: + # lines = aconfig.readlines() + # # pdb.set_trace() + # current = self._parse_rules(lines, check_host=True) + # if len(expected.symmetric_difference(current)) > 0: + # diff = expected.difference(current) + # if len(diff) > 0: + # print('WARNING: missing routes:') + # for r in sorted(diff, key=lambda tup: tup[1]): + # print(('{cmd} {source} {target}'.format( + # cmd=r[0], source=r[1], target='http://<interne-IP-Master>'+r[2]))) + # diff = current.difference(expected) + # if len(diff) > 0: + # print('WARNING: found unexpected routes:') + # for r in sorted(diff, key=lambda tup: tup[1]): + # print(('{cmd} {source} {target}'.format( + # cmd=r[0], source=r[1], target='<target>'+r[2]))) + + # def _parse_rules(self, lines, check_host=False): + # rules = set(['ProxyPassMatch', 'ProxyPassReverse', 'ProxyPass']) + # ret = [] + # hosts = set() + # for line in lines: + # tokens = [t for t in line.strip().split(' ') if t.strip()] + # if not tokens or tokens[0] not in rules: + # continue + # assert len(tokens) == 3 + # # for token in tokens: + # # print(token) + # f = urlsplit(tokens[2]) + # ret.append((tokens[0], tokens[1], f.path)) + # hosts.add(f.netloc) + # if check_host and len(hosts) > 1: + # print(('WARNING: found multiple target hosts: {hosts}'.format( + # hosts=', '.join(hosts)))) + # return set(ret) diff --git a/ckanext/odsh/tests/test_rdfexport.py b/ckanext/odsh/tests/test_rdfexport.py index 795c767ca8c0fe5a1862c8054aed568403e91934..f288733179dd9201040bd85aea3105b11d519d61 100644 --- a/ckanext/odsh/tests/test_rdfexport.py +++ b/ckanext/odsh/tests/test_rdfexport.py @@ -13,8 +13,6 @@ from ckanext.dcatde.profiles import DCATDE, DCAT, DCATDE_1_0 import pdb -# run with nosetests --ckan --nologcapture --with-pylons=<config to test> ckanext/odsh/tests/test_routes.py - DCAT = Namespace("http://www.w3.org/ns/dcat#") DCT = Namespace("http://purl.org/dc/terms/") diff --git a/ckanext/odsh/tests/test_routes.py b/ckanext/odsh/tests/test_routes.py index 59ddeffc288e9a8234008abce426339972ccb1d2..8e35beda87af8083f449e55db93fa67a07df3c01 100644 --- a/ckanext/odsh/tests/test_routes.py +++ b/ckanext/odsh/tests/test_routes.py @@ -10,7 +10,6 @@ import ckan.config.middleware from routes import url_for webtest_submit = helpers.webtest_submit -# run with nosetests --ckan --nologcapture --with-pylons=<config to test> ckanext/odsh/tests/test_routes.py def _get_test_app(): app = ckan.config.middleware.make_app(config['global_conf'], **config) diff --git a/ckanext/odsh/tests/test_selenium.py b/ckanext/odsh/tests/test_selenium.py index accaea79351b0a11d5ad4fed7c6b9ea69702d528..084e515ba5660ab9665cda186670447007f9d04c 100644 --- a/ckanext/odsh/tests/test_selenium.py +++ b/ckanext/odsh/tests/test_selenium.py @@ -24,7 +24,6 @@ class TestSelenium: @depends(after=test_login) def test_create_dataset(self): TestSelenium.app.got_to_url('/dataset/new?group=') - # assert TestSelenium.app.onMaster() guid = str(uuid.uuid4()) title = 'test_' + guid @@ -66,5 +65,4 @@ class TestSelenium: ] for path in paths: TestSelenium.app.got_to_url(path) - cont = TestSelenium.app.get_slave_flag() - assert cont == '0' + assert TestSelenium.app.is_page_loaded() \ No newline at end of file