def test_write_header_args_escape(self): c = push.Channel(channel_type='my_channel_type', channel_args={'a': 'b%c'}) headers = {} c.write_header(headers) self.assertEqual('my_channel_type?a=b%25c', headers['X-GOOG-SUBSCRIBE'])
def test_non_get_error(self): m = model.JsonModel() request = http.HttpRequest( None, m.response, 'https://www.googleapis.com/someapi/v1/collection/?foo=bar', method='POST', body='{}', headers={'content-type': 'application/json'}) c = push.Channel('my_channel', {}) self.assertRaises(push.InvalidSubscriptionRequestError, push.Subscription.for_request, request, c)
def test_request_is_post(self): m = model.JsonModel() request = http.HttpRequest( None, m.response, 'https://www.googleapis.com/someapi/v1/collection/?foo=bar', method='GET', body='{}', headers={'content-type': 'application/json'}) c = push.Channel('my_channel', {}) push.Subscription.for_request(request, c) self.assertEqual('POST', request.method)
def test_do_subscribe(self): m = model.JsonModel() request = http.HttpRequest( None, m.response, 'https://www.googleapis.com/someapi/v1/collection/?foo=bar', method='GET', body='{}', headers={'content-type': 'application/json'}) h = http.HttpMockSequence([({ 'status': 200, 'X-Goog-Subscription-ID': 'my_subscription' }, '{}')]) c = push.Channel('my_channel', {}) s = push.Subscription.for_request(request, c) request.execute(http=h) self.assertEqual('my_subscription', s.subscription_id)
def test_write_header_noargs(self): c = push.Channel(channel_type='my_channel_type', channel_args={}) headers = {} c.write_header(headers) self.assertEqual('my_channel_type?', headers['X-GOOG-SUBSCRIBE'])
def test_as_header_value_args_escape(self): c = push.Channel(channel_type='my_channel_type', channel_args={'a': 'b%c'}) self.assertEqual('my_channel_type?a=b%25c', c.as_header_value())
def test_as_header_value_noargs(self): c = push.Channel(channel_type='my_channel_type', channel_args={}) self.assertEqual('my_channel_type?', c.as_header_value())
def test_creation_args(self): c = push.Channel(channel_type='my_channel_type', channel_args={'a': 'b'}) self.assertEqual('my_channel_type', c.channel_type) self.assertEqual({'a': 'b'}, c.channel_args)