mirror of https://github.com/docker/docker-py.git
Allow container name property from sparse list
When listing containers with `sparse=True` the container's name property does not work because there is no 'Name' attribue on the object returned by the Docker API. Instead the name is in the 'Names' attribute. Signed-off-by: Stuart Thomson <stuartwthomson@live.co.uk>
This commit is contained in:
parent
b4beaaac8c
commit
290ee89a8c
|
@ -28,6 +28,8 @@ class Container(Model):
|
|||
"""
|
||||
if self.attrs.get('Name') is not None:
|
||||
return self.attrs['Name'].lstrip('/')
|
||||
if self.attrs.get('Names') is not None:
|
||||
return self.attrs['Names'][0].lstrip('/')
|
||||
|
||||
@property
|
||||
def image(self):
|
||||
|
|
|
@ -210,7 +210,7 @@ class ContainerCollectionTest(BaseIntegrationTest):
|
|||
def test_list_sparse(self):
|
||||
client = docker.from_env(version=TEST_API_VERSION)
|
||||
container_id = client.containers.run(
|
||||
"alpine", "sleep 300", detach=True).id
|
||||
"alpine", "sleep 300", detach=True, name='a_container').id
|
||||
self.tmp_containers.append(container_id)
|
||||
containers = [c for c in client.containers.list(sparse=True) if c.id ==
|
||||
container_id]
|
||||
|
@ -220,6 +220,7 @@ class ContainerCollectionTest(BaseIntegrationTest):
|
|||
assert container.attrs['Image'] == 'alpine'
|
||||
assert container.status == 'running'
|
||||
assert container.image == client.images.get('alpine')
|
||||
assert container.name == 'a_container'
|
||||
with pytest.raises(docker.errors.DockerException):
|
||||
container.labels
|
||||
|
||||
|
|
Loading…
Reference in New Issue