Esempio n. 1
0
    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")
Esempio n. 2
0
    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')
Esempio n. 3
0
    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})
Esempio n. 4
0
    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})
Esempio n. 5
0
    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})
Esempio n. 6
0
 def test_containers(self):
     service = Service('db', self.mock_client, 'myproject', image='foo')
     self.mock_client.containers.return_value = []
     self.assertEqual(service.containers(), [])
Esempio n. 7
0
 def test_containers(self):
     service = Service('db', self.mock_client, 'myproject', image='foo')
     self.mock_client.containers.return_value = []
     assert list(service.containers()) == []
Esempio n. 8
0
 def test_containers(self):
     service = Service("db", self.mock_client, "myproject", image="foo")
     self.mock_client.containers.return_value = []
     self.assertEqual(service.containers(), [])
Esempio n. 9
0
 def test_containers(self):
     service = Service('db', self.mock_client, 'myproject', image='foo')
     self.mock_client.containers.return_value = []
     assert list(service.containers()) == []