Merge pull request #3032 from davidsoncasey/master

Changes for #3028
This commit is contained in:
Cory Benfield
2016-03-06 18:07:59 +00:00
2 changed files with 38 additions and 0 deletions
+6
View File
@@ -277,6 +277,12 @@ class RequestsCookieJar(cookielib.CookieJar, collections.MutableMapping):
dictionary[cookie.name] = cookie.value
return dictionary
def __contains__(self, name):
try:
return super(RequestsCookieJar, self).__contains__(name)
except CookieConflictError:
return True
def __getitem__(self, name):
"""Dict-like __getitem__() for compatibility with client code. Throws
exception if there are more than one cookie with name. In that case,
+32
View File
@@ -754,6 +754,38 @@ class TestRequests:
# make sure one can use items multiple times
assert list(items) == list(items)
def test_cookie_duplicate_names_different_domains(self):
key = 'some_cookie'
value = 'some_value'
domain1 = 'test1.com'
domain2 = 'test2.com'
jar = requests.cookies.RequestsCookieJar()
jar.set(key, value, domain=domain1)
jar.set(key, value, domain=domain2)
assert key in jar
items = jar.items()
assert len(items) == 2
# Verify that CookieConflictError is raised if domain is not specified
with pytest.raises(requests.cookies.CookieConflictError):
jar.get(key)
# Verify that CookieConflictError is not raised if domain is specified
cookie = jar.get(key, domain=domain1)
assert cookie == value
def test_cookie_duplicate_names_raises_cookie_conflict_error(self):
key = 'some_cookie'
value = 'some_value'
path = 'some_path'
jar = requests.cookies.RequestsCookieJar()
jar.set(key, value, path=path)
jar.set(key, value)
with pytest.raises(requests.cookies.CookieConflictError):
jar.get(key)
def test_time_elapsed_blank(self, httpbin):
r = requests.get(httpbin('get'))
td = r.elapsed