Skip to content

Commit

Permalink
test_requests: Add tests for morsel_to_cookie
Browse files Browse the repository at this point in the history
These tests will ensure my changes to how we handle 'expires' don't cause any regressions.
  • Loading branch information
mdbecker committed Dec 6, 2013
1 parent 3235766 commit 3984156
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions test_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -759,6 +760,24 @@ def test_oddball_schemes_dont_check_URLs(self):
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):

Expand Down

0 comments on commit 3984156

Please sign in to comment.