aboutsummaryrefslogtreecommitdiff
path: root/test/test_socks.py
diff options
context:
space:
mode:
authorYen Chi Hsuan <yan12125@gmail.com>2016-05-05 17:09:13 +0800
committerYen Chi Hsuan <yan12125@gmail.com>2016-05-10 14:51:38 +0800
commite21f17fc86aab0ac7f1f4cee28f64e7b9b954f71 (patch)
tree71b564cf76a1acd865f8a486212a700c94b65583 /test/test_socks.py
parentedaa23f822a1e4a62771422fb598c7bd8ae0a152 (diff)
downloadyoutube-dl-e21f17fc86aab0ac7f1f4cee28f64e7b9b954f71.tar.xz
[test/test_socks] Test with local SOCKS servers
Diffstat (limited to 'test/test_socks.py')
-rw-r--r--test/test_socks.py42
1 files changed, 39 insertions, 3 deletions
diff --git a/test/test_socks.py b/test/test_socks.py
index 92574c6fd..dc9b8d276 100644
--- a/test/test_socks.py
+++ b/test/test_socks.py
@@ -8,11 +8,20 @@ import sys
import unittest
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
-from test.helper import (FakeYDL, get_params)
-from youtube_dl.compat import compat_urllib_request
+import random
+import subprocess
+from test.helper import (
+ FakeYDL,
+ get_params,
+)
+from youtube_dl.compat import (
+ compat_str,
+ compat_urllib_request,
+)
-class TestSocks(unittest.TestCase):
+
+class TestMultipleSocks(unittest.TestCase):
@staticmethod
def _check_params(attrs):
params = get_params()
@@ -67,5 +76,32 @@ class TestSocks(unittest.TestCase):
params['secondary_server_ip'])
+class TestSocks(unittest.TestCase):
+ def setUp(self):
+ self.port = random.randint(49152, 65535)
+ self.server_process = subprocess.Popen([
+ 'srelay', '-f', '-i', '127.0.0.1:%d' % self.port],
+ stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+
+ def tearDown(self):
+ self.server_process.terminate()
+ self.server_process.communicate()
+
+ def _get_ip(self, protocol):
+ ydl = FakeYDL({
+ 'proxy': '%s://127.0.0.1:%d' % (protocol, self.port),
+ })
+ return ydl.urlopen('http://yt-dl.org/ip').read().decode('utf-8')
+
+ def test_socks4(self):
+ self.assertTrue(isinstance(self._get_ip('socks4'), compat_str))
+
+ def test_socks4a(self):
+ self.assertTrue(isinstance(self._get_ip('socks4a'), compat_str))
+
+ def test_socks5(self):
+ self.assertTrue(isinstance(self._get_ip('socks5'), compat_str))
+
+
if __name__ == '__main__':
unittest.main()