<s> import pytest <EOL> import requests <EOL> from cachecontrol import CacheControl <EOL> from cachecontrol . cache import DictCache <EOL> from cachecontrol . compat import urljoin <EOL> from pprint import pprint <EOL> class TestVary ( object ) : <EOL> @ pytest . fixture ( ) <EOL> def sess ( self , url ) : <EOL> self . url = urljoin ( url , '<STR_LIT>' ) <EOL> self . cache = DictCache ( ) <EOL> sess = CacheControl ( requests . Session ( ) , cache = self . cache ) <EOL> return sess <EOL> def cached_equal ( self , cached , resp ) : <EOL> if '<STR_LIT>' in resp . raw . headers . get ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> resp . raw . headers . pop ( '<STR_LIT>' ) <EOL> checks = [ <EOL> cached . _fp . getvalue ( ) == resp . content , <EOL> cached . headers == resp . raw . headers , <EOL> cached . status == resp . raw . status , <EOL> cached . version == resp . raw . version , <EOL> cached . reason == resp . raw . reason , <EOL> cached . strict == resp . raw . strict , <EOL> cached . decode_content == resp . raw . decode_content , <EOL> ] <EOL> print ( checks ) <EOL> pprint ( dict ( cached . headers ) ) <EOL> pprint ( dict ( resp . raw . headers ) ) <EOL> return all ( checks ) <EOL> def test_vary_example ( self , sess ) : <EOL> """<STR_LIT>""" <EOL> s = sess . adapters [ "<STR_LIT>" ] . controller . serializer <EOL> r = sess . get ( self . url ) <EOL> c = s . loads ( r . request , self . cache . get ( self . url ) ) <EOL> assert self . cached_equal ( c , r ) <EOL> resp = sess . get ( self . url ) <EOL> assert self . cached_equal ( c , resp ) <EOL> assert resp . from_cache <EOL> resp = sess . get ( self . url , headers = { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> assert not self . cached_equal ( c , resp ) <EOL> assert not resp . from_cache <EOL> assert '<STR_LIT>' in r . headers <EOL> assert len ( r . headers [ '<STR_LIT>' ] . replace ( '<STR_LIT:U+0020>' , '<STR_LIT>' ) . split ( '<STR_LIT:U+002C>' ) ) == <NUM_LIT:2> </s>
