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

add version check

parent d4bfc397
Branches
Tags
No related merge requests found
......@@ -14,6 +14,7 @@ import hashlib
import re
from ckan.common import request
from urlparse import urlsplit, urlunsplit
import subprocess
get_action = logic.get_action
......@@ -225,3 +226,9 @@ def odsh_public_resource_url(res):
return urlunsplit((0, 0, f[2], f[3], f[4]))
else:
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
'odsh_tracking_url': odsh_helpers.odsh_tracking_url,
'odsh_has_more_facets': odsh_helpers.odsh_has_more_facets,
'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):
......
{{ h.odsh_get_version_id()}}
\ No newline at end of file
......@@ -9,6 +9,8 @@ import sys
import ConfigParser
from collections import OrderedDict
expected_commit = '5298c6f4b86b1a03fbf177974e3ab4eefb1b1192'
# 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):
return value
def checkConfigUrl(key, expectedKey=None, responseContains=None):
value = checkConfig(key, expected=expectedKey)
def readUrl(value):
req = urllib2.Request(value)
response = urllib2.urlopen(req)
data = response.read()
return data
def checkConfigUrl(key, expectedKey=None, responseContains=None):
value = checkConfig(key, expected=expectedKey)
data = readUrl(value)
if responseContains:
assert responseContains in data
......@@ -156,3 +162,10 @@ class TestEnv:
checkConfig('ckanext.odsh.matomo_id', expected='3')
checkConfigUrl('ckanext.odsh.matomo_url',
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