def test_push_msg(self, mock): """Test push_msg works.""" client = PybossaOneSignal(app_id="1", api_key="key") fakeRequest = MagicMock() fakeRequest.status_code = 200 fakeRequest.reason = 'OK' fakeRequest.json.return_value = self.valid_notification mock.return_value = fakeRequest tmp = client.push_msg() assert tmp[0] == 200 assert tmp[1] == 'OK' assert tmp[2] == self.valid_notification
def push_notification(project_id, **kwargs): """Send push notification.""" from pybossa.core import project_repo project = project_repo.get(project_id) if project.info.get('onesignal'): app_id = current_app.config.get('ONESIGNAL_APP_ID') api_key = current_app.config.get('ONESIGNAL_API_KEY') client = PybossaOneSignal(app_id=app_id, api_key=api_key) filters = [{"field": "tag", "key": project_id, "relation": "exists"}] return client.push_msg(contents=kwargs['contents'], headings=kwargs['headings'], launch_url=kwargs['launch_url'], web_buttons=kwargs['web_buttons'], filters=filters)
def push_notification(project_id, **kwargs): """Send push notification.""" from pybossa.core import project_repo project = project_repo.get(project_id) if project.info.get('onesignal'): app_id = current_app.config.get('ONESIGNAL_APP_ID') api_key = current_app.config.get('ONESIGNAL_API_KEY') client = PybossaOneSignal(app_id=app_id, api_key=api_key) filters = [{"field": "tag", "key": project_id, "relation": "exists"}] return client.push_msg(contents=kwargs['contents'], headings=kwargs['headings'], launch_url=kwargs['launch_url'], web_buttons=kwargs['web_buttons'], filters=filters)
def test_push_msg_app_ids(self, mock): """Test push_msg with array app_ids works.""" client = PybossaOneSignal(app_ids=["1", "2"], api_key="key") fakeRequest = MagicMock() fakeRequest.status_code = 200 fakeRequest.reason = 'OK' fakeRequest.json.return_value = self.valid_notification mock.return_value = fakeRequest tmp = client.push_msg() assert tmp[0] == 200 assert tmp[1] == 'OK' assert tmp[2] == self.valid_notification self.payload['app_ids'] = ["1", "2"] mock.assert_called_with(client.api_url, headers=client.header("key"), json=self.payload)
def test_push_msg_include_priority(self, mock): """Test push_msg with array priority works.""" client = PybossaOneSignal(app_id="1", api_key="key") fakeRequest = MagicMock() fakeRequest.status_code = 200 fakeRequest.reason = 'OK' fakeRequest.json.return_value = self.valid_notification mock.return_value = fakeRequest tmp = client.push_msg(priority="10") assert tmp[0] == 200 assert tmp[1] == 'OK' assert tmp[2] == self.valid_notification self.payload['app_id'] = "1" self.payload['priority'] = "10" mock.assert_called_with(client.api_url, headers=client.header("key"), json=self.payload)
def test_push_msg_include_send_after(self, mock): """Test push_msg with array send_after works.""" client = PybossaOneSignal(app_id="1", api_key="key") fakeRequest = MagicMock() fakeRequest.status_code = 200 fakeRequest.reason = 'OK' fakeRequest.json.return_value = self.valid_notification mock.return_value = fakeRequest tmp = client.push_msg(send_after="Thu Sep 24 2015 14:00:00 GMT-0700 (PDT)") assert tmp[0] == 200 assert tmp[1] == 'OK' assert tmp[2] == self.valid_notification self.payload['app_id'] = "1" self.payload['send_after'] = "Thu Sep 24 2015 14:00:00 GMT-0700 (PDT)" mock.assert_called_with(client.api_url, headers=client.header("key"), json=self.payload)
def test_push_msg_no_api_key(self): """Test push_msg without api_key.""" client = PybossaOneSignal(app_id="1", auth_key="something") client.push_msg()