]> Raphaƫl G. Git Repositories - youtubedl/blob - test/test_YoutubeDLCookieJar.py
f959798deb595165fddac6a8e555570c0420e454
[youtubedl] / test / test_YoutubeDLCookieJar.py
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):
17 def test_keep_session_cookies(self):
18 cookiejar = YoutubeDLCookieJar('./test/testdata/cookies/session_cookies.txt')
19 cookiejar.load(ignore_discard=True, ignore_expires=True)
20 tf = tempfile.NamedTemporaryFile(delete=False)
21 try:
22 cookiejar.save(filename=tf.name, ignore_discard=True, ignore_expires=True)
23 temp = tf.read().decode('utf-8')
24 self.assertTrue(re.search(
25 r'www\.foobar\.foobar\s+FALSE\s+/\s+TRUE\s+0\s+YoutubeDLExpiresEmpty\s+YoutubeDLExpiresEmptyValue', temp))
26 self.assertTrue(re.search(
27 r'www\.foobar\.foobar\s+FALSE\s+/\s+TRUE\s+0\s+YoutubeDLExpires0\s+YoutubeDLExpires0Value', temp))
28 finally:
29 tf.close()
30 os.remove(tf.name)
31
32 def test_strip_httponly_prefix(self):
33 cookiejar = YoutubeDLCookieJar('./test/testdata/cookies/httponly_cookies.txt')
34 cookiejar.load(ignore_discard=True, ignore_expires=True)
35
36 def assert_cookie_has_value(key):
37 self.assertEqual(cookiejar._cookies['www.foobar.foobar']['/'][key].value, key + '_VALUE')
38
39 assert_cookie_has_value('HTTPONLY_COOKIE')
40 assert_cookie_has_value('JS_ACCESSIBLE_COOKIE')
41
42
43 if __name__ == '__main__':
44 unittest.main()