aboutsummaryrefslogtreecommitdiffstats
path: root/setuptools/tests
diff options
context:
space:
mode:
authorPaul Ganssle <paul@ganssle.io>2018-11-07 17:15:22 -0500
committerPaul Ganssle <paul@ganssle.io>2018-11-07 17:38:42 -0500
commitdfe1b3afb433c7e1d0679c005407ac12104e6141 (patch)
treead3c854c1609075c4d28a56728a8b8e152284506 /setuptools/tests
parentbef22678626f4e201ef1bb6c5bc753dd01e6bf5a (diff)
downloadexternal_python_setuptools-dfe1b3afb433c7e1d0679c005407ac12104e6141.tar.gz
external_python_setuptools-dfe1b3afb433c7e1d0679c005407ac12104e6141.tar.bz2
external_python_setuptools-dfe1b3afb433c7e1d0679c005407ac12104e6141.zip
Add upload fixture
This is a fixture to create an upload command with a patched version of urlopen so that no HTTP queries are sent.
Diffstat (limited to 'setuptools/tests')
-rw-r--r--setuptools/tests/test_upload.py45
1 files changed, 45 insertions, 0 deletions
diff --git a/setuptools/tests/test_upload.py b/setuptools/tests/test_upload.py
index b18f83c8..1b70301b 100644
--- a/setuptools/tests/test_upload.py
+++ b/setuptools/tests/test_upload.py
@@ -32,6 +32,51 @@ def _parse_upload_body(body):
return entries
+@pytest.fixture
+def patched_upload(tmpdir):
+ class Fix:
+ def __init__(self, cmd, urlopen):
+ self.cmd = cmd
+ self.urlopen = urlopen
+
+ def __iter__(self):
+ return iter((self.cmd, self.urlopen))
+
+ def get_uploaded_metadata(self):
+ request = self.urlopen.call_args_list[0][0][0]
+ body = request.data.decode('utf-8')
+ entries = dict(_parse_upload_body(body))
+
+ return entries
+
+ class ResponseMock(mock.Mock):
+ def getheader(self, name, default=None):
+ """Mocked getheader method for response object"""
+ return {
+ 'content-type': 'text/plain; charset=utf-8',
+ }.get(name.lower(), default)
+
+ with mock.patch('setuptools.command.upload.urlopen') as urlopen:
+ urlopen.return_value = ResponseMock()
+ urlopen.return_value.getcode.return_value = 200
+ urlopen.return_value.read.return_value = b''
+
+ content = os.path.join(str(tmpdir), "content_data")
+
+ with open(content, 'w') as f:
+ f.write("Some content")
+
+ dist = Distribution()
+ dist.dist_files = [('sdist', '3.7.0', content)]
+
+ cmd = upload(dist)
+ cmd.announce = mock.Mock()
+ cmd.username = 'user'
+ cmd.password = 'hunter2'
+
+ yield Fix(cmd, urlopen)
+
+
class TestUploadTest:
@mock.patch('setuptools.command.upload.urlopen')
def test_upload_metadata(self, patch, tmpdir):