@@ -26,9 +26,10 @@ def _makeOne(self, *args, **kw):
2626
2727 def test_ctor (self ):
2828 connection = _Connection ()
29+ client = _Client (connection )
2930 PATH = '/foo'
30- iterator = self ._makeOne (connection , PATH )
31- self .assertTrue (iterator .connection is connection )
31+ iterator = self ._makeOne (client , PATH )
32+ self .assertTrue (iterator .client is client )
3233 self .assertEqual (iterator .path , PATH )
3334 self .assertEqual (iterator .page_number , 0 )
3435 self .assertEqual (iterator .next_page_token , None )
@@ -44,7 +45,8 @@ def _get_items(response):
4445 for item in response .get ('items' , []):
4546 yield ITEMS [item ['name' ]]
4647 connection = _Connection ({'items' : [{'name' : KEY1 }, {'name' : KEY2 }]})
47- iterator = self ._makeOne (connection , PATH )
48+ client = _Client (connection )
49+ iterator = self ._makeOne (client , PATH )
4850 iterator .get_items_from_response = _get_items
4951 self .assertEqual (list (iterator ), [ITEM1 , ITEM2 ])
5052 kw , = connection ._requested
@@ -54,54 +56,61 @@ def _get_items(response):
5456
5557 def test_has_next_page_new (self ):
5658 connection = _Connection ()
59+ client = _Client (connection )
5760 PATH = '/foo'
58- iterator = self ._makeOne (connection , PATH )
61+ iterator = self ._makeOne (client , PATH )
5962 self .assertTrue (iterator .has_next_page ())
6063
6164 def test_has_next_page_w_number_no_token (self ):
6265 connection = _Connection ()
66+ client = _Client (connection )
6367 PATH = '/foo'
64- iterator = self ._makeOne (connection , PATH )
68+ iterator = self ._makeOne (client , PATH )
6569 iterator .page_number = 1
6670 self .assertFalse (iterator .has_next_page ())
6771
6872 def test_has_next_page_w_number_w_token (self ):
6973 connection = _Connection ()
74+ client = _Client (connection )
7075 PATH = '/foo'
7176 TOKEN = 'token'
72- iterator = self ._makeOne (connection , PATH )
77+ iterator = self ._makeOne (client , PATH )
7378 iterator .page_number = 1
7479 iterator .next_page_token = TOKEN
7580 self .assertTrue (iterator .has_next_page ())
7681
7782 def test_get_query_params_no_token (self ):
7883 connection = _Connection ()
84+ client = _Client (connection )
7985 PATH = '/foo'
80- iterator = self ._makeOne (connection , PATH )
86+ iterator = self ._makeOne (client , PATH )
8187 self .assertEqual (iterator .get_query_params (), {})
8288
8389 def test_get_query_params_w_token (self ):
8490 connection = _Connection ()
91+ client = _Client (connection )
8592 PATH = '/foo'
8693 TOKEN = 'token'
87- iterator = self ._makeOne (connection , PATH )
94+ iterator = self ._makeOne (client , PATH )
8895 iterator .next_page_token = TOKEN
8996 self .assertEqual (iterator .get_query_params (),
9097 {'pageToken' : TOKEN })
9198
9299 def test_get_query_params_extra_params (self ):
93100 connection = _Connection ()
101+ client = _Client (connection )
94102 PATH = '/foo'
95103 extra_params = {'key' : 'val' }
96- iterator = self ._makeOne (connection , PATH , extra_params = extra_params )
104+ iterator = self ._makeOne (client , PATH , extra_params = extra_params )
97105 self .assertEqual (iterator .get_query_params (), extra_params )
98106
99107 def test_get_query_params_w_token_and_extra_params (self ):
100108 connection = _Connection ()
109+ client = _Client (connection )
101110 PATH = '/foo'
102111 TOKEN = 'token'
103112 extra_params = {'key' : 'val' }
104- iterator = self ._makeOne (connection , PATH , extra_params = extra_params )
113+ iterator = self ._makeOne (client , PATH , extra_params = extra_params )
105114 iterator .next_page_token = TOKEN
106115
107116 expected_query = extra_params .copy ()
@@ -110,9 +119,10 @@ def test_get_query_params_w_token_and_extra_params(self):
110119
111120 def test_get_query_params_w_token_collision (self ):
112121 connection = _Connection ()
122+ client = _Client (connection )
113123 PATH = '/foo'
114124 extra_params = {'pageToken' : 'val' }
115- self .assertRaises (ValueError , self ._makeOne , connection , PATH ,
125+ self .assertRaises (ValueError , self ._makeOne , client , PATH ,
116126 extra_params = extra_params )
117127
118128 def test_get_next_page_response_new_no_token_in_response (self ):
@@ -122,7 +132,8 @@ def test_get_next_page_response_new_no_token_in_response(self):
122132 KEY2 = 'key2'
123133 connection = _Connection ({'items' : [{'name' : KEY1 }, {'name' : KEY2 }],
124134 'nextPageToken' : TOKEN })
125- iterator = self ._makeOne (connection , PATH )
135+ client = _Client (connection )
136+ iterator = self ._makeOne (client , PATH )
126137 response = iterator .get_next_page_response ()
127138 self .assertEqual (response ['items' ], [{'name' : KEY1 }, {'name' : KEY2 }])
128139 self .assertEqual (iterator .page_number , 1 )
@@ -134,16 +145,18 @@ def test_get_next_page_response_new_no_token_in_response(self):
134145
135146 def test_get_next_page_response_no_token (self ):
136147 connection = _Connection ()
148+ client = _Client (connection )
137149 PATH = '/foo'
138- iterator = self ._makeOne (connection , PATH )
150+ iterator = self ._makeOne (client , PATH )
139151 iterator .page_number = 1
140152 self .assertRaises (RuntimeError , iterator .get_next_page_response )
141153
142154 def test_reset (self ):
143155 connection = _Connection ()
156+ client = _Client (connection )
144157 PATH = '/foo'
145158 TOKEN = 'token'
146- iterator = self ._makeOne (connection , PATH )
159+ iterator = self ._makeOne (client , PATH )
147160 iterator .page_number = 1
148161 iterator .next_page_token = TOKEN
149162 iterator .reset ()
@@ -153,7 +166,8 @@ def test_reset(self):
153166 def test_get_items_from_response_raises_NotImplementedError (self ):
154167 PATH = '/foo'
155168 connection = _Connection ()
156- iterator = self ._makeOne (connection , PATH )
169+ client = _Client (connection )
170+ iterator = self ._makeOne (client , PATH )
157171 self .assertRaises (NotImplementedError ,
158172 iterator .get_items_from_response , object ())
159173
@@ -168,3 +182,9 @@ def api_request(self, **kw):
168182 self ._requested .append (kw )
169183 response , self ._responses = self ._responses [0 ], self ._responses [1 :]
170184 return response
185+
186+
187+ class _Client (object ):
188+
189+ def __init__ (self , connection ):
190+ self .connection = connection
0 commit comments