]>
Raphaƫl G. Git Repositories - youtubedl/blob - test/test_http.py
bd4d46fef95e60eb7d91752b4c8ba0462b4c469e
2 from __future__
import unicode_literals
4 # Allow direct execution
8 sys
.path
.insert(0, os
.path
.dirname(os
.path
.dirname(os
.path
.abspath(__file__
))))
10 from youtube_dl
import YoutubeDL
11 from youtube_dl
.compat
import compat_http_server
15 TEST_DIR
= os
.path
.dirname(os
.path
.abspath(__file__
))
18 class HTTPTestRequestHandler(compat_http_server
.BaseHTTPRequestHandler
):
19 def log_message(self
, format
, *args
):
23 if self
.path
== '/video.html':
24 self
.send_response(200)
25 self
.send_header('Content-Type', 'text/html; charset=utf-8')
27 self
.wfile
.write(b
'<html><video src="/vid.mp4" /></html>')
28 elif self
.path
== '/vid.mp4':
29 self
.send_response(200)
30 self
.send_header('Content-Type', 'video/mp4')
32 self
.wfile
.write(b
'\x00\x00\x00\x00\x20\x66\x74[video]')
37 class FakeLogger(object):
41 def warning(self
, msg
):
48 class TestHTTP(unittest
.TestCase
):
50 certfn
= os
.path
.join(TEST_DIR
, 'testcert.pem')
51 self
.httpd
= compat_http_server
.HTTPServer(
52 ('localhost', 0), HTTPTestRequestHandler
)
53 self
.httpd
.socket
= ssl
.wrap_socket(
54 self
.httpd
.socket
, certfile
=certfn
, server_side
=True)
55 self
.port
= self
.httpd
.socket
.getsockname()[1]
56 self
.server_thread
= threading
.Thread(target
=self
.httpd
.serve_forever
)
57 self
.server_thread
.daemon
= True
58 self
.server_thread
.start()
60 def test_nocheckcertificate(self
):
61 if sys
.version_info
>= (2, 7, 9): # No certificate checking anyways
62 ydl
= YoutubeDL({'logger': FakeLogger()})
65 ydl
.extract_info
, 'https://localhost:%d/video.html' % self
.port
)
67 ydl
= YoutubeDL({'logger': FakeLogger(), 'nocheckcertificate': True})
68 r
= ydl
.extract_info('https://localhost:%d/video.html' % self
.port
)
69 self
.assertEqual(r
['url'], 'https://localhost:%d/vid.mp4' % self
.port
)
71 if __name__
== '__main__':