mirror of https://github.com/docker/docker-py.git
				
				
				
			Fix joining of unicode and byte strings in python3.
Check logs response in unit tests, and fix log integration tests for py3.
This commit is contained in:
		
							parent
							
								
									3dd8d9eb90
								
							
						
					
					
						commit
						d34b78aac5
					
				| 
						 | 
					@ -250,7 +250,7 @@ class Client(requests.Session):
 | 
				
			||||||
            start = walker + STREAM_HEADER_SIZE_BYTES
 | 
					            start = walker + STREAM_HEADER_SIZE_BYTES
 | 
				
			||||||
            end = start + length
 | 
					            end = start + length
 | 
				
			||||||
            walker = end
 | 
					            walker = end
 | 
				
			||||||
            yield str(buf[start:end])
 | 
					            yield buf[start:end]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def _multiplexed_socket_stream_helper(self, response):
 | 
					    def _multiplexed_socket_stream_helper(self, response):
 | 
				
			||||||
        """A generator of multiplexed data blocks coming from a response
 | 
					        """A generator of multiplexed data blocks coming from a response
 | 
				
			||||||
| 
						 | 
					@ -311,8 +311,10 @@ class Client(requests.Session):
 | 
				
			||||||
            return stream_result() if stream else \
 | 
					            return stream_result() if stream else \
 | 
				
			||||||
                self._result(response, binary=True)
 | 
					                self._result(response, binary=True)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        sep = bytes() if six.PY3 else str()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return stream and self._multiplexed_socket_stream_helper(response) or \
 | 
					        return stream and self._multiplexed_socket_stream_helper(response) or \
 | 
				
			||||||
            ''.join([x for x in self._multiplexed_buffer_helper(response)])
 | 
					            sep.join([x for x in self._multiplexed_buffer_helper(response)])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def attach_socket(self, container, params=None, ws=False):
 | 
					    def attach_socket(self, container, params=None, ws=False):
 | 
				
			||||||
        if params is None:
 | 
					        if params is None:
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -202,7 +202,8 @@ def get_fake_wait():
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def get_fake_logs():
 | 
					def get_fake_logs():
 | 
				
			||||||
    status_code = 200
 | 
					    status_code = 200
 | 
				
			||||||
    response = 'Flowering Nights (Sakuya Iyazoi)'
 | 
					    response = (b'\x01\x00\x00\x00\x00\x00\x00\x11Flowering Nights\n'
 | 
				
			||||||
 | 
					                b'\x01\x00\x00\x00\x00\x00\x00\x10(Sakuya Iyazoi)\n')
 | 
				
			||||||
    return status_code, response
 | 
					    return status_code, response
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -278,7 +278,7 @@ class TestLogs(BaseTestCase):
 | 
				
			||||||
        exitcode = self.client.wait(id)
 | 
					        exitcode = self.client.wait(id)
 | 
				
			||||||
        self.assertEqual(exitcode, 0)
 | 
					        self.assertEqual(exitcode, 0)
 | 
				
			||||||
        logs = self.client.logs(id)
 | 
					        logs = self.client.logs(id)
 | 
				
			||||||
        self.assertEqual(logs, snippet + '\n')
 | 
					        self.assertEqual(logs, (snippet + '\n').encode(encoding='ascii'))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class TestLogsStreaming(BaseTestCase):
 | 
					class TestLogsStreaming(BaseTestCase):
 | 
				
			||||||
| 
						 | 
					@ -290,14 +290,14 @@ class TestLogsStreaming(BaseTestCase):
 | 
				
			||||||
        id = container['Id']
 | 
					        id = container['Id']
 | 
				
			||||||
        self.client.start(id)
 | 
					        self.client.start(id)
 | 
				
			||||||
        self.tmp_containers.append(id)
 | 
					        self.tmp_containers.append(id)
 | 
				
			||||||
        logs = ''
 | 
					        logs = bytes() if six.PY3 else str()
 | 
				
			||||||
        for chunk in self.client.logs(id, stream=True):
 | 
					        for chunk in self.client.logs(id, stream=True):
 | 
				
			||||||
            logs += chunk
 | 
					            logs += chunk
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        exitcode = self.client.wait(id)
 | 
					        exitcode = self.client.wait(id)
 | 
				
			||||||
        self.assertEqual(exitcode, 0)
 | 
					        self.assertEqual(exitcode, 0)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        self.assertEqual(logs, snippet + '\n')
 | 
					        self.assertEqual(logs, (snippet + '\n').encode(encoding='ascii'))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class TestLogsWithDictInsteadOfId(BaseTestCase):
 | 
					class TestLogsWithDictInsteadOfId(BaseTestCase):
 | 
				
			||||||
