]> Raphaƫl G. Git Repositories - youtubedl/blob - test/test_YoutubeDLCookieJar.py
Initiate new release.
[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
33 if __name__ == '__main__':
34 unittest.main()