@@ -89,6 +89,43 @@ def test_set_explicit(self):
8989 self ._test_with_environ ({}, DATASET_ID , dataset_id = DATASET_ID )
9090
9191
92+ class Test_set_default_connection (unittest2 .TestCase ):
93+
94+ def setUp (self ):
95+ from gcloud .datastore import _implicit_environ
96+ self ._replaced_connection = _implicit_environ .CONNECTION
97+ _implicit_environ .CONNECTION = None
98+
99+ def tearDown (self ):
100+ from gcloud .datastore import _implicit_environ
101+ _implicit_environ .CONNECTION = self ._replaced_connection
102+
103+ def _callFUT (self , connection = None ):
104+ from gcloud .datastore import set_default_connection
105+ return set_default_connection (connection = connection )
106+
107+ def test_set_explicit (self ):
108+ from gcloud .datastore import _implicit_environ
109+
110+ self .assertEqual (_implicit_environ .CONNECTION , None )
111+ fake_cnxn = object ()
112+ self ._callFUT (connection = fake_cnxn )
113+ self .assertEqual (_implicit_environ .CONNECTION , fake_cnxn )
114+
115+ def test_set_implicit (self ):
116+ from gcloud ._testing import _Monkey
117+ from gcloud import datastore
118+ from gcloud .datastore import _implicit_environ
119+
120+ self .assertEqual (_implicit_environ .CONNECTION , None )
121+
122+ fake_cnxn = object ()
123+ with _Monkey (datastore , get_connection = lambda : fake_cnxn ):
124+ self ._callFUT ()
125+
126+ self .assertEqual (_implicit_environ .CONNECTION , fake_cnxn )
127+
128+
92129class Test_get_dataset (unittest2 .TestCase ):
93130
94131 def _callFUT (self , dataset_id ):
0 commit comments