Don't attempt to truncate a None value in Container.slug

Signed-off-by: Joffrey F <joffrey@docker.com>
This commit is contained in:
Joffrey F 2018-10-31 13:55:20 -07:00
parent a7ca78d854
commit 187f48e338
2 changed files with 10 additions and 1 deletions

View File

@ -96,6 +96,8 @@ class Container(object):
@property
def slug(self):
if not self.full_slug:
return None
return truncate_id(self.full_slug)
@property

View File

@ -5,6 +5,7 @@ import docker
from .. import mock
from .. import unittest
from compose.const import LABEL_SLUG
from compose.container import Container
from compose.container import get_container_name
@ -87,7 +88,7 @@ class ContainerTest(unittest.TestCase):
assert container.name == "composetest_db_1"
def test_name_without_project(self):
self.container_dict['Name'] = "/composetest_web_7"
self.container_dict['Name'] = "/composetest_web_7_092cd63296fd"
container = Container(None, self.container_dict, has_been_inspected=True)
assert container.name_without_project == "web_7_092cd63296fd"
@ -96,6 +97,12 @@ class ContainerTest(unittest.TestCase):
container = Container(None, self.container_dict, has_been_inspected=True)
assert container.name_without_project == "custom_name_of_container"
def test_name_without_project_noslug(self):
self.container_dict['Name'] = "/composetest_web_7"
del self.container_dict['Config']['Labels'][LABEL_SLUG]
container = Container(None, self.container_dict, has_been_inspected=True)
assert container.name_without_project == 'web_7'
def test_inspect_if_not_inspected(self):
mock_client = mock.create_autospec(docker.APIClient)
container = Container(mock_client, dict(Id="the_id"))