]>
Commit | Line | Data |
---|---|---|
9e02c2c7 S |
1 | #!/usr/bin/env python |
2 | # coding: utf-8 | |
3 | ||
4 | from __future__ import unicode_literals | |
5 | ||
6 | import os | |
7 | import re | |
8 | import sys | |
9 | import tempfile | |
10 | import unittest | |
11 | sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) | |
12 | ||
13 | from youtube_dl.utils import YoutubeDLCookieJar | |
14 | ||
15 | ||
16 | class TestYoutubeDLCookieJar(unittest.TestCase): | |
cff99c91 S |
17 | def __assert_cookie_has_value(self, cookiejar, key): |
18 | self.assertEqual(cookiejar._cookies['www.foobar.foobar']['/'][key].value, key + '_VALUE') | |
19 | ||
9e02c2c7 S |
20 | def test_keep_session_cookies(self): |
21 | cookiejar = YoutubeDLCookieJar('./test/testdata/cookies/session_cookies.txt') | |
22 | cookiejar.load(ignore_discard=True, ignore_expires=True) | |
23 | tf = tempfile.NamedTemporaryFile(delete=False) | |
24 | try: | |
25 | cookiejar.save(filename=tf.name, ignore_discard=True, ignore_expires=True) | |
26 | temp = tf.read().decode('utf-8') | |
27 | self.assertTrue(re.search( | |
28 | r'www\.foobar\.foobar\s+FALSE\s+/\s+TRUE\s+0\s+YoutubeDLExpiresEmpty\s+YoutubeDLExpiresEmptyValue', temp)) | |
29 | self.assertTrue(re.search( | |
30 | r'www\.foobar\.foobar\s+FALSE\s+/\s+TRUE\s+0\s+YoutubeDLExpires0\s+YoutubeDLExpires0Value', temp)) | |
31 | finally: | |
32 | tf.close() | |
33 | os.remove(tf.name) | |
34 | ||
e7e62441 | 35 | def test_strip_httponly_prefix(self): |
36 | cookiejar = YoutubeDLCookieJar('./test/testdata/cookies/httponly_cookies.txt') | |
37 | cookiejar.load(ignore_discard=True, ignore_expires=True) | |
cff99c91 S |
38 | self.__assert_cookie_has_value(cookiejar, 'HTTPONLY_COOKIE') |
39 | self.__assert_cookie_has_value(cookiejar, 'JS_ACCESSIBLE_COOKIE') | |
e7e62441 | 40 | |
cff99c91 S |
41 | def test_convert_spaces_to_tabs(self): |
42 | cookiejar = YoutubeDLCookieJar('./test/testdata/cookies/cookie_file_with_spaces.txt') | |
43 | cookiejar.load(ignore_discard=True, ignore_expires=True) | |
44 | self.__assert_cookie_has_value(cookiejar, 'COOKIE') | |
e7e62441 | 45 | |
9e02c2c7 S |
46 | |
47 | if __name__ == '__main__': | |
48 | unittest.main() |