Skip to content
Snippets Groups Projects
Commit adc6ba89 authored by anonymous's avatar anonymous
Browse files

add version check

parent d4bfc397
No related branches found
No related tags found
No related merge requests found
...@@ -14,6 +14,7 @@ import hashlib ...@@ -14,6 +14,7 @@ import hashlib
import re import re
from ckan.common import request from ckan.common import request
from urlparse import urlsplit, urlunsplit from urlparse import urlsplit, urlunsplit
import subprocess
get_action = logic.get_action get_action = logic.get_action
...@@ -225,3 +226,9 @@ def odsh_public_resource_url(res): ...@@ -225,3 +226,9 @@ def odsh_public_resource_url(res):
return urlunsplit((0, 0, f[2], f[3], f[4])) return urlunsplit((0, 0, f[2], f[3], f[4]))
else: else:
return res['url'] return res['url']
def odsh_get_version_id():
try:
return subprocess.check_output(["git", "rev-parse", "HEAD"]).strip()
except:
return 'unknown'
...@@ -290,7 +290,8 @@ class OdshPlugin(plugins.SingletonPlugin, DefaultTranslation, DefaultDatasetForm ...@@ -290,7 +290,8 @@ class OdshPlugin(plugins.SingletonPlugin, DefaultTranslation, DefaultDatasetForm
'odsh_tracking_url': odsh_helpers.odsh_tracking_url, 'odsh_tracking_url': odsh_helpers.odsh_tracking_url,
'odsh_has_more_facets': odsh_helpers.odsh_has_more_facets, 'odsh_has_more_facets': odsh_helpers.odsh_has_more_facets,
'odsh_public_url': odsh_helpers.odsh_public_url, 'odsh_public_url': odsh_helpers.odsh_public_url,
'odsh_public_resource_url': odsh_helpers.odsh_public_resource_url 'odsh_public_resource_url': odsh_helpers.odsh_public_resource_url,
'odsh_get_version_id': odsh_helpers.odsh_get_version_id
} }
def after_map(self, map): def after_map(self, map):
......
{{ h.odsh_get_version_id()}}
\ No newline at end of file
...@@ -9,6 +9,8 @@ import sys ...@@ -9,6 +9,8 @@ import sys
import ConfigParser import ConfigParser
from collections import OrderedDict from collections import OrderedDict
expected_commit = '5298c6f4b86b1a03fbf177974e3ab4eefb1b1192'
# run with nosetests --ckan --nologcapture --with-pylons=<config to test> ckanext/odsh/tests/test_env.py # run with nosetests --ckan --nologcapture --with-pylons=<config to test> ckanext/odsh/tests/test_env.py
...@@ -23,12 +25,16 @@ def checkConfig(key, expected=None, minLength=None): ...@@ -23,12 +25,16 @@ def checkConfig(key, expected=None, minLength=None):
return value return value
def checkConfigUrl(key, expectedKey=None, responseContains=None): def readUrl(value):
value = checkConfig(key, expected=expectedKey)
req = urllib2.Request(value) req = urllib2.Request(value)
response = urllib2.urlopen(req) response = urllib2.urlopen(req)
data = response.read() data = response.read()
return data
def checkConfigUrl(key, expectedKey=None, responseContains=None):
value = checkConfig(key, expected=expectedKey)
data = readUrl(value)
if responseContains: if responseContains:
assert responseContains in data assert responseContains in data
...@@ -156,3 +162,10 @@ class TestEnv: ...@@ -156,3 +162,10 @@ class TestEnv:
checkConfig('ckanext.odsh.matomo_id', expected='3') checkConfig('ckanext.odsh.matomo_id', expected='3')
checkConfigUrl('ckanext.odsh.matomo_url', checkConfigUrl('ckanext.odsh.matomo_url',
responseContains='This resource is part of Matomo') responseContains='This resource is part of Matomo')
def test_version(self):
url = checkConfig('ckan.site_url')
if url[-1] == '/':
url = url[:-1]
version = readUrl(url+'/qv4yAI2rgotamXGk98gJ').strip()
assert version == expected_commit, "wrong version: {was}!={exp}".format(version, expected_commit)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment