Exemplo n.º 1
0
    def test_v2_download_has_no_stray_output_to_stdout(self):
        """Ensure no stray print statements corrupt the image"""
        saved_stdout = sys.stdout
        try:
            sys.stdout = output = testutils.FakeNoTTYStdout()
            id = image_show_fixture['id']
            headers = {
                'Content-Length': '4',
                'Content-type': 'application/octet-stream'
            }
            fake = testutils.FakeResponse(headers, six.StringIO('DATA'))

            self.requests = self.useFixture(rm_fixture.Fixture())
            self.requests.get('http://example.com/v2/images/%s/file' % id,
                              headers=headers,
                              raw=fake)

            shell = openstack_shell.OpenStackImagesShell()
            argstr = ('--os-image-api-version 2 --os-auth-token faketoken '
                      '--os-image-url http://example.com '
                      'image-download %s' % id)
            shell.main(argstr.split())
            # Ensure we have *only* image data
            self.assertEqual('DATA', output.getvalue())
        finally:
            sys.stdout = saved_stdout
Exemplo n.º 2
0
 def test_log_http_response_with_non_ascii_char(self):
     try:
         response = 'Ok'
         headers = {"Content-Type": "text/plain", "test": "value1\xa5\xa6"}
         fake = utils.FakeResponse(headers, six.StringIO(response))
         self.client.log_http_response(fake)
     except UnicodeDecodeError as e:
         self.fail("Unexpected UnicodeDecodeError exception '%s'" % e)
Exemplo n.º 3
0
    def test_download_has_no_stray_output_to_stdout(self):
        """Regression test for bug 1488914"""
        saved_stdout = sys.stdout
        try:
            sys.stdout = output = testutils.FakeNoTTYStdout()
            id = image_show_fixture['id']
            self.requests = self.useFixture(rm_fixture.Fixture())
            self.requests.get('http://example.com/versions',
                              json=image_versions_fixture)

            headers = {
                'Content-Length': '4',
                'Content-type': 'application/octet-stream'
            }
            fake = testutils.FakeResponse(headers, six.StringIO('DATA'))
            self.requests.get('http://example.com/v1/images/%s' % id, raw=fake)

            self.requests.get('http://example.com/v1/images/detail'
                              '?sort_key=name&sort_dir=asc&limit=20')

            headers = {'X-Image-Meta-Id': id}
            self.requests.head('http://example.com/v1/images/%s' % id,
                               headers=headers)

            with mock.patch.object(openstack_shell.OpenStackImagesShell,
                                   '_cache_schemas') as mocked_cache_schema:
                mocked_cache_schema.return_value = True
                shell = openstack_shell.OpenStackImagesShell()
                argstr = ('--os-auth-token faketoken '
                          '--os-image-url http://example.com '
                          'image-download %s' % id)
                shell.main(argstr.split())
                self.assertTrue(mocked_cache_schema.called)
            # Ensure we have *only* image data
            self.assertEqual('DATA', output.getvalue())
        finally:
            sys.stdout = saved_stdout
Exemplo n.º 4
0
 def test_download_no_data(self):
     resp = utils.FakeResponse(headers={}, status_code=204)
     self.controller.http_client.get = mock.Mock(return_value=(resp, None))
     body = self.controller.data('image_id')
     self.assertIsNone(body)
Exemplo n.º 5
0
 def get(self, url, **kwargs):
     self.url = url
     return utils.FakeResponse({}), ParameterFakeAPI.image_list