forked from pyinstaller/pyinstaller
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request pyinstaller#151 from rbranche/hook-requests
Add test for requests library.
- Loading branch information
Showing
5 changed files
with
131 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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__) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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----- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters