Cookie tests done
This commit is contained in:
parent
96e3a0b1f1
commit
418328e61b
@ -37,6 +37,7 @@ PERFECT_FILES = [
|
||||
'qutebrowser/commands/cmdutils.py',
|
||||
'qutebrowser/commands/argparser.py',
|
||||
|
||||
'qutebrowser/browser/cookies.py',
|
||||
'qutebrowser/browser/tabhistory.py',
|
||||
'qutebrowser/browser/http.py',
|
||||
'qutebrowser/browser/rfc6266.py',
|
||||
|
@ -324,11 +324,6 @@ class ConfigStub(QObject):
|
||||
def __getitem__(self, name):
|
||||
return self.section(name)
|
||||
|
||||
def __setattr__(self, name, value):
|
||||
if name == 'data':
|
||||
self.changed.emit('', '')
|
||||
super().__setattr__(name, value)
|
||||
|
||||
def section(self, name):
|
||||
"""Get a section from the config.
|
||||
|
||||
@ -348,6 +343,15 @@ class ConfigStub(QObject):
|
||||
except KeyError:
|
||||
raise configexc.NoOptionError(opt, sect)
|
||||
|
||||
def set(self, sect, opt, value):
|
||||
"""Set a value in the config."""
|
||||
data = self.data[sect]
|
||||
try:
|
||||
data[opt] = value
|
||||
self.changed.emit(sect, opt)
|
||||
except KeyError:
|
||||
raise configexc.NoOptionError(opt, sect)
|
||||
|
||||
|
||||
class KeyConfigStub:
|
||||
|
||||
|
@ -33,7 +33,6 @@ from qutebrowser.misc import lineparser
|
||||
CONFIG_ALL_COOKIES = {'content': {'cookies-accept': 'all'}}
|
||||
CONFIG_NEVER_COOKIES = {'content': {'cookies-accept': 'never'}}
|
||||
CONFIG_COOKIES_ENABLED = {'content': {'cookies-store': True}}
|
||||
CONFIG_COOKIES_DISABLED = {'content': {'cookies-store': False}}
|
||||
|
||||
|
||||
cookie1 = b'foo1=bar; expires=Tue, 01-Jan-2036 08:00:01 GMT'
|
||||
@ -62,8 +61,6 @@ def fake_save_manager():
|
||||
yield
|
||||
objreg.delete('save-manager')
|
||||
|
||||
"""Tests for RAMCookieJar."""
|
||||
|
||||
|
||||
def test_set_cookies_accept(config_stub, qtbot, monkeypatch):
|
||||
"""Test setCookiesFromUrl with cookies enabled."""
|
||||
@ -110,7 +107,10 @@ def test_purge_old_cookies(config_stub, fake_save_manager):
|
||||
jar = cookies.CookieJar(line_parser=line_parser_stub)
|
||||
|
||||
assert len(jar.allCookies()) == 4
|
||||
|
||||
jar.purge_old_cookies()
|
||||
|
||||
# Test that old cookies are gone
|
||||
assert len(jar.allCookies()) == 3
|
||||
assert jar.allCookies()[0].toRawForm().data() == cookie1
|
||||
assert jar.allCookies()[1].toRawForm().data() == cookie2
|
||||
@ -125,7 +125,7 @@ def test_save(config_stub, fake_save_manager, monkeypatch):
|
||||
jar = cookies.CookieJar()
|
||||
jar._lineparser.data = [cookie1, cookie2, session_cookie, expired_cookie]
|
||||
|
||||
# update the cookies on the jar itself
|
||||
# Update the cookies on the jar itself
|
||||
jar.parse_cookies()
|
||||
jar.save()
|
||||
assert len(jar._lineparser.saved) == 2
|
||||
@ -139,10 +139,11 @@ def test_cookies_changed(config_stub, fake_save_manager, monkeypatch, qtbot):
|
||||
monkeypatch.setattr(lineparser,
|
||||
'LineParser', LineparserSaveStub)
|
||||
jar = cookies.CookieJar()
|
||||
jar._lineparser.data = [cookie1, cookie2]
|
||||
|
||||
# Test that signal is emitted
|
||||
# Test that cookies are not saved
|
||||
with qtbot.waitSignal(jar.changed, raising=True):
|
||||
config_stub.data == CONFIG_COOKIES_DISABLED
|
||||
config_stub.set('content', 'cookies-store', False)
|
||||
|
||||
# test that cookies aren't saved
|
||||
# Test that cookies are not saved
|
||||
assert len(jar._lineparser.saved) == 0
|
||||
|
Loading…
Reference in New Issue
Block a user