diff options
author | Michael Becker <mike@beckerfuffle.com> | 2013-12-02 22:14:41 -0500 |
---|---|---|
committer | Michael Becker <mike@beckerfuffle.com> | 2013-12-06 08:56:30 -0500 |
commit | 39841562c5a5d34ed6bebbf733f97b95d57977ca (patch) | |
tree | 41caa608a6103fa86fc5124d90a888c2445e37a5 /test_requests.py | |
parent | 3235766d67aecc8db3b343f40d190e9d4752c071 (diff) | |
download | python-requests-39841562c5a5d34ed6bebbf733f97b95d57977ca.tar.gz |
test_requests: Add tests for morsel_to_cookie
These tests will ensure my changes to how we handle 'expires' don't cause any regressions.
Diffstat (limited to 'test_requests.py')
-rwxr-xr-x | test_requests.py | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/test_requests.py b/test_requests.py index a800ba71..41341534 100755 --- a/test_requests.py +++ b/test_requests.py @@ -6,15 +6,16 @@ from __future__ import division import json import os -import unittest import pickle +import unittest import requests import pytest -from requests.auth import HTTPDigestAuth from requests.adapters import HTTPAdapter -from requests.compat import str, cookielib, getproxies, urljoin, urlparse -from requests.cookies import cookiejar_from_dict +from requests.auth import HTTPDigestAuth +from requests.compat import ( + Morsel, cookielib, getproxies, str, urljoin, urlparse) +from requests.cookies import cookiejar_from_dict, morsel_to_cookie from requests.exceptions import InvalidURL, MissingSchema from requests.structures import CaseInsensitiveDict @@ -759,6 +760,24 @@ class RequestsTestCase(unittest.TestCase): preq = req.prepare() assert test_url == preq.url + def test_morsel_to_cookie_expires_is_converted(self): + morsel = Morsel() + + # Test case where we convert from string time + morsel['expires'] = 'Thu, 01-Jan-1970 00:00:01 GMT' + cookie = morsel_to_cookie(morsel) + self.assertEquals(cookie.expires, 18001) + + # Test case where no conversion is required + morsel['expires'] = 100 + cookie = morsel_to_cookie(morsel) + self.assertEquals(cookie.expires, 100) + + # Test case where an invalid string is input + morsel['expires'] = 'woops' + with self.assertRaises(ValueError): + cookie = morsel_to_cookie(morsel) + class TestContentEncodingDetection(unittest.TestCase): |