Skip to content

Commit

Permalink
Hook up --keep-session-cookies instead of always True.
Browse files Browse the repository at this point in the history
Closes #266
  • Loading branch information
chfoo committed Apr 20, 2015
1 parent 14af516 commit 7352c90
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
1 change: 1 addition & 0 deletions doc/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Unreleased
* Fixed: Input URLs are not fetched in order. Regression since 1.1.
* Fixed: UnicodeEncodeError when fetching FTP files with non-ASCII filenames.
* Fixed: Session cookies not loaded when using ``--load-cookies``.
* Fixed: ``--keep-session-cookies`` was always on.
* Changed: FTP communication uses UTF-8 instead of Latin-1.
* Changed: ``--prefer-family=none`` is now default.
* Added: ``none`` as a choice to ``--prefer-family``.
Expand Down
31 changes: 31 additions & 0 deletions wpull/app_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,37 @@ def test_iri_handling(self):

self.assertEqual(0, exit_code)

@wpull.testing.async.async_test(timeout=DEFAULT_TIMEOUT)
def test_save_cookie(self):
arg_parser = AppArgumentParser()

with tempfile.NamedTemporaryFile() as in_file:
in_file.write(b'# Kittens\n')
in_file.write(b'localhost.local')
in_file.write(b'\tFALSE\t/\tFALSE\t9999999999\tisloggedin\t1\n')
in_file.write(b'\tFALSE\t/\tFALSE\t\tadmin\t1\n')
in_file.flush()

args = arg_parser.parse_args([
self.get_url('/some_page/'),
'--load-cookies', in_file.name,
'--tries', '1',
'--save-cookies', 'wpull_test_cookies.txt',
])
builder = Builder(args, unit_test=True)

app = builder.build()
exit_code = yield From(app.run())

self.assertEqual(0, exit_code)
self.assertEqual(1, builder.factory['Statistics'].files)

with open('wpull_test_cookies.txt', 'rb') as saved_file:
cookie_data = saved_file.read()

self.assertIn(b'isloggedin\t1', cookie_data)
self.assertNotIn(b'admin\t1', cookie_data)

@wpull.testing.async.async_test(timeout=DEFAULT_TIMEOUT)
def test_session_cookie(self):
arg_parser = AppArgumentParser()
Expand Down
2 changes: 1 addition & 1 deletion wpull/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -1262,7 +1262,7 @@ def _build_cookie_jar(self):
'CookieJarWrapper',
cookie_jar,
save_filename=self._args.save_cookies,
keep_session_cookies=True,
keep_session_cookies=self._args.keep_session_cookies,
)

return cookie_jar_wrapper
Expand Down

0 comments on commit 7352c90

Please sign in to comment.