Commit b7a6d8ad authored by Paul Ganssle's avatar Paul Ganssle

Add failing test for issue #1381

parent 83fb2385
import mock import mock
import os
import re
from distutils import log from distutils import log
from distutils.version import StrictVersion
import pytest import pytest
import six
from setuptools.command.upload import upload from setuptools.command.upload import upload
from setuptools.dist import Distribution from setuptools.dist import Distribution
def _parse_upload_body(body):
boundary = u'\r\n----------------GHSKFJDLGDS7543FJKLFHRE75642756743254'
entries = []
name_re = re.compile(u'^Content-Disposition: form-data; name="([^\"]+)"')
for entry in body.split(boundary):
pair = entry.split(u'\r\n\r\n')
if not len(pair) == 2:
continue
key, value = map(six.text_type.strip, pair)
m = name_re.match(key)
if m is not None:
key = m.group(1)
entries.append((key, value))
return entries
class TestUploadTest: class TestUploadTest:
@pytest.mark.xfail(reason='Issue #1381')
@mock.patch('setuptools.command.upload.urlopen')
def test_upload_metadata(self, patch, tmpdir):
dist = Distribution()
dist.metadata.metadata_version = StrictVersion('2.1')
content = os.path.join(str(tmpdir), "test_upload_metadata_content")
with open(content, 'w') as f:
f.write("Some content")
dist.dist_files = [('xxx', '3.7', content)]
patch.return_value = mock.Mock()
patch.return_value.getcode.return_value = 200
cmd = upload(dist)
cmd.announce = mock.Mock()
cmd.username = 'user'
cmd.password = 'hunter2'
cmd.ensure_finalized()
cmd.run()
# Make sure we did the upload
patch.assert_called_once()
# Make sure the metadata version is correct in the headers
request = patch.call_args_list[0][0][0]
body = request.data.decode('utf-8')
entries = dict(_parse_upload_body(body))
assert entries['metadata_version'] == '2.1'
def test_warns_deprecation(self): def test_warns_deprecation(self):
dist = Distribution() dist = Distribution()
dist.dist_files = [(mock.Mock(), mock.Mock(), mock.Mock())] dist.dist_files = [(mock.Mock(), mock.Mock(), mock.Mock())]
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment