diff options
author | Sergey M․ <[email protected]> | 2018-12-09 22:56:33 +0700 |
---|---|---|
committer | Sergey M․ <[email protected]> | 2018-12-09 22:57:00 +0700 |
commit | 9e02c2c704d15d56b92ebe2fc8d481f99f5d106d (patch) | |
tree | a8835bb255c972f71bd0867e0023ad18d0fbf446 /test | |
parent | 5ee7ae5c7577c9c137a7b38edd5ad01ae3a40376 (diff) | |
download | youtube-dl-9e02c2c704d15d56b92ebe2fc8d481f99f5d106d.tar.gz youtube-dl-9e02c2c704d15d56b92ebe2fc8d481f99f5d106d.zip |
[YoutubeDLCookieJar] Add test for keeping session cookies
Diffstat (limited to 'test')
-rw-r--r-- | test/test_YoutubeDLCookieJar.py | 34 | ||||
-rw-r--r-- | test/testdata/cookies/session_cookies.txt | 6 |
2 files changed, 40 insertions, 0 deletions
diff --git a/test/test_YoutubeDLCookieJar.py b/test/test_YoutubeDLCookieJar.py new file mode 100644 index 000000000..6a8243590 --- /dev/null +++ b/test/test_YoutubeDLCookieJar.py @@ -0,0 +1,34 @@ +#!/usr/bin/env python +# coding: utf-8 + +from __future__ import unicode_literals + +import os +import re +import sys +import tempfile +import unittest +sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) + +from youtube_dl.utils import YoutubeDLCookieJar + + +class TestYoutubeDLCookieJar(unittest.TestCase): + def test_keep_session_cookies(self): + cookiejar = YoutubeDLCookieJar('./test/testdata/cookies/session_cookies.txt') + cookiejar.load(ignore_discard=True, ignore_expires=True) + tf = tempfile.NamedTemporaryFile(delete=False) + try: + cookiejar.save(filename=tf.name, ignore_discard=True, ignore_expires=True) + temp = tf.read().decode('utf-8') + self.assertTrue(re.search( + r'www\.foobar\.foobar\s+FALSE\s+/\s+TRUE\s+0\s+YoutubeDLExpiresEmpty\s+YoutubeDLExpiresEmptyValue', temp)) + self.assertTrue(re.search( + r'www\.foobar\.foobar\s+FALSE\s+/\s+TRUE\s+0\s+YoutubeDLExpires0\s+YoutubeDLExpires0Value', temp)) + finally: + tf.close() + os.remove(tf.name) + + +if __name__ == '__main__': + unittest.main() diff --git a/test/testdata/cookies/session_cookies.txt b/test/testdata/cookies/session_cookies.txt new file mode 100644 index 000000000..91e5c9231 --- /dev/null +++ b/test/testdata/cookies/session_cookies.txt @@ -0,0 +1,6 @@ +# Netscape HTTP Cookie File +# http://curl.haxx.se/rfc/cookie_spec.html +# This is a generated file! Do not edit. + +www.foobar.foobar FALSE / TRUE 0 YoutubeDLExpires0 YoutubeDLExpires0Value +www.foobar.foobar FALSE / TRUE 0 YoutubeDLExpiresEmpty YoutubeDLExpiresEmptyValue |