Example #1
0
    def test_create_container_no_build(self):
        self.mock_client.images.return_value = []
        service = Service('foo', client=self.mock_client, build='.')
        service.create_container(do_build=False)

        self.assertFalse(self.mock_client.images.called)
        self.assertFalse(self.mock_client.build.called)
Example #2
0
    def test_create_container_with_build(self):
        self.mock_client.images.return_value = []
        service = Service('foo', client=self.mock_client, build='.')
        service.build = mock.create_autospec(service.build)
        service.create_container(do_build=True)

        self.mock_client.images.assert_called_once_with(name=service.full_name)
        service.build.assert_called_once_with()
Example #3
0
 def test_create_container_from_insecure_registry(self, mock_log):
     service = Service("foo", client=self.mock_client, image="someimage:sometag")
     mock_response = mock.Mock(Response)
     mock_response.status_code = 404
     mock_response.reason = "Not Found"
     Container.create = mock.Mock()
     Container.create.side_effect = APIError("Mock error", mock_response, "No such image")
     try:
         service.create_container(insecure_registry=True)
     except APIError:  # We expect the APIError because our service requires a non-existent image.
         pass
     self.mock_client.pull.assert_called_once_with("someimage:sometag", insecure_registry=True, stream=True)
     mock_log.info.assert_called_once_with("Pulling image someimage:sometag...")
Example #4
0
 def test_create_container_from_insecure_registry(self, mock_log):
     service = Service('foo', client=self.mock_client, image='someimage:sometag')
     mock_response = mock.Mock(Response)
     mock_response.status_code = 404
     mock_response.reason = "Not Found"
     Container.create = mock.Mock()
     Container.create.side_effect = APIError('Mock error', mock_response, "No such image")
     try:
         service.create_container(insecure_registry=True)
     except APIError:  # We expect the APIError because our service requires a non-existent image.
         pass
     self.mock_client.pull.assert_called_once_with('someimage:sometag', insecure_registry=True, stream=True)
     mock_log.info.assert_called_once_with('Pulling image someimage:sometag...')
Example #5
0
    def test_create_container_from_insecure_registry(
            self,
            mock_log,
            mock_container):
        service = Service('foo', client=self.mock_client, image='someimage:sometag')
        mock_response = mock.Mock(Response)
        mock_response.status_code = 404
        mock_response.reason = "Not Found"
        mock_container.create.side_effect = APIError(
            'Mock error', mock_response, "No such image")

        # We expect the APIError because our service requires a
        # non-existent image.
        with self.assertRaises(APIError):
            service.create_container(insecure_registry=True)

        self.mock_client.pull.assert_called_once_with(
            'someimage:sometag',
            insecure_registry=True,
            stream=True)
        mock_log.info.assert_called_once_with(
            'Pulling image someimage:sometag...')
Example #6
0
 def test_latest_is_used_when_tag_is_not_specified(self):
     service = Service('foo', client=self.mock_client, image='someimage')
     Container.create = mock.Mock()
     service.create_container()
     self.assertEqual(Container.create.call_args[1]['image'], 'someimage:latest')
Example #7
0
 def test_latest_is_used_when_tag_is_not_specified(self):
     service = Service("foo", client=self.mock_client, image="someimage")
     Container.create = mock.Mock()
     service.create_container()
     self.assertEqual(Container.create.call_args[1]["image"], "someimage:latest")
Example #8
0
 def test_latest_is_used_when_tag_is_not_specified(self):
     service = Service('foo', client=self.mock_client, image='someimage')
     Container.create = mock.Mock()
     service.create_container()
     self.assertEqual(Container.create.call_args[1]['image'],
                      'someimage:latest')