@@ -92,3 +92,34 @@ def test_scoped_credentials_scopes():
9292def test_scoped_credentials_requires_scopes ():
9393 credentials = ScopedCredentialsImpl ()
9494 assert not credentials .requires_scopes
95+
96+
97+ class RequiresScopedCredentialsImpl (credentials .Scoped , CredentialsImpl ):
98+ def __init__ (self , scopes = None ):
99+ super (RequiresScopedCredentialsImpl , self ).__init__ ()
100+ self ._scopes = scopes
101+
102+ @property
103+ def requires_scopes (self ):
104+ return not self .scopes
105+
106+ def with_scopes (self , scopes ):
107+ return RequiresScopedCredentialsImpl (scopes = scopes )
108+
109+
110+ def test_create_scoped_if_required_scoped ():
111+ unscoped_credentials = RequiresScopedCredentialsImpl ()
112+ scoped_credentials = credentials .with_scopes_if_required (
113+ unscoped_credentials , ['one' , 'two' ])
114+
115+ assert scoped_credentials is not unscoped_credentials
116+ assert not scoped_credentials .requires_scopes
117+ assert scoped_credentials .has_scopes (['one' , 'two' ])
118+
119+
120+ def test_create_scoped_if_required_not_scopes ():
121+ unscoped_credentials = CredentialsImpl ()
122+ scoped_credentials = credentials .with_scopes_if_required (
123+ unscoped_credentials , ['one' , 'two' ])
124+
125+ assert scoped_credentials is unscoped_credentials
0 commit comments