]>
Raphaƫl G. Git Repositories - youtubedl/blob - test/test_YoutubeDLCookieJar.py
4 from __future__
import unicode_literals
11 sys
.path
.insert(0, os
.path
.dirname(os
.path
.dirname(os
.path
.abspath(__file__
))))
13 from youtube_dl
.utils
import YoutubeDLCookieJar
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)
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
))
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)
36 def assert_cookie_has_value(key
):
37 self
.assertEqual(cookiejar
._cookies
['www.foobar.foobar']['/'][key
].value
, key
+ '_VALUE')
39 assert_cookie_has_value('HTTPONLY_COOKIE')
40 assert_cookie_has_value('JS_ACCESSIBLE_COOKIE')
43 if __name__
== '__main__':