jeanphix / Ghost.py

Webkit based scriptable web browser for python.
http://ghost-py.readthedocs.org/en/latest/
2.77k stars 380 forks source link

Upload test fails (unittest test_set_field_value_simple_file_field) #202

Open ghost opened 9 years ago

ghost commented 9 years ago

On Debian 7 (wheezy) with PySide 1.1.1 the test works, on Debian 8 (jessie) with PySide 1.2.2 the test fails.

ghost commented 9 years ago

Not beautiful, but this seems to work:

    def test_set_field_value_simple_file_field(self):
        import mimetypes
        import random
        import string
        filename = 'blackhat.jpg'
        upload = os.path.join(os.path.dirname(__file__), 'static', filename)
        filetype = mimetypes.guess_type(upload)[0] or 'application/octet-stream'
        boundary = '-' * 27 + ''.join(random.choice(string.digits) for _ in range(29))
        content = ''
        with open(upload) as f:
            content = f.read()
        body = '\n'.join(['--' + boundary,
                          'Content-Disposition: form-data; name="simple-file"; filename="%s"' % filename,
                          'Content-Type: %s' % filetype,
                          '',
                          content,
                          '--' + boundary + '--'])
        headers = {'Content-Type': 'multipart/form-data;boundary=' + boundary,
                   'Content-Length': str(len(body))}
        self.ghost.open("%supload" % base_url, method='post', body=body, headers=headers)
        file_path = os.path.join(
            os.path.dirname(__file__), 'uploaded_' + filename)
        self.assertTrue(os.path.isfile(file_path))
        os.remove(file_path)
davidhrbac commented 9 years ago

This does not work too. Ubuntu 14.04:

In [11]: ghost.__version__
Out[11]: '0.1.1'

In [12]: PySide.__version__
Out[12]: '1.2.1'