def test_container_without_name(self): self.mock_client.containers.return_value = [ {"Image": "foo", "Id": "1", "Name": "1"}, {"Image": "foo", "Id": "2", "Name": None}, {"Image": "foo", "Id": "3"}, ] service = Service("db", self.mock_client, "myproject", image="foo") self.assertEqual([c.id for c in service.containers()], ["1"]) self.assertEqual(service._next_container_number(), 2) self.assertEqual(service.get_container(1).id, "1")
def test_container_without_name(self): self.mock_client.containers.return_value = [ {'Image': 'foo', 'Id': '1', 'Name': '1'}, {'Image': 'foo', 'Id': '2', 'Name': None}, {'Image': 'foo', 'Id': '3'}, ] service = Service('db', self.mock_client, 'myproject', image='foo') self.assertEqual([c.id for c in service.containers()], ['1']) self.assertEqual(service._next_container_number(), 2) self.assertEqual(service.get_container(1).id, '1')
def test_containers_with_containers(self): self.mock_client.containers.return_value = [dict(Name=str(i), Image="foo", Id=i) for i in range(3)] service = Service("db", self.mock_client, "myproject", image="foo") self.assertEqual([c.id for c in service.containers()], range(3)) expected_labels = [ "{0}=myproject".format(LABEL_PROJECT), "{0}=db".format(LABEL_SERVICE), "{0}=False".format(LABEL_ONE_OFF), ] self.mock_client.containers.assert_called_once_with(all=False, filters={"label": expected_labels})
def test_containers_with_containers(self): self.mock_client.containers.return_value = [ dict(Name=str(i), Image='foo', Id=i) for i in range(3) ] service = Service('db', self.mock_client, 'myproject', image='foo') self.assertEqual([c.id for c in service.containers()], list(range(3))) expected_labels = [ '{0}=myproject'.format(LABEL_PROJECT), '{0}=db'.format(LABEL_SERVICE), '{0}=False'.format(LABEL_ONE_OFF), ] self.mock_client.containers.assert_called_once_with( all=False, filters={'label': expected_labels})
def test_containers_with_containers(self): self.mock_client.containers.return_value = [ dict(Name=str(i), Image='foo', Id=i) for i in range(3) ] service = Service('db', self.mock_client, 'myproject', image='foo') self.assertEqual([c.id for c in service.containers()], range(3)) expected_labels = [ '{0}=myproject'.format(LABEL_PROJECT), '{0}=db'.format(LABEL_SERVICE), '{0}=False'.format(LABEL_ONE_OFF), ] self.mock_client.containers.assert_called_once_with( all=False, filters={'label': expected_labels})
def test_containers(self): service = Service('db', self.mock_client, 'myproject', image='foo') self.mock_client.containers.return_value = [] self.assertEqual(service.containers(), [])
def test_containers(self): service = Service('db', self.mock_client, 'myproject', image='foo') self.mock_client.containers.return_value = [] assert list(service.containers()) == []
def test_containers(self): service = Service("db", self.mock_client, "myproject", image="foo") self.mock_client.containers.return_value = [] self.assertEqual(service.containers(), [])