Преглед изворни кода

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

Signed-off-by: Joffrey F <[email protected]>
Joffrey F пре 7 година
родитељ
комит
187f48e338
2 измењених фајлова са 10 додато и 1 уклоњено
  1. 2 0
      compose/container.py
  2. 8 1
      tests/unit/container_test.py

+ 2 - 0
compose/container.py

@@ -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

+ 8 - 1
tests/unit/container_test.py

@@ -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"))