mirror of
https://github.com/kennethreitz/requests.git
synced 2026-06-05 22:50:18 +00:00
test_requests: Add tests for morsel_to_cookie
These tests will ensure my changes to how we handle 'expires' don't cause any regressions.
This commit is contained in:
+23
-4
@@ -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):
|
||||
|
||||
|
||||
Reference in New Issue
Block a user