1717
1818class Test__UserAgentReifyProperty (unittest2 .TestCase ):
1919
20+ def setUp (self ):
21+ from gcloud .connection import Connection
22+ self ._original_connection_user_agent = Connection .user_agent
23+ Connection .user_agent = self ._makeOne (_NamedObject ('user_agent' ))
24+
25+ def tearDown (self ):
26+ from gcloud .connection import Connection
27+ Connection .user_agent = self ._original_connection_user_agent
28+
2029 def _getTargetClass (self ):
2130 from gcloud import _UserAgentReifyProperty
2231 return _UserAgentReifyProperty
@@ -25,8 +34,8 @@ def _makeOne(self, *args, **kw):
2534 return self ._getTargetClass ()(* args , ** kw )
2635
2736 def test_ctor_defaults (self ):
28- ua_prop = self ._makeOne (NamedObject ())
29- self .assertEqual (ua_prop ._property_name , NamedObject .NAME_VAL )
37+ ua_prop = self ._makeOne (_NamedObject ())
38+ self .assertEqual (ua_prop ._property_name , _NamedObject .NAME_VAL )
3039 self .assertEqual (ua_prop ._curr_environ , None )
3140 self .assertEqual (ua_prop ._user_agent , None )
3241
@@ -36,8 +45,8 @@ def test_ctor_appengine_loaded(self):
3645
3746 NON_NULL = object ()
3847 with _Monkey (gcloud , appengine = NON_NULL ):
39- ua_prop = self ._makeOne (NamedObject ())
40- self .assertEqual (ua_prop ._property_name , NamedObject .NAME_VAL )
48+ ua_prop = self ._makeOne (_NamedObject ())
49+ self .assertEqual (ua_prop ._property_name , _NamedObject .NAME_VAL )
4150 self .assertEqual (ua_prop ._curr_environ , '-GAE' )
4251 self .assertEqual (ua_prop ._user_agent , None )
4352
@@ -100,14 +109,29 @@ def test_instance_property_on_connection_default(self):
100109 expected_ua = 'gcloud-python/{0}' .format (gcloud .__version__ )
101110 self .assertEqual (cnxn .user_agent , expected_ua )
102111
112+ def test___get___access_twice (self ):
113+ import gcloud
114+ from gcloud .connection import Connection
115+
116+ expected_ua = 'gcloud-python/{0}' .format (gcloud .__version__ )
117+
118+ self .assertEqual (Connection .user_agent ._user_agent , None )
119+ value = Connection .user_agent .__get__ (_NamedObject ())
120+ self .assertEqual (value , expected_ua )
121+
122+ # Now test using it a second time.
123+ self .assertEqual (Connection .user_agent ._user_agent , expected_ua )
124+ value_again = Connection .user_agent .__get__ (_NamedObject ())
125+ self .assertEqual (value_again , expected_ua )
126+
103127 def test_instance_property_connection_with_appengine (self ):
104128 import gcloud
105129 from gcloud ._testing import _Monkey
106130 from gcloud .connection import Connection
107131
108132 NON_NULL = object ()
109133 with _Monkey (gcloud , appengine = NON_NULL ):
110- local_prop = self ._makeOne (NamedObject ('user_agent' ))
134+ local_prop = self ._makeOne (_NamedObject ('user_agent' ))
111135 with _Monkey (Connection , user_agent = local_prop ):
112136 cnxn = Connection ()
113137 value = cnxn .user_agent
@@ -130,7 +154,7 @@ def _factory(host, timeout):
130154 return CONNECTION
131155
132156 with _Monkey (gcloud , HTTPConnection = _factory ):
133- local_prop = self ._makeOne (NamedObject ('user_agent' ))
157+ local_prop = self ._makeOne (_NamedObject ('user_agent' ))
134158 with _Monkey (Connection , user_agent = local_prop ):
135159 cnxn = Connection ()
136160 value = cnxn .user_agent
@@ -139,7 +163,7 @@ def _factory(host, timeout):
139163 self .assertEqual (value , expected_ua )
140164
141165
142- class NamedObject (object ):
166+ class _NamedObject (object ):
143167
144168 NAME_VAL = object ()
145169
0 commit comments