<s> """<STR_LIT>""" <EOL> from . . base_test import FlaskCorsTestCase , AppConfigTest <EOL> from flask import Flask , jsonify <EOL> from flask_cors import * <EOL> from flask_cors . core import * <EOL> class AppExtensionRegexp ( AppConfigTest ) : <EOL> def setUp ( self ) : <EOL> self . app = Flask ( __name__ ) <EOL> CORS ( self . app , resources = { <EOL> r'<STR_LIT:/>' : { } , <EOL> r'<STR_LIT>' : { '<STR_LIT>' : [ "<STR_LIT>" , "<STR_LIT>" ] } , <EOL> r'<STR_LIT>' : { '<STR_LIT>' : '<STR_LIT>' } , <EOL> r'<STR_LIT>' : { <EOL> '<STR_LIT>' : set ( [ "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> } , <EOL> r'<STR_LIT>' : { <EOL> '<STR_LIT>' : r"<STR_LIT>" <EOL> } , <EOL> r'<STR_LIT>' : { <EOL> '<STR_LIT>' : [ r"<STR_LIT>" , r"<STR_LIT>" ] <EOL> } , <EOL> r'<STR_LIT>' : { <EOL> '<STR_LIT>' : [ "<STR_LIT>" , r"<STR_LIT>" ] <EOL> } , <EOL> r'<STR_LIT>' : { <EOL> '<STR_LIT>' : True <EOL> } <EOL> } ) <EOL> @ self . app . route ( '<STR_LIT:/>' ) <EOL> def wildcard ( ) : <EOL> return '<STR_LIT>' <EOL> @ self . app . route ( '<STR_LIT>' ) <EOL> def send_wildcard_with_origin ( ) : <EOL> return '<STR_LIT>' <EOL> @ self . app . route ( '<STR_LIT>' ) <EOL> def test_list ( ) : <EOL> return '<STR_LIT>' <EOL> @ self . app . route ( '<STR_LIT>' ) <EOL> def test_string ( ) : <EOL> return '<STR_LIT>' <EOL> @ self . app . route ( '<STR_LIT>' ) <EOL> def test_set ( ) : <EOL> return '<STR_LIT>' <EOL> def test_defaults_no_origin ( self ) : <EOL> '''<STR_LIT>''' <EOL> for resp in self . iter_responses ( '<STR_LIT:/>' ) : <EOL> self . assertEqual ( resp . headers . get ( ACL_ORIGIN ) , None ) <EOL> def test_defaults_with_origin ( self ) : <EOL> '''<STR_LIT>''' <EOL> for resp in self . iter_responses ( '<STR_LIT:/>' , origin = '<STR_LIT>' ) : <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( resp . headers . get ( ACL_ORIGIN ) , '<STR_LIT>' ) <EOL> def test_send_wildcard_with_origin ( self ) : <EOL> '''<STR_LIT>''' <EOL> for resp in self . iter_responses ( '<STR_LIT>' , origin = '<STR_LIT>' ) : <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( resp . headers . get ( ACL_ORIGIN ) , '<STR_LIT:*>' ) <EOL> def test_list_serialized ( self ) : <EOL> '''<STR_LIT>''' <EOL> resp = self . get ( '<STR_LIT>' , origin = '<STR_LIT>' ) <EOL> self . assertEqual ( resp . headers . get ( ACL_ORIGIN ) , '<STR_LIT>' ) <EOL> def test_string_serialized ( self ) : <EOL> '''<STR_LIT>''' <EOL> resp = self . get ( '<STR_LIT>' , origin = '<STR_LIT>' ) <EOL> self . assertEqual ( resp . headers . get ( ACL_ORIGIN ) , '<STR_LIT>' ) <EOL> def test_set_serialized ( self ) : <EOL> '''<STR_LIT>''' <EOL> resp = self . get ( '<STR_LIT>' , origin = '<STR_LIT>' ) <EOL> allowed = resp . headers . get ( ACL_ORIGIN ) <EOL> self . assertEqual ( allowed , '<STR_LIT>' ) <EOL> def test_not_matching_origins ( self ) : <EOL> for resp in self . iter_responses ( '<STR_LIT>' , origin = "<STR_LIT>" ) : <EOL> self . assertFalse ( ACL_ORIGIN in resp . headers ) <EOL> def test_subdomain_regex ( self ) : <EOL> for sub in letters : <EOL> domain = "<STR_LIT>" % sub <EOL> for resp in self . iter_responses ( '<STR_LIT>' , <EOL> headers = { '<STR_LIT>' : domain } ) : <EOL> self . assertEqual ( domain , resp . headers . get ( ACL_ORIGIN ) ) <EOL> def test_compiled_subdomain_regex ( self ) : <EOL> for sub in letters : <EOL> domain = "<STR_LIT>" % sub <EOL> for resp in self . iter_responses ( '<STR_LIT>' , <EOL> headers = { '<STR_LIT>' : domain } ) : <EOL> self . assertEqual ( domain , resp . headers . get ( ACL_ORIGIN ) ) <EOL> def test_regex_list ( self ) : <EOL> for parent in '<STR_LIT>' , '<STR_LIT>' : <EOL> for sub in letters : <EOL> domain = "<STR_LIT>" % ( sub , parent ) <EOL> for resp in self . iter_responses ( '<STR_LIT>' , <EOL> headers = { '<STR_LIT>' : domain } ) : <EOL> self . assertEqual ( domain , resp . headers . get ( ACL_ORIGIN ) ) <EOL> def test_regex_mixed_list ( self ) : <EOL> '''<STR_LIT>''' <EOL> for sub in letters : <EOL> domain = "<STR_LIT>" % sub <EOL> for resp in self . iter_responses ( '<STR_LIT>' , <EOL> origin = domain ) : <EOL> self . assertEqual ( domain , resp . headers . get ( ACL_ORIGIN ) ) <EOL> self . assertEquals ( "<STR_LIT>" , <EOL> self . get ( '<STR_LIT>' , origin = '<STR_LIT>' ) . headers . get ( ACL_ORIGIN ) ) <EOL> class AppExtensionList ( FlaskCorsTestCase ) : <EOL> def setUp ( self ) : <EOL> self . app = Flask ( __name__ ) <EOL> CORS ( self . app , resources = [ r'<STR_LIT>' , r'<STR_LIT>' ] , <EOL> origins = [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> @ self . app . route ( '<STR_LIT>' ) <EOL> def unexposed ( ) : <EOL> return '<STR_LIT>' <EOL> @ self . app . route ( '<STR_LIT>' ) <EOL> def exposed1 ( ) : <EOL> return '<STR_LIT>' <EOL> @ self . app . route ( '<STR_LIT>' ) <EOL> def exposed2 ( ) : <EOL> return '<STR_LIT>' <EOL> def test_exposed ( self ) : <EOL> for resp in self . iter_responses ( '<STR_LIT>' , origin = '<STR_LIT>' ) : <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( resp . headers . get ( ACL_ORIGIN ) , '<STR_LIT>' ) <EOL> def test_other_exposed ( self ) : <EOL> for resp in self . iter_responses ( '<STR_LIT>' , origin = '<STR_LIT>' ) : <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( resp . headers . get ( ACL_ORIGIN ) , '<STR_LIT>' ) <EOL> def test_unexposed ( self ) : <EOL> for resp in self . iter_responses ( '<STR_LIT>' , origin = '<STR_LIT>' ) : <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> self . assertFalse ( ACL_ORIGIN in resp . headers ) <EOL> class AppExtensionString ( FlaskCorsTestCase ) : <EOL> def setUp ( self ) : <EOL> self . app = Flask ( __name__ ) <EOL> CORS ( self . app , resources = r'<STR_LIT>' , <EOL> headers = '<STR_LIT:Content-Type>' , <EOL> expose_headers = '<STR_LIT>' , <EOL> origins = '<STR_LIT>' ) <EOL> @ self . app . route ( '<STR_LIT>' ) <EOL> def exposed1 ( ) : <EOL> return jsonify ( success = True ) <EOL> @ self . app . route ( '<STR_LIT>' ) <EOL> def exposed2 ( ) : <EOL> return jsonify ( success = True ) <EOL> @ self . app . route ( '<STR_LIT>' ) <EOL> @ cross_origin ( origins = '<STR_LIT>' ) <EOL> def overridden ( ) : <EOL> return jsonify ( special = True ) <EOL> @ self . app . route ( '<STR_LIT:/>' ) <EOL> def index ( ) : <EOL> return '<STR_LIT>' <EOL> def test_exposed ( self ) : <EOL> for path in '<STR_LIT>' , '<STR_LIT>' : <EOL> for resp in self . iter_responses ( path , origin = '<STR_LIT>' ) : <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( resp . headers . get ( ACL_ORIGIN ) , '<STR_LIT>' ) <EOL> self . assertEqual ( resp . headers . get ( ACL_EXPOSE_HEADERS ) , <EOL> '<STR_LIT>' ) <EOL> for resp in self . iter_responses ( path , origin = '<STR_LIT>' ) : <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> self . assertFalse ( ACL_ORIGIN in resp . headers ) <EOL> self . assertFalse ( ACL_EXPOSE_HEADERS in resp . headers ) <EOL> def test_unexposed ( self ) : <EOL> for resp in self . iter_responses ( '<STR_LIT:/>' , origin = '<STR_LIT>' ) : <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> self . assertFalse ( ACL_ORIGIN in resp . headers ) <EOL> self . assertFalse ( ACL_EXPOSE_HEADERS in resp . headers ) <EOL> def test_override ( self ) : <EOL> for resp in self . iter_responses ( '<STR_LIT>' , origin = '<STR_LIT>' ) : <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( resp . headers . get ( ACL_ORIGIN ) , '<STR_LIT>' ) <EOL> self . assertFalse ( ACL_EXPOSE_HEADERS in resp . headers ) <EOL> for resp in self . iter_responses ( '<STR_LIT>' , origin = '<STR_LIT>' ) : <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> self . assertFalse ( ACL_ORIGIN in resp . headers ) <EOL> self . assertFalse ( ACL_EXPOSE_HEADERS in resp . headers ) <EOL> class AppExtensionError ( FlaskCorsTestCase ) : <EOL> def test_value_error ( self ) : <EOL> try : <EOL> app = Flask ( __name__ ) <EOL> CORS ( app , resources = <NUM_LIT:5> ) <EOL> self . assertTrue ( False , "<STR_LIT>" ) <EOL> except ValueError : <EOL> pass <EOL> class AppExtensionDefault ( FlaskCorsTestCase ) : <EOL> def test_default ( self ) : <EOL> '''<STR_LIT>''' <EOL> self . app = Flask ( __name__ ) <EOL> CORS ( self . app ) <EOL> @ self . app . route ( '<STR_LIT:/>' ) <EOL> def index ( ) : <EOL> return '<STR_LIT>' <EOL> for resp in self . iter_responses ( '<STR_LIT:/>' , origin = '<STR_LIT>' ) : <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> self . assertTrue ( ACL_ORIGIN in resp . headers ) <EOL> class AppExtensionExampleApp ( FlaskCorsTestCase ) : <EOL> def setUp ( self ) : <EOL> self . app = Flask ( __name__ ) <EOL> CORS ( self . app , resources = { <EOL> r'<STR_LIT>' : { '<STR_LIT>' : [ '<STR_LIT>' , '<STR_LIT>' ] } <EOL> } ) <EOL> @ self . app . route ( '<STR_LIT:/>' ) <EOL> def index ( ) : <EOL> return '<STR_LIT>' <EOL> @ self . app . route ( '<STR_LIT>' ) <EOL> def test_wildcard ( ) : <EOL> return '<STR_LIT>' <EOL> @ self . app . route ( '<STR_LIT>' ) <EOL> def test_exact_match ( ) : <EOL> return '<STR_LIT>' <EOL> def test_index ( self ) : <EOL> '''<STR_LIT>''' <EOL> for resp in self . iter_responses ( '<STR_LIT:/>' , origin = '<STR_LIT>' ) : <EOL> self . assertFalse ( ACL_ORIGIN in resp . headers ) <EOL> def test_wildcard ( self ) : <EOL> '''<STR_LIT>''' <EOL> for origin in [ '<STR_LIT>' , '<STR_LIT>' ] : <EOL> for resp in self . iter_responses ( '<STR_LIT>' , origin = origin ) : <EOL> self . assertTrue ( ACL_ORIGIN in resp . headers ) <EOL> self . assertEqual ( origin , resp . headers . get ( ACL_ORIGIN ) ) <EOL> def test_exact_match ( self ) : <EOL> '''<STR_LIT>''' <EOL> for origin in [ '<STR_LIT>' , '<STR_LIT>' ] : <EOL> for resp in self . iter_responses ( '<STR_LIT>' , origin = origin ) : <EOL> self . assertTrue ( ACL_ORIGIN in resp . headers ) <EOL> self . assertEqual ( origin , resp . headers . get ( ACL_ORIGIN ) ) <EOL> class AppExtensionCompiledRegexp ( FlaskCorsTestCase ) : <EOL> def test_compiled_regex ( self ) : <EOL> '''<STR_LIT>''' <EOL> import re <EOL> self . app = Flask ( __name__ ) <EOL> CORS ( self . app , resources = re . compile ( '<STR_LIT>' ) ) <EOL> @ self . app . route ( '<STR_LIT:/>' ) <EOL> def index ( ) : <EOL> return '<STR_LIT>' <EOL> @ self . app . route ( '<STR_LIT>' ) <EOL> def example ( ) : <EOL> return '<STR_LIT>' <EOL> for resp in self . iter_responses ( '<STR_LIT:/>' ) : <EOL> self . assertFalse ( ACL_ORIGIN in resp . headers ) <EOL> for resp in self . iter_responses ( '<STR_LIT>' , origin = '<STR_LIT>' ) : <EOL> self . assertTrue ( ACL_ORIGIN in resp . headers ) <EOL> class AppExtensionBadRegexp ( FlaskCorsTestCase ) : <EOL> def test_value_error ( self ) : <EOL> '''<STR_LIT>''' <EOL> self . app = Flask ( __name__ ) <EOL> CORS ( self . app , resources = "<STR_LIT:[>" ) <EOL> @ self . app . route ( '<STR_LIT:/>' ) <EOL> def index ( ) : <EOL> return '<STR_LIT>' <EOL> for resp in self . iter_responses ( '<STR_LIT:/>' ) : <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> unittest . main ( ) </s>
