Skip to content

Commit fc686da

Browse files
committed
Added generic make_request_plaintext test.
Factored out response value testing from unicode regression test.
1 parent 2cf94a2 commit fc686da

1 file changed

Lines changed: 28 additions & 6 deletions

File tree

gcm/test.py

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -185,21 +185,43 @@ def test_handle_plaintext_response(self):
185185
self.assertEqual(res, '3456')
186186

187187
@patch('urllib2.urlopen')
188-
def test_make_request_unicode(self, urlopen_mock):
189-
""" Regression: Test make_request with unicode payload. """
188+
def test_make_request_plaintext(self, urlopen_mock):
189+
""" Test plaintext make_request. """
190190

191191
# Set mock value for urlopen return value
192192
urlopen_mock.return_value = MockResponse('blah')
193193

194-
data = {
195-
'message': u'\x80abc'
196-
}
194+
# Perform request
195+
response = self.gcm.make_request({'message': 'test'}, is_json=False)
197196

197+
# Get request (first positional argument to urlopen)
198+
# Ref: http://www.voidspace.org.uk/python/mock/mock.html#mock.Mock.call_args
199+
request = urlopen_mock.call_args[0][0]
200+
201+
# Test encoded data
202+
encoded_data = request.get_data()
198203
self.assertEquals(
199-
self.gcm.make_request(data, is_json=False),
204+
encoded_data, 'message=test'
205+
)
206+
207+
# Assert return value
208+
self.assertEquals(
209+
response,
200210
'blah'
201211
)
202212

213+
214+
@patch('urllib2.urlopen')
215+
def test_make_request_unicode(self, urlopen_mock):
216+
""" Regression: Test make_request with unicode payload. """
217+
218+
# Unicode character in data
219+
data = {
220+
'message': u'\x80abc'
221+
}
222+
223+
self.gcm.make_request(data, is_json=False)
224+
203225
def test_retry_plaintext_request_ok(self):
204226
returns = [GCMUnavailableException(), GCMUnavailableException(), 'id=123456789']
205227

0 commit comments

Comments
 (0)