You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
1.1 KiB

  1. #!/usr/bin/env python
  2. # coding: utf-8
  3. from __future__ import unicode_literals
  4. import os
  5. import re
  6. import sys
  7. import tempfile
  8. import unittest
  9. sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
  10. from youtube_dl.utils import YoutubeDLCookieJar
  11. class TestYoutubeDLCookieJar(unittest.TestCase):
  12. def test_keep_session_cookies(self):
  13. cookiejar = YoutubeDLCookieJar('./test/testdata/cookies/session_cookies.txt')
  14. cookiejar.load(ignore_discard=True, ignore_expires=True)
  15. tf = tempfile.NamedTemporaryFile(delete=False)
  16. try:
  17. cookiejar.save(filename=tf.name, ignore_discard=True, ignore_expires=True)
  18. temp = tf.read().decode('utf-8')
  19. self.assertTrue(re.search(
  20. r'www\.foobar\.foobar\s+FALSE\s+/\s+TRUE\s+0\s+YoutubeDLExpiresEmpty\s+YoutubeDLExpiresEmptyValue', temp))
  21. self.assertTrue(re.search(
  22. r'www\.foobar\.foobar\s+FALSE\s+/\s+TRUE\s+0\s+YoutubeDLExpires0\s+YoutubeDLExpires0Value', temp))
  23. finally:
  24. tf.close()
  25. os.remove(tf.name)
  26. if __name__ == '__main__':
  27. unittest.main()