tests: use binary content in request cache tests
This commit is contained in:
parent
cbd9044835
commit
96ac10646a
|
@ -128,23 +128,23 @@ def test_sign_anonymous_user():
|
||||||
|
|
||||||
def test_requests_cache():
|
def test_requests_cache():
|
||||||
with mock.patch('combo.utils.requests_wrapper.RequestsSession.request') as requests_get:
|
with mock.patch('combo.utils.requests_wrapper.RequestsSession.request') as requests_get:
|
||||||
requests_get.return_value = mock.Mock(content='hello world', status_code=200)
|
requests_get.return_value = mock.Mock(content=b'hello world', status_code=200)
|
||||||
# default cache, nothing in there
|
# default cache, nothing in there
|
||||||
assert requests.get('http://cache.example.org/').content == 'hello world'
|
assert requests.get('http://cache.example.org/').content == b'hello world'
|
||||||
assert requests_get.call_count == 1
|
assert requests_get.call_count == 1
|
||||||
# now there's something in cache
|
# now there's something in cache
|
||||||
assert requests.get('http://cache.example.org/').content == 'hello world'
|
assert requests.get('http://cache.example.org/').content == b'hello world'
|
||||||
assert requests_get.call_count == 1
|
assert requests_get.call_count == 1
|
||||||
# value changed
|
# value changed
|
||||||
requests_get.return_value = mock.Mock(content='hello second world', status_code=200)
|
requests_get.return_value = mock.Mock(content=b'hello second world', status_code=200)
|
||||||
assert requests.get('http://cache.example.org/').content == 'hello world'
|
assert requests.get('http://cache.example.org/').content == b'hello world'
|
||||||
assert requests_get.call_count == 1
|
assert requests_get.call_count == 1
|
||||||
# force cache invalidation
|
# force cache invalidation
|
||||||
assert requests.get('http://cache.example.org/', invalidate_cache=True).content == 'hello second world'
|
assert requests.get('http://cache.example.org/', invalidate_cache=True).content == b'hello second world'
|
||||||
assert requests_get.call_count == 2
|
assert requests_get.call_count == 2
|
||||||
# check raise_if_not_cached
|
# check raise_if_not_cached
|
||||||
with pytest.raises(NothingInCacheException):
|
with pytest.raises(NothingInCacheException):
|
||||||
requests.get('http://cache.example.org/other', raise_if_not_cached=True)
|
requests.get('http://cache.example.org/other', raise_if_not_cached=True)
|
||||||
|
|
||||||
# check with unicode url
|
# check with unicode url
|
||||||
assert requests.get(u'http://cache.example.org/éléphant').content == 'hello second world'
|
assert requests.get(u'http://cache.example.org/éléphant').content == b'hello second world'
|
||||||
|
|
Loading…
Reference in New Issue