def test_send(self): request = SubscriptionBatchRequest('abc', 'broadcasts', SubscriptionActionType.REMOVE) response = request.send('abcd123') self.assertIsNotNone(response.subscribers) self.assertEqual(len(response.subscribers), 1) self.assertIsNone(response.error)
def test_token_value_len(self): max = 1000 with self.assertRaises(ValueError): SubscriptionBatchRequest(['abc' for _ in xrange(max + 1)], 'broadcasts', SubscriptionActionType.ADD) SubscriptionBatchRequest(['abc' for _ in xrange(max)], 'broadcasts', SubscriptionActionType.ADD)
def test_str(self): request = SubscriptionBatchRequest('abc', 'broadcasts', SubscriptionActionType.REMOVE) self.assertEqual( str(request), "SubscriptionBatchRequest(tokens=['abc'], topic=/topics/broadcasts, method=v1:batchRemove)" )
def test_iid_info_url(self): for action_type in SubscriptionActionType.batch_actions: method = SubscriptionActionType.BATCH_METHODS[action_type] request = SubscriptionBatchRequest('abc', 'broadcasts', action_type) self.assertEqual( request._batch_url, 'https://iid.googleapis.com/iid/{}'.format(method))
def test_send_api_key_empty(self): request = SubscriptionBatchRequest('abc', 'broadcasts', SubscriptionActionType.REMOVE) with self.assertRaises(ValueError): response = request.send('')
def test_topic(self): request = SubscriptionBatchRequest('abc', '/topics/broadcasts', SubscriptionActionType.ADD) self.assertEqual(request.topic, '/topics/broadcasts')
def test_token_value_mixed(self): with self.assertRaises(ValueError): SubscriptionBatchRequest(['abc', 2], 'broadcasts', SubscriptionActionType.ADD)
def test_tokens_type(self): with self.assertRaises(ValueError): SubscriptionBatchRequest([], 'broadcasts', SubscriptionActionType.ADD)
def test_token_value_none(self): with self.assertRaises(TypeError): SubscriptionBatchRequest(None, 'broadcasts', SubscriptionActionType.ADD)
def test_tokens(self): request = SubscriptionBatchRequest('abc', 'broadcasts', SubscriptionActionType.ADD) self.assertEqual(request.tokens, ['abc'])
def test_action_type(self): with self.assertRaises(ValueError): SubscriptionBatchRequest('abc', 'broadcasts', -1)
def test_action_type(self): SubscriptionBatchRequest('abc', 'broadcasts', SubscriptionActionType.ADD)
def test_topic_empty(self): with self.assertRaises(ValueError): SubscriptionBatchRequest('abc', '', SubscriptionActionType.ADD)
def test_topic_none(self): with self.assertRaises(TypeError): SubscriptionBatchRequest('abc', None, SubscriptionActionType.ADD)