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
@@ -89,14 +98,29 @@ def test_instance_property_on_connection_default(self):
8998 expected_ua = 'gcloud-python/{0}' .format (gcloud .__version__ )
9099 self .assertEqual (cnxn .user_agent , expected_ua )
91100
101+ def test___get___access_twice (self ):
102+ import gcloud
103+ from gcloud .connection import Connection
104+
105+ expected_ua = 'gcloud-python/{0}' .format (gcloud .__version__ )
106+
107+ self .assertEqual (Connection .user_agent ._user_agent , None )
108+ value = Connection .user_agent .__get__ (_NamedObject ())
109+ self .assertEqual (value , expected_ua )
110+
111+ # Now test using it a second time.
112+ self .assertEqual (Connection .user_agent ._user_agent , expected_ua )
113+ value_again = Connection .user_agent .__get__ (_NamedObject ())
114+ self .assertEqual (value_again , expected_ua )
115+
92116 def test_instance_property_connection_with_appengine (self ):
93117 import gcloud
94118 from gcloud ._testing import _Monkey
95119 from gcloud .connection import Connection
96120
97121 NON_NULL = object ()
98122 with _Monkey (gcloud , appengine = NON_NULL ):
99- local_prop = self ._makeOne (NamedObject ('user_agent' ))
123+ local_prop = self ._makeOne (_NamedObject ('user_agent' ))
100124 with _Monkey (Connection , user_agent = local_prop ):
101125 cnxn = Connection ()
102126 value = cnxn .user_agent
@@ -111,7 +135,7 @@ def test_instance_property_connection_with_compute_engine(self):
111135
112136 HTTPLIB = _Httplib (status = 200 )
113137 with _Monkey (gcloud , httplib = HTTPLIB ):
114- local_prop = self ._makeOne (NamedObject ('user_agent' ))
138+ local_prop = self ._makeOne (_NamedObject ('user_agent' ))
115139 with _Monkey (Connection , user_agent = local_prop ):
116140 cnxn = Connection ()
117141 value = cnxn .user_agent
@@ -120,7 +144,7 @@ def test_instance_property_connection_with_compute_engine(self):
120144 self .assertEqual (value , expected_ua )
121145
122146
123- class NamedObject (object ):
147+ class _NamedObject (object ):
124148
125149 NAME_VAL = object ()
126150
0 commit comments