| 
						 | 
					@ -312,7 +312,7 @@ class TestLogsWithDictInsteadOfId(BaseTestCase):
 | 
				
			||||||
        exitcode = self.client.wait(id)
 | 
					        exitcode = self.client.wait(id)
 | 
				
			||||||
        self.assertEqual(exitcode, 0)
 | 
					        self.assertEqual(exitcode, 0)
 | 
				
			||||||
        logs = self.client.logs(container)
 | 
					        logs = self.client.logs(container)
 | 
				
			||||||
        self.assertEqual(logs, snippet + '\n')
 | 
					        self.assertEqual(logs, (snippet + '\n').encode(encoding='ascii'))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class TestDiff(BaseTestCase):
 | 
					class TestDiff(BaseTestCase):
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -39,10 +39,8 @@ def response(status_code=200, content='', headers=None, reason=None, elapsed=0,
 | 
				
			||||||
             request=None):
 | 
					             request=None):
 | 
				
			||||||
    res = requests.Response()
 | 
					    res = requests.Response()
 | 
				
			||||||
    res.status_code = status_code
 | 
					    res.status_code = status_code
 | 
				
			||||||
    if not isinstance(content, six.string_types):
 | 
					    if not isinstance(content, six.binary_type):
 | 
				
			||||||
        content = json.dumps(content)
 | 
					        content = json.dumps(content).encode('ascii')
 | 
				
			||||||
    if six.PY3:
 | 
					 | 
				
			||||||
        content = content.encode('ascii')
 | 
					 | 
				
			||||||
    res._content = content
 | 
					    res._content = content
 | 
				
			||||||
    res.headers = requests.structures.CaseInsensitiveDict(headers or {})
 | 
					    res.headers = requests.structures.CaseInsensitiveDict(headers or {})
 | 
				
			||||||
    res.reason = reason
 | 
					    res.reason = reason
 | 
				
			||||||
| 
						 | 
					@ -737,7 +735,7 @@ class DockerClientTest(unittest.TestCase):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_logs(self):
 | 
					    def test_logs(self):
 | 
				
			||||||
        try:
 | 
					        try:
 | 
				
			||||||
            self.client.logs(fake_api.FAKE_CONTAINER_ID)
 | 
					            logs = self.client.logs(fake_api.FAKE_CONTAINER_ID)
 | 
				
			||||||
        except Exception as e:
 | 
					        except Exception as e:
 | 
				
			||||||
            self.fail('Command should not raise exception: {0}'.format(e))
 | 
					            self.fail('Command should not raise exception: {0}'.format(e))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -748,9 +746,14 @@ class DockerClientTest(unittest.TestCase):
 | 
				
			||||||
            stream=False
 | 
					            stream=False
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        self.assertEqual(
 | 
				
			||||||
 | 
					            logs,
 | 
				
			||||||
 | 
					            'Flowering Nights\n(Sakuya Iyazoi)\n'.encode('ascii')
 | 
				
			||||||
 | 
					        )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_logs_with_dict_instead_of_id(self):
 | 
					    def test_logs_with_dict_instead_of_id(self):
 | 
				
			||||||
        try:
 | 
					        try:
 | 
				
			||||||
            self.client.logs({'Id': fake_api.FAKE_CONTAINER_ID})
 | 
					            logs = self.client.logs({'Id': fake_api.FAKE_CONTAINER_ID})
 | 
				
			||||||
        except Exception as e:
 | 
					        except Exception as e:
 | 
				
			||||||
            self.fail('Command should not raise exception: {0}'.format(e))
 | 
					            self.fail('Command should not raise exception: {0}'.format(e))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -761,6 +764,11 @@ class DockerClientTest(unittest.TestCase):
 | 
				
			||||||
            stream=False
 | 
					            stream=False
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        self.assertEqual(
 | 
				
			||||||
 | 
					            logs,
 | 
				
			||||||
 | 
					            'Flowering Nights\n(Sakuya Iyazoi)\n'.encode('ascii')
 | 
				
			||||||
 | 
					        )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_log_streaming(self):
 | 
					    def test_log_streaming(self):
 | 
				
			||||||
        try:
 | 
					        try:
 | 
				
			||||||
            self.client.logs(fake_api.FAKE_CONTAINER_ID, stream=True)
 | 
					            self.client.logs(fake_api.FAKE_CONTAINER_ID, stream=True)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue