mirror of https://github.com/python/cpython
gh-79096: Fix/improve http cookiejar tests (GH-93614)
Fixup of GH-93463: - remove stray print - use proper way to check file mode - add working chmod decorator Co-authored-by: Łukasz Langa <lukasz@langa.pl>
This commit is contained in:
parent
22df2e0322
commit
68f6a5da19
|
@ -1,6 +1,7 @@
|
|||
"""Tests for http/cookiejar.py."""
|
||||
|
||||
import os
|
||||
import stat
|
||||
import sys
|
||||
import re
|
||||
import test.support
|
||||
|
@ -366,11 +367,11 @@ class FileCookieJarTests(unittest.TestCase):
|
|||
c = LWPCookieJar()
|
||||
c.load(filename, ignore_discard=True)
|
||||
finally:
|
||||
try: os.unlink(filename)
|
||||
except OSError: pass
|
||||
os_helper.unlink(filename)
|
||||
self.assertEqual(c._cookies["www.acme.com"]["/"]["boo"].value, None)
|
||||
|
||||
@unittest.skipIf(mswindows, "windows file permissions are incompatible with file modes")
|
||||
@os_helper.skip_unless_working_chmod
|
||||
def test_lwp_filepermissions(self):
|
||||
# Cookie file should only be readable by the creator
|
||||
filename = os_helper.TESTFN
|
||||
|
@ -378,14 +379,13 @@ class FileCookieJarTests(unittest.TestCase):
|
|||
interact_netscape(c, "http://www.acme.com/", 'boo')
|
||||
try:
|
||||
c.save(filename, ignore_discard=True)
|
||||
status = os.stat(filename)
|
||||
print(status.st_mode)
|
||||
self.assertEqual(oct(status.st_mode)[-3:], '600')
|
||||
st = os.stat(filename)
|
||||
self.assertEqual(stat.S_IMODE(st.st_mode), 0o600)
|
||||
finally:
|
||||
try: os.unlink(filename)
|
||||
except OSError: pass
|
||||
os_helper.unlink(filename)
|
||||
|
||||
@unittest.skipIf(mswindows, "windows file permissions are incompatible with file modes")
|
||||
@os_helper.skip_unless_working_chmod
|
||||
def test_mozilla_filepermissions(self):
|
||||
# Cookie file should only be readable by the creator
|
||||
filename = os_helper.TESTFN
|
||||
|
@ -393,11 +393,10 @@ class FileCookieJarTests(unittest.TestCase):
|
|||
interact_netscape(c, "http://www.acme.com/", 'boo')
|
||||
try:
|
||||
c.save(filename, ignore_discard=True)
|
||||
status = os.stat(filename)
|
||||
self.assertEqual(oct(status.st_mode)[-3:], '600')
|
||||
st = os.stat(filename)
|
||||
self.assertEqual(stat.S_IMODE(st.st_mode), 0o600)
|
||||
finally:
|
||||
try: os.unlink(filename)
|
||||
except OSError: pass
|
||||
os_helper.unlink(filename)
|
||||
|
||||
def test_bad_magic(self):
|
||||
# OSErrors (eg. file doesn't exist) are allowed to propagate
|
||||
|
@ -422,8 +421,7 @@ class FileCookieJarTests(unittest.TestCase):
|
|||
c = cookiejar_class()
|
||||
self.assertRaises(LoadError, c.load, filename)
|
||||
finally:
|
||||
try: os.unlink(filename)
|
||||
except OSError: pass
|
||||
os_helper.unlink(filename)
|
||||
|
||||
class CookieTests(unittest.TestCase):
|
||||
# XXX
|
||||
|
@ -527,7 +525,7 @@ class CookieTests(unittest.TestCase):
|
|||
c = MozillaCookieJar(filename)
|
||||
c.revert(ignore_expires=True, ignore_discard=True)
|
||||
finally:
|
||||
os.unlink(c.filename)
|
||||
os_helper.unlink(c.filename)
|
||||
# cookies unchanged apart from lost info re. whether path was specified
|
||||
self.assertEqual(
|
||||
repr(c),
|
||||
|
@ -1797,8 +1795,7 @@ class LWPCookieTests(unittest.TestCase):
|
|||
c = LWPCookieJar(policy=pol)
|
||||
c.load(filename, ignore_discard=True)
|
||||
finally:
|
||||
try: os.unlink(filename)
|
||||
except OSError: pass
|
||||
os_helper.unlink(filename)
|
||||
|
||||
self.assertEqual(old, repr(c))
|
||||
|
||||
|
@ -1857,8 +1854,7 @@ class LWPCookieTests(unittest.TestCase):
|
|||
DefaultCookiePolicy(rfc2965=True))
|
||||
new_c.load(ignore_discard=ignore_discard)
|
||||
finally:
|
||||
try: os.unlink(filename)
|
||||
except OSError: pass
|
||||
os_helper.unlink(filename)
|
||||
return new_c
|
||||
|
||||
new_c = save_and_restore(c, True)
|
||||
|
|
Loading…
Reference in New Issue