<s> from django . http import HttpResponse <EOL> from django . test import RequestFactory <EOL> from django . test . utils import override_settings <EOL> from csp . decorators import csp , csp_replace , csp_update , csp_exempt <EOL> from csp . middleware import CSPMiddleware <EOL> REQUEST = RequestFactory ( ) . get ( '<STR_LIT:/>' ) <EOL> mw = CSPMiddleware ( ) <EOL> def test_csp_exempt ( ) : <EOL> @ csp_exempt <EOL> def view ( request ) : <EOL> return HttpResponse ( ) <EOL> response = view ( REQUEST ) <EOL> assert response . _csp_exempt <EOL> @ override_settings ( CSP_IMG_SRC = [ '<STR_LIT>' ] ) <EOL> def test_csp_update ( ) : <EOL> @ csp_update ( IMG_SRC = '<STR_LIT>' ) <EOL> def view ( request ) : <EOL> return HttpResponse ( ) <EOL> response = view ( REQUEST ) <EOL> assert response . _csp_update == { '<STR_LIT>' : '<STR_LIT>' } <EOL> @ override_settings ( CSP_IMG_SRC = [ '<STR_LIT>' ] ) <EOL> def test_csp_replace ( ) : <EOL> @ csp_replace ( IMG_SRC = '<STR_LIT>' ) <EOL> def view ( request ) : <EOL> return HttpResponse ( ) <EOL> response = view ( REQUEST ) <EOL> assert response . _csp_replace == { '<STR_LIT>' : '<STR_LIT>' } <EOL> def test_csp ( ) : <EOL> @ csp ( IMG_SRC = [ '<STR_LIT>' ] , FONT_SRC = [ '<STR_LIT>' ] ) <EOL> def view ( request ) : <EOL> return HttpResponse ( ) <EOL> response = view ( REQUEST ) <EOL> assert response . _csp_config == { <EOL> '<STR_LIT>' : [ '<STR_LIT>' ] , '<STR_LIT>' : [ '<STR_LIT>' ] <EOL> } <EOL> mw . process_response ( REQUEST , response ) <EOL> policy_list = sorted ( response [ '<STR_LIT>' ] . split ( "<STR_LIT>" ) ) <EOL> assert policy_list == [ "<STR_LIT>" , "<STR_LIT>" ] <EOL> def test_csp_string_values ( ) : <EOL> @ csp ( IMG_SRC = '<STR_LIT>' , FONT_SRC = '<STR_LIT>' ) <EOL> def view ( request ) : <EOL> return HttpResponse ( ) <EOL> response = view ( REQUEST ) <EOL> assert response . _csp_config == { <EOL> '<STR_LIT>' : [ '<STR_LIT>' ] , '<STR_LIT>' : [ '<STR_LIT>' ] <EOL> } <EOL> mw . process_response ( REQUEST , response ) <EOL> policy_list = sorted ( response [ '<STR_LIT>' ] . split ( "<STR_LIT>" ) ) <EOL> assert policy_list == [ "<STR_LIT>" , "<STR_LIT>" ] </s>
