<s> import mock <EOL> from pyramid . authentication import SessionAuthenticationPolicy <EOL> from pyramid . testing import DummyRequest <EOL> import pytest <EOL> from h . auth . policy import AuthenticationPolicy <EOL> SESSION_AUTH_PATHS = ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ) <EOL> TOKEN_AUTH_PATHS = ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ) <EOL> class TestAuthenticationPolicy ( object ) : <EOL> @ pytest . fixture ( autouse = True ) <EOL> def policy ( self ) : <EOL> self . upstream_policy = mock . Mock ( spec_set = SessionAuthenticationPolicy ( ) ) <EOL> self . policy = AuthenticationPolicy ( ) <EOL> self . policy . session_policy = self . upstream_policy <EOL> @ pytest . fixture ( params = SESSION_AUTH_PATHS ) <EOL> def session_request ( self , request ) : <EOL> return DummyRequest ( path = request . param ) <EOL> @ pytest . fixture ( params = TOKEN_AUTH_PATHS ) <EOL> def token_request ( self , request ) : <EOL> return DummyRequest ( path = request . param ) <EOL> def test_authenticated_userid_delegates_for_session_auth_paths ( self , session_request ) : <EOL> result = self . policy . authenticated_userid ( session_request ) <EOL> self . upstream_policy . authenticated_userid . assert_called_once_with ( session_request ) <EOL> assert result == self . upstream_policy . authenticated_userid . return_value <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> def test_authenticated_userid_uses_tokens_for_token_auth_paths ( self , tokens , token_request ) : <EOL> result = self . policy . authenticated_userid ( token_request ) <EOL> tokens . authenticated_userid . assert_called_once_with ( token_request ) <EOL> assert result == tokens . authenticated_userid . return_value <EOL> def test_unauthenticated_userid_delegates_for_session_auth_paths ( self , session_request ) : <EOL> result = self . policy . unauthenticated_userid ( session_request ) <EOL> self . upstream_policy . unauthenticated_userid . assert_called_once_with ( session_request ) <EOL> assert result == self . upstream_policy . unauthenticated_userid . return_value <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> def test_unauthenticated_userid_uses_tokens_for_token_auth_paths ( self , tokens , token_request ) : <EOL> result = self . policy . unauthenticated_userid ( token_request ) <EOL> tokens . authenticated_userid . assert_called_once_with ( token_request ) <EOL> assert result == tokens . authenticated_userid . return_value <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> def test_effective_principals_calls_effective_principals_with_authenticated_userid ( self , util , authn_policy ) : <EOL> authn_policy . authenticated_userid . return_value = '<STR_LIT>' <EOL> request = DummyRequest ( ) <EOL> result = self . policy . effective_principals ( request ) <EOL> util . effective_principals . assert_called_once_with ( '<STR_LIT>' , request ) <EOL> assert result == util . effective_principals . return_value <EOL> def test_remember_delegates_for_session_auth_paths ( self , session_request ) : <EOL> result = self . policy . remember ( session_request , '<STR_LIT:foo>' , bar = '<STR_LIT>' ) <EOL> self . upstream_policy . remember . assert_called_once_with ( session_request , '<STR_LIT:foo>' , bar = '<STR_LIT>' ) <EOL> assert result == self . upstream_policy . remember . return_value <EOL> def test_remember_does_nothing_for_token_auth_paths ( self , token_request ) : <EOL> result = self . policy . remember ( token_request , '<STR_LIT:foo>' , bar = '<STR_LIT>' ) <EOL> self . upstream_policy . remember . assert_not_called ( ) <EOL> assert result == [ ] <EOL> def test_forget_delegates_for_session_auth_paths ( self , session_request ) : <EOL> result = self . policy . forget ( session_request ) <EOL> self . upstream_policy . forget . assert_called_once_with ( session_request ) <EOL> assert result == self . upstream_policy . forget . return_value <EOL> def test_forget_does_nothing_for_token_auth_paths ( self , token_request ) : <EOL> result = self . policy . forget ( token_request ) <EOL> self . upstream_policy . forget . assert_not_called ( ) <EOL> assert result == [ ] </s>
