Skip to content

Commit

Permalink
Merge pull request pyinstaller#151 from rbranche/hook-requests
Browse files Browse the repository at this point in the history
Add test for requests library.
  • Loading branch information
matysek committed Jan 16, 2015
2 parents 289636f + 24cf324 commit 707e2e6
Show file tree
Hide file tree
Showing 5 changed files with 131 additions and 0 deletions.
65 changes: 65 additions & 0 deletions tests/libraries/test_requests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# -----------------------------------------------------------------------------
# Copyright (c) 2014, PyInstaller Development Team.
#
# Distributed under the terms of the GNU General Public License with exception
# for distributing bootloader.
#
# The full license is in the file COPYING.txt, distributed with this software.
# -----------------------------------------------------------------------------

import BaseHTTPServer
import SimpleHTTPServer

import os
import ssl
import sys
import threading
import time

import requests

"""
Note: to re-create the test_requests_server.pem file use the
following commands.
cd /path/to/pyinstaller.git/tests/libraries
openssl req -new -x509 -keyout test_requests_server.pem \
-out test_requests_server.pem -days 365 \
-nodes -config test_requests_openssl.conf
"""


SERVER_PORT = 8443
SERVER_CERT = os.path.join(
os.path.dirname(sys.executable),
u"test_requests_server.pem")


def ssl_server():
# SSL server copied from here:
# http://www.piware.de/2011/01/creating-an-https-server-in-python/
httpd = BaseHTTPServer.HTTPServer(
('localhost', SERVER_PORT),
SimpleHTTPServer.SimpleHTTPRequestHandler)
httpd.socket = ssl.wrap_socket(
httpd.socket, certfile=SERVER_CERT, server_side=True)
httpd.serve_forever()


def main():
# Start the SSL server
thread = threading.Thread(target=ssl_server)
thread.daemon = True
thread.start()

# Wait a bit for the server to start
time.sleep(1)

# Use requests to get a page from the server
requests.get(
u"https://localhost:{}".format(SERVER_PORT),
verify=SERVER_CERT)
# requests.get("https://github.com")

if __name__ == '__main__':
main()
36 changes: 36 additions & 0 deletions tests/libraries/test_requests.spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# -*- mode: python -*-
#-----------------------------------------------------------------------------
# Copyright (c) 2013, PyInstaller Development Team.
#
# Distributed under the terms of the GNU General Public License with exception
# for distributing bootloader.
#
# The full license is in the file COPYING.txt, distributed with this software.
#-----------------------------------------------------------------------------


__testname__ = 'test_requests'

a = Analysis([__testname__ + '.py'],
pathex=[])
pyz = PYZ(a.pure)

TOC_custom = [('test_requests_server.pem','test_requests_server.pem','DATA')]

exe = EXE(pyz,
a.scripts,
exclude_binaries=1,
name=__testname__ + '.exe',
debug=True,
strip=False,
upx=True,
console=True )

coll = COLLECT( exe,
a.binaries,
a.zipfiles,
a.datas,
TOC_custom,
strip=False,
upx=True,
name=__testname__)
10 changes: 10 additions & 0 deletions tests/libraries/test_requests_openssl.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[ req ]
distinguished_name = req_distinguished_name
x509_extensions = v3_ca
[ alternate_names ]
DNS.1 = localhost
[ req_distinguished_name ]
commonName = Common Name
commonName_default = localhost
[ v3_ca ]
subjectAltName = @alternate_names
18 changes: 18 additions & 0 deletions tests/libraries/test_requests_server.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
-----BEGIN RSA PRIVATE KEY-----
MIIBOgIBAAJBALni+6hwnJKQg12wz22L5r3Wm5tz4aeC/3OnziiEUY/4IFv+N651
DVoCI3LFDUA1lMp7UjR+omyrZtZvWmZfqa8CAwEAAQJABtGQsakP1UB/0Rv/P+F1
4VjR9G3XxTFE9ZUeNtZDt6guY2PplKR/JqleAQvPSXaEwRyMhPwZYbmzNGmpmurc
gQIhAOMMJQuvl0cqEWvPq+88H92wkdAQYPK8NSoCQe+VxZifAiEA0ZcqABAb/F+X
nxm/NHTFZjV15oDonZrV+pSeFLW3hPECIGHjF4mtP3x3/6DKnSb8dgSfHo5ksVeV
mxosdP71RIajAiB1EVg2XMkk+Ef6aCkypZ607luCerJzhc7LfkOmEbIGIQIhANnJ
Cfpcqkonyl/2ZgEyhIFugFtQo+TKAOoautt2lhgW
-----END RSA PRIVATE KEY-----
-----BEGIN CERTIFICATE-----
MIIBODCB46ADAgECAgkA87ahT46HZfgwDQYJKoZIhvcNAQEFBQAwFDESMBAGA1UE
AwwJbG9jYWxob3N0MB4XDTE1MDExNTIxMTgwNVoXDTE2MDExNTIxMTgwNVowFDES
MBAGA1UEAwwJbG9jYWxob3N0MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBALni+6hw
nJKQg12wz22L5r3Wm5tz4aeC/3OnziiEUY/4IFv+N651DVoCI3LFDUA1lMp7UjR+
omyrZtZvWmZfqa8CAwEAAaMYMBYwFAYDVR0RBA0wC4IJbG9jYWxob3N0MA0GCSqG
SIb3DQEBBQUAA0EAtuRhYAM7E/CAvAipC29BgoGoihyJWljsVaSjfuneOMNMiNQb
aaU7A6Vi4QsE5+rExs/o5ysn4JrQMF4cDCR0lw==
-----END CERTIFICATE-----
2 changes: 2 additions & 0 deletions tests/runtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ def __init__(self):
'libraries/test_pytz': ['pytz'],
'libraries/test_PyQt4-QtWebKit': ['PyQt4'],
'libraries/test_PyQt4-uic': ['PyQt4'],
'libraries/test_requests': ['requests'],
'libraries/test_sysconfig': ['sysconfig'],
'libraries/test_scapy1': ['scapy'],
'libraries/test_scapy2': ['scapy'],
Expand Down Expand Up @@ -266,6 +267,7 @@ def check(self, test_name):
'interactive/test_onefile_win32_uac_admin',
'libraries/test_Image',
'libraries/test_PIL',
'libraries/test_requests',
'multipackage/test_multipackage1',
'multipackage/test_multipackage2',
'multipackage/test_multipackage3',
Expand Down

0 comments on commit 707e2e6

Please sign in to comment.