<s> from . support import ( BaseWebTest , unittest , MINIMALIST_BUCKET , <EOL> MINIMALIST_COLLECTION , MINIMALIST_RECORD ) <EOL> class GlobalSettingsTest ( BaseWebTest , unittest . TestCase ) : <EOL> def get_app_settings ( self , extra = None ) : <EOL> settings = super ( GlobalSettingsTest , self ) . get_app_settings ( extra ) <EOL> settings [ '<STR_LIT>' ] = <NUM_LIT> <EOL> settings [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> return settings <EOL> def setUp ( self ) : <EOL> super ( GlobalSettingsTest , self ) . setUp ( ) <EOL> self . create_bucket ( '<STR_LIT>' ) <EOL> self . app . put_json ( '<STR_LIT>' , <EOL> MINIMALIST_COLLECTION , <EOL> headers = self . headers ) <EOL> r = self . app . post_json ( '<STR_LIT>' , <EOL> MINIMALIST_RECORD , <EOL> headers = self . headers ) <EOL> self . record = r . json [ '<STR_LIT:data>' ] <EOL> def test_expires_and_cache_control_headers_are_set ( self ) : <EOL> url = '<STR_LIT>' <EOL> r = self . app . get ( url ) <EOL> self . assertIn ( '<STR_LIT>' , r . headers ) <EOL> self . assertEqual ( r . headers [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> r = self . app . get ( url + '<STR_LIT>' % self . record [ '<STR_LIT:id>' ] ) <EOL> self . assertIn ( '<STR_LIT>' , r . headers ) <EOL> self . assertEqual ( r . headers [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> class SpecificSettingsTest ( BaseWebTest , unittest . TestCase ) : <EOL> def get_app_settings ( self , extra = None ) : <EOL> settings = super ( SpecificSettingsTest , self ) . get_app_settings ( extra ) <EOL> settings [ '<STR_LIT>' ] = <NUM_LIT:30> <EOL> settings [ '<STR_LIT>' ] = <NUM_LIT> <EOL> return settings <EOL> def setUp ( self ) : <EOL> super ( SpecificSettingsTest , self ) . setUp ( ) <EOL> def create_record_in_collection ( bucket_id , collection_id ) : <EOL> bucket = MINIMALIST_BUCKET . copy ( ) <EOL> bucket [ '<STR_LIT>' ] = { '<STR_LIT>' : [ '<STR_LIT>' ] } <EOL> self . app . put_json ( '<STR_LIT>' % bucket_id , <EOL> bucket , <EOL> headers = self . headers ) <EOL> collection_url = '<STR_LIT>' % ( bucket_id , <EOL> collection_id ) <EOL> self . app . put_json ( collection_url , <EOL> MINIMALIST_COLLECTION , <EOL> headers = self . headers ) <EOL> r = self . app . post_json ( collection_url + '<STR_LIT>' , <EOL> MINIMALIST_RECORD , <EOL> headers = self . headers ) <EOL> return r . json [ '<STR_LIT:data>' ] <EOL> self . blog_record = create_record_in_collection ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . app_record = create_record_in_collection ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> def assertHasCache ( self , url , age ) : <EOL> r = self . app . get ( url ) <EOL> self . assertIn ( '<STR_LIT>' , r . headers ) <EOL> self . assertEqual ( r . headers [ '<STR_LIT>' ] , '<STR_LIT>' % age ) <EOL> def test_for_records_on_a_specific_bucket ( self ) : <EOL> collection_url = '<STR_LIT>' <EOL> self . assertHasCache ( collection_url , <NUM_LIT:30> ) <EOL> record_url = collection_url + '<STR_LIT>' % self . blog_record [ '<STR_LIT:id>' ] <EOL> self . assertHasCache ( record_url , <NUM_LIT:30> ) <EOL> def test_for_records_on_a_specific_collection ( self ) : <EOL> collection_url = '<STR_LIT>' <EOL> self . assertHasCache ( collection_url , <NUM_LIT> ) <EOL> record_url = collection_url + '<STR_LIT>' % self . app_record [ '<STR_LIT:id>' ] <EOL> self . assertHasCache ( record_url , <NUM_LIT> ) <EOL> class CollectionExpiresTest ( BaseWebTest , unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> super ( CollectionExpiresTest , self ) . setUp ( ) <EOL> bucket = MINIMALIST_BUCKET . copy ( ) <EOL> bucket [ '<STR_LIT>' ] = { '<STR_LIT>' : [ '<STR_LIT>' ] } <EOL> self . app . put_json ( '<STR_LIT>' , <EOL> bucket , <EOL> headers = self . headers ) <EOL> self . collection_url = '<STR_LIT>' <EOL> self . app . put_json ( self . collection_url , <EOL> { '<STR_LIT:data>' : { '<STR_LIT>' : <NUM_LIT> } } , <EOL> headers = self . headers ) <EOL> self . records_url = self . collection_url + '<STR_LIT>' <EOL> resp = self . app . post_json ( self . records_url , <EOL> MINIMALIST_RECORD , <EOL> headers = self . headers ) <EOL> self . record = resp . json [ '<STR_LIT:data>' ] <EOL> self . record_url = self . records_url + '<STR_LIT:/>' + self . record [ '<STR_LIT:id>' ] <EOL> def test_cache_expires_must_be_an_integer ( self ) : <EOL> self . app . put_json ( self . collection_url , <EOL> { '<STR_LIT:data>' : { '<STR_LIT>' : '<STR_LIT:abc>' } } , <EOL> headers = self . headers , <EOL> status = <NUM_LIT> ) <EOL> def test_expires_and_cache_control_are_not_set_if_authenticated ( self ) : <EOL> r = self . app . get ( self . records_url , headers = self . headers ) <EOL> self . assertNotIn ( '<STR_LIT>' , r . headers ) <EOL> self . assertIn ( '<STR_LIT>' , r . headers ) <EOL> self . assertEqual ( r . headers [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> def test_expires_and_cache_control_are_set_on_records ( self ) : <EOL> r = self . app . get ( self . records_url ) <EOL> self . assertIn ( '<STR_LIT>' , r . headers ) <EOL> self . assertEqual ( r . headers [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> def test_expires_and_cache_control_are_set_on_record ( self ) : <EOL> r = self . app . get ( self . record_url ) <EOL> self . assertIn ( '<STR_LIT>' , r . headers ) <EOL> self . assertEqual ( r . headers [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> def test_cache_control_is_set_no_cache_if_zero ( self ) : <EOL> self . app . put_json ( self . collection_url , <EOL> { '<STR_LIT:data>' : { '<STR_LIT>' : <NUM_LIT:0> } } , <EOL> headers = self . headers ) <EOL> r = self . app . get ( self . records_url ) <EOL> self . assertIn ( '<STR_LIT>' , r . headers ) <EOL> self . assertEqual ( r . headers [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' ) <EOL> self . assertEqual ( r . headers [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> def test_cache_control_on_collection_overrides_setting ( self ) : <EOL> app = self . _get_test_app ( { <EOL> '<STR_LIT>' : <NUM_LIT:10> , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } ) <EOL> app . put_json ( '<STR_LIT>' , MINIMALIST_BUCKET , headers = self . headers ) <EOL> app . put_json ( self . collection_url , <EOL> { '<STR_LIT:data>' : { '<STR_LIT>' : <NUM_LIT> } } , <EOL> headers = self . headers ) <EOL> r = app . get ( self . records_url ) <EOL> self . assertIn ( '<STR_LIT>' , r . headers ) <EOL> self . assertEqual ( r . headers [ '<STR_LIT>' ] , '<STR_LIT>' ) </s>
