Merge #409 Translate paths without double slash
This commit is contained in:
commit
c34817989c
@ -36,6 +36,8 @@ def translate_path(compose, path):
|
|||||||
|
|
||||||
for prefix, newvalue in mapping:
|
for prefix, newvalue in mapping:
|
||||||
prefix = os.path.normpath(prefix)
|
prefix = os.path.normpath(prefix)
|
||||||
|
# Strip trailing slashes: the prefix has them stripped by `normpath`.
|
||||||
|
newvalue = newvalue.rstrip('/')
|
||||||
if normpath.startswith(prefix):
|
if normpath.startswith(prefix):
|
||||||
# We can't call os.path.normpath on result since it is not actually
|
# 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.
|
# a path - http:// would get changed to http:/ and so on.
|
||||||
|
@ -39,6 +39,34 @@ class TestNotifier(unittest.TestCase):
|
|||||||
stdin_data=json.dumps(data),
|
stdin_data=json.dumps(data),
|
||||||
can_fail=True, return_stdout=False, workdir='/a/b')
|
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')
|
@mock.patch('kobo.shortcuts.run')
|
||||||
def test_does_not_run_without_config(self, run):
|
def test_does_not_run_without_config(self, run):
|
||||||
n = PungiNotifier(None)
|
n = PungiNotifier(None)
|
||||||
|
Loading…
Reference in New Issue
Block a user