Merge #409 `Translate paths without double slash`

This commit is contained in:
Dennis Gilmore 2016-09-27 13:31:44 +00:00
commit c34817989c
2 changed files with 30 additions and 0 deletions

View File

@ -36,6 +36,8 @@ def translate_path(compose, path):
for prefix, newvalue in mapping:
prefix = os.path.normpath(prefix)
# Strip trailing slashes: the prefix has them stripped by `normpath`.
newvalue = newvalue.rstrip('/')
if normpath.startswith(prefix):
# We can't call os.path.normpath on result since it is not actually
# a path - http:// would get changed to http:/ and so on.

View File

@ -39,6 +39,34 @@ class TestNotifier(unittest.TestCase):
stdin_data=json.dumps(data),
can_fail=True, return_stdout=False, workdir='/a/b')
@mock.patch('kobo.shortcuts.run')
def test_translates_path(self, run):
compose = mock.Mock(
compose_id='COMPOSE_ID',
paths=mock.Mock(
compose=mock.Mock(
topdir=mock.Mock(return_value='/root/a/b')
)
),
conf={
"translate_paths": [("/root/", "http://example.com/compose/")],
}
)
run.return_value = (0, None)
n = PungiNotifier('run-notify')
n.compose = compose
data = {'foo': 'bar', 'baz': 'quux'}
n.send('cmd', **data)
data['compose_id'] = 'COMPOSE_ID'
data['location'] = 'http://example.com/compose/a/b'
run.assert_called_once_with(('run-notify', 'cmd'),
stdin_data=json.dumps(data),
can_fail=True, return_stdout=False,
workdir='/root/a/b')
@mock.patch('kobo.shortcuts.run')
def test_does_not_run_without_config(self, run):
n = PungiNotifier(None)