Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docker/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def _convert_port_binding(binding):
if result['HostPort'] is None:
result['HostPort'] = ''
else:
result['HostPort'] = str(result['HostPort'])
result['HostPort'] = str(int(result['HostPort']))

return result

Expand Down
41 changes: 41 additions & 0 deletions tests/test_util.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import unittest

from docker.utils import convert_port_bindings

class UtilsTest(unittest.TestCase):
def test_convert_port_binding_with_dict(self):
"""
Ensure the port binding raises an exception if the value is clearly unexpected
"""
binding = [{
'HostIp': '0.0.0.0',
'HostPort': '4000',
}]

bindings = {
'80': binding,
}

self.assertRaises(TypeError, convert_port_bindings, bindings)

def test_convert_port_binding_with_non_int_string(self):
"""
Ensure the port binding raises an exception if the value is clearly unexpected
"""
binding = ['hi']

bindings = {
'80': binding,
}

self.assertRaises(ValueError, convert_port_bindings, bindings)

def test_convert_port_binding_just_port_number(self):
binding = '4000'
bindings = {
'80': binding,
}

converted = convert_port_bindings(bindings)

self.assertEqual(binding, converted.values()[0][0]['HostPort'])