@@ -26,9 +26,10 @@ def _makeOne(self, *args, **kw):
26
26
27
27
def test_ctor (self ):
28
28
connection = _Connection ()
29
+ client = _Client (connection )
29
30
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 )
32
33
self .assertEqual (iterator .path , PATH )
33
34
self .assertEqual (iterator .page_number , 0 )
34
35
self .assertEqual (iterator .next_page_token , None )
@@ -44,7 +45,8 @@ def _get_items(response):
44
45
for item in response .get ('items' , []):
45
46
yield ITEMS [item ['name' ]]
46
47
connection = _Connection ({'items' : [{'name' : KEY1 }, {'name' : KEY2 }]})
47
- iterator = self ._makeOne (connection , PATH )
48
+ client = _Client (connection )
49
+ iterator = self ._makeOne (client , PATH )
48
50
iterator .get_items_from_response = _get_items
49
51
self .assertEqual (list (iterator ), [ITEM1 , ITEM2 ])
50
52
kw , = connection ._requested
@@ -54,54 +56,61 @@ def _get_items(response):
54
56
55
57
def test_has_next_page_new (self ):
56
58
connection = _Connection ()
59
+ client = _Client (connection )
57
60
PATH = '/foo'
58
- iterator = self ._makeOne (connection , PATH )
61
+ iterator = self ._makeOne (client , PATH )
59
62
self .assertTrue (iterator .has_next_page ())
60
63
61
64
def test_has_next_page_w_number_no_token (self ):
62
65
connection = _Connection ()
66
+ client = _Client (connection )
63
67
PATH = '/foo'
64
- iterator = self ._makeOne (connection , PATH )
68
+ iterator = self ._makeOne (client , PATH )
65
69
iterator .page_number = 1
66
70
self .assertFalse (iterator .has_next_page ())
67
71
68
72
def test_has_next_page_w_number_w_token (self ):
69
73
connection = _Connection ()
74
+ client = _Client (connection )
70
75
PATH = '/foo'
71
76
TOKEN = 'token'
72
- iterator = self ._makeOne (connection , PATH )
77
+ iterator = self ._makeOne (client , PATH )
73
78
iterator .page_number = 1
74
79
iterator .next_page_token = TOKEN
75
80
self .assertTrue (iterator .has_next_page ())
76
81
77
82
def test_get_query_params_no_token (self ):
78
83
connection = _Connection ()
84
+ client = _Client (connection )
79
85
PATH = '/foo'
80
- iterator = self ._makeOne (connection , PATH )
86
+ iterator = self ._makeOne (client , PATH )
81
87
self .assertEqual (iterator .get_query_params (), {})
82
88
83
89
def test_get_query_params_w_token (self ):
84
90
connection = _Connection ()
91
+ client = _Client (connection )
85
92
PATH = '/foo'
86
93
TOKEN = 'token'
87
- iterator = self ._makeOne (connection , PATH )
94
+ iterator = self ._makeOne (client , PATH )
88
95
iterator .next_page_token = TOKEN
89
96
self .assertEqual (iterator .get_query_params (),
90
97
{'pageToken' : TOKEN })
91
98
92
99
def test_get_query_params_extra_params (self ):
93
100
connection = _Connection ()
101
+ client = _Client (connection )
94
102
PATH = '/foo'
95
103
extra_params = {'key' : 'val' }
96
- iterator = self ._makeOne (connection , PATH , extra_params = extra_params )
104
+ iterator = self ._makeOne (client , PATH , extra_params = extra_params )
97
105
self .assertEqual (iterator .get_query_params (), extra_params )
98
106
99
107
def test_get_query_params_w_token_and_extra_params (self ):
100
108
connection = _Connection ()
109
+ client = _Client (connection )
101
110
PATH = '/foo'
102
111
TOKEN = 'token'
103
112
extra_params = {'key' : 'val' }
104
- iterator = self ._makeOne (connection , PATH , extra_params = extra_params )
113
+ iterator = self ._makeOne (client , PATH , extra_params = extra_params )
105
114
iterator .next_page_token = TOKEN
106
115
107
116
expected_query = extra_params .copy ()
@@ -110,9 +119,10 @@ def test_get_query_params_w_token_and_extra_params(self):
110
119
111
120
def test_get_query_params_w_token_collision (self ):
112
121
connection = _Connection ()
122
+ client = _Client (connection )
113
123
PATH = '/foo'
114
124
extra_params = {'pageToken' : 'val' }
115
- self .assertRaises (ValueError , self ._makeOne , connection , PATH ,
125
+ self .assertRaises (ValueError , self ._makeOne , client , PATH ,
116
126
extra_params = extra_params )
117
127
118
128
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):
122
132
KEY2 = 'key2'
123
133
connection = _Connection ({'items' : [{'name' : KEY1 }, {'name' : KEY2 }],
124
134
'nextPageToken' : TOKEN })
125
- iterator = self ._makeOne (connection , PATH )
135
+ client = _Client (connection )
136
+ iterator = self ._makeOne (client , PATH )
126
137
response = iterator .get_next_page_response ()
127
138
self .assertEqual (response ['items' ], [{'name' : KEY1 }, {'name' : KEY2 }])
128
139
self .assertEqual (iterator .page_number , 1 )
@@ -134,16 +145,18 @@ def test_get_next_page_response_new_no_token_in_response(self):
134
145
135
146
def test_get_next_page_response_no_token (self ):
136
147
connection = _Connection ()
148
+ client = _Client (connection )
137
149
PATH = '/foo'
138
- iterator = self ._makeOne (connection , PATH )
150
+ iterator = self ._makeOne (client , PATH )
139
151
iterator .page_number = 1
140
152
self .assertRaises (RuntimeError , iterator .get_next_page_response )
141
153
142
154
def test_reset (self ):
143
155
connection = _Connection ()
156
+ client = _Client (connection )
144
157
PATH = '/foo'
145
158
TOKEN = 'token'
146
- iterator = self ._makeOne (connection , PATH )
159
+ iterator = self ._makeOne (client , PATH )
147
160
iterator .page_number = 1
148
161
iterator .next_page_token = TOKEN
149
162
iterator .reset ()
@@ -153,7 +166,8 @@ def test_reset(self):
153
166
def test_get_items_from_response_raises_NotImplementedError (self ):
154
167
PATH = '/foo'
155
168
connection = _Connection ()
156
- iterator = self ._makeOne (connection , PATH )
169
+ client = _Client (connection )
170
+ iterator = self ._makeOne (client , PATH )
157
171
self .assertRaises (NotImplementedError ,
158
172
iterator .get_items_from_response , object ())
159
173
@@ -168,3 +182,9 @@ def api_request(self, **kw):
168
182
self ._requested .append (kw )
169
183
response , self ._responses = self ._responses [0 ], self ._responses [1 :]
170
184
return response
185
+
186
+
187
+ class _Client (object ):
188
+
189
+ def __init__ (self , connection ):
190
+ self .connection = connection
0 commit comments