def setUp(self): self.gcm = gcmclient.GCM(api_key="FakeValue") self.gcm._sender = self._m_request = Mock(spec=requests.post) self._m_response = Mock(spec=requests.Response) self._m_response.return_value = 200 self._m_response.headers = dict() self.m_payload = gcmclient.JSONMessage(registration_ids="some_reg_id", collapse_key="coll_key", time_to_live=60, dry_run=False, data={"foo": "bar"})
def setUp(self): conf = AutopushConfig( hostname="localhost", statsd_host=None, ) self.gcm_config = { 'max_data': 32, 'ttl': 60, 'senderIDs': { 'test123': { "auth": "12345678abcdefg" } } } self.response = Mock(spec=requests.Response) self.response.status_code = 200 self.response.headers = dict() self.response.content = json.dumps({ "multicast_id": 5174939174563864884, "success": 1, "failure": 0, "canonical_ids": 0, "results": [{ "message_id": "0:1510011451922224%7a0e7efbaab8b7cc" }] }) self.gcm = gcmclient.GCM(api_key="SomeKey") self.gcm._sender = Mock(return_value=self.response) self.router = GCMRouter(conf, self.gcm_config, SinkMetrics()) self.router.gcm['test123'] = self.gcm self.headers = { "content-encoding": "aesgcm", "encryption": "test", "encryption-key": "test" } # Payloads are Base64-encoded. self.notif = WebPushNotification( uaid=uuid.UUID(dummy_uaid), channel_id=uuid.UUID(dummy_chid), data="q60d6g", headers=self.headers, ttl=200, message_id=10, ) self.notif.cleanup_headers() self.router_data = dict(router_data=dict( token="connect_data", creds=dict(senderID="test123", auth="12345678abcdefg")))
def setUp(self): self.gcm = gcmclient.GCM(api_key="FakeValue") self.gcm._sender = Mock(spec=treq.request) self._m_request = Deferred() self.gcm._sender.return_value = self._m_request self._m_response = Mock(spec=treq.response._Response) self._m_response.code = 200 self._m_response.headers = Headers() self._m_resp_text = Deferred() self._m_response.text.return_value = self._m_resp_text self.m_payload = gcmclient.JSONMessage( registration_ids="some_reg_id", collapse_key="coll_key", time_to_live=60, dry_run=False, data={"foo": "bar"} )
def __init__(self, conf, router_conf, metrics): """Create a new GCM router and connect to GCM""" self.conf = conf self.router_conf = router_conf self.metrics = metrics self.min_ttl = router_conf.get("ttl", 60) self.dryRun = router_conf.get("dryrun", False) self.collapseKey = router_conf.get("collapseKey") self.gcm = {} self.senderIDs = {} # Flatten the SenderID list from human readable and init gcmclient if not router_conf.get("senderIDs"): raise IOError("SenderIDs not configured.") for sid in router_conf.get("senderIDs"): auth = router_conf.get("senderIDs").get(sid).get("auth") self.senderIDs[sid] = auth self.gcm[sid] = gcmclient.GCM(auth) self._base_tags = ["platform:gcm"] self.log.debug("Starting GCM router...")