@@ -27,6 +27,14 @@ def test_wo_override(self):
2727
2828class Test_get_default_connection (unittest2 .TestCase ):
2929
30+ def setUp (self ):
31+ from gcloud .storage ._testing import _setup_defaults
32+ _setup_defaults (self )
33+
34+ def tearDown (self ):
35+ from gcloud .storage ._testing import _tear_down_defaults
36+ _tear_down_defaults (self )
37+
3038 def _callFUT (self ):
3139 from gcloud .storage ._implicit_environ import get_default_connection
3240 return get_default_connection ()
@@ -99,3 +107,30 @@ def mock_get_connection(*args, **kwargs):
99107 self .assertEqual (_implicit_environ .get_default_connection (), fake_cnxn )
100108 self .assertEqual (_called_args , [()])
101109 self .assertEqual (_called_kwargs , [{}])
110+
111+
112+ class Test_lazy_loading (unittest2 .TestCase ):
113+
114+ def setUp (self ):
115+ from gcloud .storage ._testing import _setup_defaults
116+ _setup_defaults (self , implicit = True )
117+
118+ def tearDown (self ):
119+ from gcloud .storage ._testing import _tear_down_defaults
120+ _tear_down_defaults (self )
121+
122+ def test_descriptor_for_connection (self ):
123+ from gcloud ._testing import _Monkey
124+ from gcloud .storage import _implicit_environ
125+
126+ self .assertFalse (
127+ 'connection' in _implicit_environ ._DEFAULTS .__dict__ )
128+
129+ DEFAULT = object ()
130+
131+ with _Monkey (_implicit_environ , get_connection = lambda : DEFAULT ):
132+ lazy_loaded = _implicit_environ ._DEFAULTS .connection
133+
134+ self .assertEqual (lazy_loaded , DEFAULT )
135+ self .assertTrue (
136+ 'connection' in _implicit_environ ._DEFAULTS .__dict__ )
0 commit comments