diff --git a/README.md b/README.md index e722085..4ab9125 100644 --- a/README.md +++ b/README.md @@ -1,74 +1,14 @@ # JPush API Python Client ## 概述 -这是 JPush REST API 的 Python 版本封装开发包,是由极光推送官方提供的,一般支持最新的 API 功能。 +这是 JPush REST API 的 Python 版本封装开发包,依赖 Hyper: HTTP/2 Client for Python。 + +Hyper: https://github.com/Lukasa/hyper 对应的 REST API 文档: ## 兼容版本 + Python 2.7 -+ Python 3 - -## 环境配置 - -pip 方式: -``` -sudo pip install jpush -``` -easy_install 方式: -``` -sudo easy_install jpush -``` -使用源码方式: -``` -sudo python setup.py install -``` - - -## 代码样例 - -> 代码样例在 jpush-api-python-client 中的 examples 文件夹中,[点击查看所有 examples ](https://github.com/jpush/jpush-api-python-client/tree/master/examples) 。 - -> 以下片断来自项目代码里的文件:jpush-api-python-client 中的 examples/push_examples 目录下的 example_all.py - -> 这个样例演示了消息推送,日志设置,异常处理。 - -``` -_jpush = jpush.JPush(app_key, master_secret) -push = _jpush.create_push() -# if you set the logging level to "DEBUG",it will show the debug logging. -_jpush.set_logging("DEBUG") -push.audience = jpush.all_ -push.notification = jpush.notification(alert="hello python jpush api") -push.platform = jpush.all_ -try: - response=push.send() -except common.Unauthorized: - raise common.Unauthorized("Unauthorized") -except common.APIConnectionException: - raise common.APIConnectionException("conn error") -except common.JPushFailure: - print ("JPushFailure") -except: - print ("Exception") -``` -## 日志说明 -logging level 默认的是 WARNING ,为了方便调试建议设置为 DEBUG -设置方法为: -``` -_jpush.set_logging("DEBUG") -``` - -## 异常说明 - -+ Unauthorized - + AppKey,Master Secret 错误,验证失败必须改正。 - -+ APIConnectionException - + 包含错误的信息:比如超时,无网络等情况。 - -+ JPushFailure - + 请求出错,参考业务返回码。 ## HTTP 状态码 diff --git a/examples/device_examples/conf.py b/examples/device_examples/conf.py index 5b8764c..3fdc12c 100644 --- a/examples/device_examples/conf.py +++ b/examples/device_examples/conf.py @@ -1,3 +1,3 @@ # please put your app_key and master_secret here app_key = u'6be9204c30b9473e87bad4dc' -master_secret = u'9349ad7c90292a603c512e92' +master_secret = u'e62664ad421b67270e5c9d5b' diff --git a/examples/device_examples/example_clrtag.py b/examples/device_examples/example_clrtag.py index 400047f..1d9bc4b 100644 --- a/examples/device_examples/example_clrtag.py +++ b/examples/device_examples/example_clrtag.py @@ -3,6 +3,6 @@ _jpush = jpush.JPush(app_key, master_secret) _jpush.set_logging("DEBUG") device = _jpush.create_device() -reg_id = '090c1f59f89' +reg_id = '160a3797c80d93ce897' entity = jpush.device_tag("") device.set_deviceinfo(reg_id, entity) diff --git a/examples/device_examples/example_getdevice.py b/examples/device_examples/example_getdevice.py index d9afb2f..4fb5751 100644 --- a/examples/device_examples/example_getdevice.py +++ b/examples/device_examples/example_getdevice.py @@ -3,5 +3,5 @@ _jpush = jpush.JPush(app_key, master_secret) _jpush.set_logging("DEBUG") device = _jpush.create_device() -reg_id = '090c1f59f89' +reg_id = '160a3797c80d93ce897' device.get_deviceinfo(reg_id) diff --git a/examples/device_examples/example_tagexist.py b/examples/device_examples/example_tagexist.py index 22a73dc..3321f0e 100644 --- a/examples/device_examples/example_tagexist.py +++ b/examples/device_examples/example_tagexist.py @@ -4,5 +4,5 @@ _jpush.set_logging("DEBUG") device = _jpush.create_device() tag = "ddd" -registration_id = '090c1f59f89' -device.check_taguserexist(tag, registration_id) +reg_id = '160a3797c80d93ce897' +device.check_taguserexist(tag, reg_id) diff --git a/examples/device_examples/example_updevice.py b/examples/device_examples/example_updevice.py index b08f3de..7d5e825 100644 --- a/examples/device_examples/example_updevice.py +++ b/examples/device_examples/example_updevice.py @@ -3,8 +3,7 @@ _jpush = jpush.JPush(app_key, master_secret) _jpush.set_logging("DEBUG") device = _jpush.create_device() -reg_id = '1507bfd3f7c466c355c' +reg_id = '160a3797c80d93ce897' entity = jpush.device_tag(jpush.add("ddd", "tageee")) result=device.set_devicemobile(reg_id, entity) -print (result.status_code) -print (result.payload) \ No newline at end of file +print (result.status_code) \ No newline at end of file diff --git a/examples/device_examples/example_updevicemobile.py b/examples/device_examples/example_updevicemobile.py index f24b027..6b511e3 100644 --- a/examples/device_examples/example_updevicemobile.py +++ b/examples/device_examples/example_updevicemobile.py @@ -3,6 +3,6 @@ _jpush = jpush.JPush(app_key, master_secret) _jpush.set_logging("DEBUG") device = _jpush.create_device() -reg_id = '1507bfd3f7c466c355c' -entity = jpush.device_mobile("18588232140") +reg_id = '160a3797c80d93ce897' +entity = jpush.device_mobile("13488888888") device.set_devicemobile(reg_id, entity) diff --git a/examples/push_examples/conf.py b/examples/push_examples/conf.py index 5b8764c..3fdc12c 100644 --- a/examples/push_examples/conf.py +++ b/examples/push_examples/conf.py @@ -1,3 +1,3 @@ # please put your app_key and master_secret here app_key = u'6be9204c30b9473e87bad4dc' -master_secret = u'9349ad7c90292a603c512e92' +master_secret = u'e62664ad421b67270e5c9d5b' diff --git a/examples/push_examples/example_all.py b/examples/push_examples/example_all.py index 0aa760d..d6fad79 100644 --- a/examples/push_examples/example_all.py +++ b/examples/push_examples/example_all.py @@ -1,6 +1,5 @@ import jpush as jpush from conf import app_key, master_secret -from jpush import common _jpush = jpush.JPush(app_key, master_secret) @@ -11,13 +10,4 @@ push.audience = jpush.all_ push.notification = jpush.notification(alert="hello python jpush api") push.platform = jpush.all_ -try: - response=push.send() -except common.Unauthorized: - raise common.Unauthorized("Unauthorized") -except common.APIConnectionException: - raise common.APIConnectionException("conn") -except common.JPushFailure: - print ("JPushFailure") -except: - print ("Exception") \ No newline at end of file +push.send() diff --git a/examples/report_examples/conf.py b/examples/report_examples/conf.py index 5b8764c..3fdc12c 100644 --- a/examples/report_examples/conf.py +++ b/examples/report_examples/conf.py @@ -1,3 +1,3 @@ # please put your app_key and master_secret here app_key = u'6be9204c30b9473e87bad4dc' -master_secret = u'9349ad7c90292a603c512e92' +master_secret = u'e62664ad421b67270e5c9d5b' diff --git a/examples/report_examples/example_messages.py b/examples/report_examples/example_messages.py index 94d3039..e2e8f5d 100644 --- a/examples/report_examples/example_messages.py +++ b/examples/report_examples/example_messages.py @@ -3,4 +3,4 @@ _jpush = jpush.JPush(app_key, master_secret) _jpush.set_logging("DEBUG") report=_jpush.create_report(); -report.get_messages("3289406737") \ No newline at end of file +print (report.get_messages("3289406737")) \ No newline at end of file diff --git a/examples/report_examples/example_received.py b/examples/report_examples/example_received.py index 7131d5b..a34674f 100644 --- a/examples/report_examples/example_received.py +++ b/examples/report_examples/example_received.py @@ -3,4 +3,4 @@ _jpush = jpush.JPush(app_key, master_secret) _jpush.set_logging("DEBUG") report=_jpush.create_report(); -report.get_received("3289406737") \ No newline at end of file +print (report.get_received("3951136871")) \ No newline at end of file diff --git a/examples/report_examples/example_users.py b/examples/report_examples/example_users.py index 0a4ae79..4642cdb 100644 --- a/examples/report_examples/example_users.py +++ b/examples/report_examples/example_users.py @@ -3,4 +3,4 @@ _jpush = jpush.JPush(app_key, master_secret) _jpush.set_logging("DEBUG") report=_jpush.create_report(); -report.get_users("DAY","2016-04-10","3") \ No newline at end of file +print (report.get_users("DAY","2017-04-10","3")) \ No newline at end of file diff --git a/examples/schedule_examples/conf.py b/examples/schedule_examples/conf.py index 5b8764c..3fdc12c 100644 --- a/examples/schedule_examples/conf.py +++ b/examples/schedule_examples/conf.py @@ -1,3 +1,3 @@ # please put your app_key and master_secret here app_key = u'6be9204c30b9473e87bad4dc' -master_secret = u'9349ad7c90292a603c512e92' +master_secret = u'e62664ad421b67270e5c9d5b' diff --git a/examples/schedule_examples/example_get_schedule.py b/examples/schedule_examples/example_get_schedule.py index 67f44bf..97f8421 100644 --- a/examples/schedule_examples/example_get_schedule.py +++ b/examples/schedule_examples/example_get_schedule.py @@ -3,4 +3,4 @@ _jpush = jpush.JPush(app_key, master_secret) _jpush.set_logging("DEBUG") schedule = _jpush.create_schedule() -schedule.get_schedule_by_id("e9c553d0-0850-11e6-b6d4-0021f652c102") +schedule.get_schedule_by_id("8f2951c8-86cd-11e6-ae78-0021f653c902") diff --git a/examples/schedule_examples/example_post_schedule.py b/examples/schedule_examples/example_post_schedule.py index b92728e..9351033 100644 --- a/examples/schedule_examples/example_post_schedule.py +++ b/examples/schedule_examples/example_post_schedule.py @@ -11,7 +11,7 @@ push.platform = jpush.all_ push=push.payload -trigger=jpush.schedulepayload.trigger("2016-07-17 12:00:00") +trigger=jpush.schedulepayload.trigger("2017-07-17 12:00:00") schedulepayload=jpush.schedulepayload.schedulepayload("name",True,trigger,push) result=schedule.post_schedule(schedulepayload) -print (result.status_code) +print (result) diff --git a/jpush/common.py b/jpush/common.py index e3c1145..a4af66f 100644 --- a/jpush/common.py +++ b/jpush/common.py @@ -2,23 +2,23 @@ import logging import requests -BASE_URL = "https://api.jpush.cn/" -PUSH_URL = BASE_URL + 'v3/push' -VALIDATE_PUSH_URL = BASE_URL + 'v3/push/validate' +PUSH_BASEURL = "api.jpush.cn" +PUSH_URL = '/v3/push' +VALIDATE_PUSH_URL = '/v3/push/validate' -DEVICE_BASEURL = "https://device.jpush.cn/" -DEVICE_URL = DEVICE_BASEURL + "v3/devices/" -TAG_URL = DEVICE_BASEURL + "v3/tags/" +DEVICE_BASEURL = "device.jpush.cn" +DEVICE_URL = "/v3/devices/" +TAG_URL = "/v3/tags/" TAGLIST_URL = TAG_URL -ALIAS_URL = DEVICE_BASEURL + "v3/aliases/" +ALIAS_URL = "/v3/aliases/" -REPORT_BASEURL="https://report.jpush.cn/" -RECEIVED_URL=REPORT_BASEURL+"v3/received?msg_ids=" -MESSAGES_URL=REPORT_BASEURL+"v3/messages?msg_ids=" -USERS_URL=REPORT_BASEURL+"v3/users?" +REPORT_BASEURL="report.jpush.cn" +RECEIVED_URL="/v3/received?msg_ids=" +MESSAGES_URL="/v3/messages?msg_ids=" +USERS_URL="/v3/users?" -BASE_SCHEDULEURL="https://api.jpush.cn/v3/schedules/" -BASE_LISTURL="https://api.jpush.cn/v3/schedules?page=" +BASE_SCHEDULEURL="/v3/schedules/" +BASE_LISTURL="/v3/schedules?page=" logger = logging.getLogger('jpush') diff --git a/jpush/core.py b/jpush/core.py index 47770fb..cdb2078 100644 --- a/jpush/core.py +++ b/jpush/core.py @@ -1,8 +1,9 @@ import json import logging import warnings - +import base64 import requests +from hyper import HTTP20Connection from . import common from .push import Push from .device import Device @@ -20,7 +21,7 @@ def __init__(self, key, secret): self.session = requests.Session() self.session.auth = (key, secret) - def _request(self, method, body, url, content_type=None, version=None, params=None): + def _request(self, method, body, url,base_url=None): headers = {} headers['user-agent'] = 'jpush-api-python-client' headers['connection'] = 'keep-alive' @@ -28,21 +29,18 @@ def _request(self, method, body, url, content_type=None, version=None, params=No logger.debug("Making %s request to %s. Headers:\n\t%s\nBody:\n\t%s", method, url, '\n\t'.join('%s: %s' % (key, value) for (key, value) in headers.items()), body) - try: - response = self.session.request(method, url, data=body, params=params, headers=headers, timeout=30) - except requests.exceptions.ConnectTimeout: - raise common.APIConnectionException("Connection to api.jpush.cn timed out.") - except: - raise common.APIConnectionException("Connection to api.jpush.cn error.") - - logger.debug("Received %s response. Headers:\n\t%s\nBody:\n\t%s", response.status_code, '\n\t'.join( - '%s: %s' % (key, value) for (key, value) in response.headers.items()), response.content) - - if response.status_code == 401: - raise common.Unauthorized("Please check your AppKey and Master Secret") - elif not (200 <= response.status_code < 300): - raise common.JPushFailure.from_response(response) - return response + base64string = base64.encodestring('%s:%s' % (self.key, self.secret))[:-1] + authheader = "Basic %s" % base64string + headers['Authorization'] = authheader + conn = HTTP20Connection(host=base_url, secure=True) + + response = conn.request(method,url,headers=headers,body=body) + resp = conn.get_response(response) + #add status_code to test + resp.status_code=resp.status + logger.debug(resp.status) + logger.debug(resp.read()) + return resp def push(self, payload): """Push this payload to the specified recipients. @@ -50,11 +48,8 @@ def push(self, payload): Payload: a dictionary the contents to send, e.g.: {'aps': {'alert': 'Hello'}, 'android': {'alert': 'Hello'}} """ - warnings.warn( - "JPush.push() is deprecated. See documentation on upgrading.", - DeprecationWarning) body = json.dumps(payload) - self._request('POST', body, common.PUSH_URL, 'application/json', version=1) + self._request('POST', body, common.PUSH_URL, common.PUSH_BASEURL) def set_logging(self, level): level_list= ["CRITICAL", "ERROR", "WARNING", "INFO", "DEBUG", "NOTSET"] @@ -88,4 +83,4 @@ def create_report(self): def create_schedule(self): """Create a Schedule.""" - return Schedule(self) + return Schedule(self) \ No newline at end of file diff --git a/jpush/device/core.py b/jpush/device/core.py index 6c027e8..51c1d58 100644 --- a/jpush/device/core.py +++ b/jpush/device/core.py @@ -1,7 +1,11 @@ #!/usr/bin/env python from jpush import common import json +import base64 +from hyper import HTTP20Connection +import logging +logger = logging.getLogger('jpush') class Device(object): """Device info query/update.. @@ -11,19 +15,33 @@ def __init__(self, jpush): self._jpush = jpush self.entity = None - def send(self, method, url, body, content_type=None, version=3): - """Send the request - - """ - response = self._jpush._request(method, body, url, content_type, version=3) - return DeviceResponse(response) + + def _request(self, method, body, url,base_url=None): + headers = {} + headers['user-agent'] = 'jpush-api-python-client' + headers['connection'] = 'keep-alive' + headers['content-type'] = 'application/json;charset:utf-8' + + logger.debug("Making %s request to %s. Headers:\n\t%s\nBody:\n\t%s", + method, url, '\n\t'.join('%s: %s' % (key, value) for (key, value) in headers.items()), body) + base64string = base64.encodestring('%s:%s' % (self.key, self.secret))[:-1] + authheader = "Basic %s" % base64string + headers['Authorization'] = authheader + conn = HTTP20Connection(host=base_url, secure=True) + + response = conn.request(method,url,headers=headers,body=body) + resp = conn.get_response(response) + logger.debug(resp.status) + logger.debug(resp.read()) + return resp + def get_taglist(self): """Get deviceinfo with registration id. """ url = common.TAGLIST_URL body = None - info = self.send("GET", url, body) + info = self._jpush._request('GET',body,url,base_url=common.DEVICE_BASEURL) return info def get_deviceinfo(self, registration_id): @@ -31,7 +49,7 @@ def get_deviceinfo(self, registration_id): """ url = common.DEVICE_URL + registration_id + "/" body = None - info = self.send("GET", url, body) + info = self._jpush._request('GET', body, url, base_url=common.DEVICE_BASEURL) return info def set_deviceinfo(self, registration_id, entity): @@ -39,7 +57,7 @@ def set_deviceinfo(self, registration_id, entity): """ url = common.DEVICE_URL + registration_id + "/" body = json.dumps(entity) - info = self.send("POST", url, body) + info = self._jpush._request('POST', body, url, base_url=common.DEVICE_BASEURL) return info def set_devicemobile(self, registration_id, entity): @@ -47,7 +65,7 @@ def set_devicemobile(self, registration_id, entity): """ url = common.DEVICE_URL + registration_id + "/" body = json.dumps(entity) - info = self.send("POST", url, body) + info = self._jpush._request('POST', body, url, base_url=common.DEVICE_BASEURL) return info def delete_tag(self, tag, platform=None): @@ -57,7 +75,7 @@ def delete_tag(self, tag, platform=None): body = None if platform: body = platform - info = self.send("DELETE", url, body) + info = self._jpush._request('DELETE', body, url, base_url=common.DEVICE_BASEURL) return info def update_tagusers(self, tag, entity): @@ -65,7 +83,7 @@ def update_tagusers(self, tag, entity): """ url = common.TAG_URL + tag + "/" body = json.dumps(entity) - info = self.send("POST", url, body) + info = self._jpush._request('POST', body, url, base_url=common.DEVICE_BASEURL) return info def check_taguserexist(self, tag, registration_id): @@ -73,7 +91,7 @@ def check_taguserexist(self, tag, registration_id): """ url = common.TAG_URL + tag + "/registration_ids/" + registration_id body = registration_id - info = self.send("GET", url, body) + info = self._jpush._request('GET', body, url, base_url=common.DEVICE_BASEURL) return info def delete_alias(self, alias, platform=None): @@ -83,7 +101,7 @@ def delete_alias(self, alias, platform=None): body = None if platform: body = platform - info = self.send("DELETE", url, body) + info = self._jpush._request('DELETE', body, url, base_url=common.DEVICE_BASEURL) return info def get_aliasuser(self, alias, platform=None): @@ -93,7 +111,7 @@ def get_aliasuser(self, alias, platform=None): body = None if platform: body = platform - info = self.send("GET", url, body) + info = self._jpush._request('GET', body, url, base_url=common.DEVICE_BASEURL) return info diff --git a/jpush/push/core.py b/jpush/push/core.py index 391afa3..7b7ea27 100644 --- a/jpush/push/core.py +++ b/jpush/push/core.py @@ -45,8 +45,8 @@ def send(self): """ body = json.dumps(self.payload) - response = self._jpush._request('POST', body, common.PUSH_URL, 'application/json', version=3) - return PushResponse(response) + response = self._jpush._request('POST',body,common.PUSH_URL,base_url=common.PUSH_BASEURL) + return response def send_validate(self): """Send the notification to validate. @@ -58,28 +58,8 @@ def send_validate(self): """ body = json.dumps(self.payload) - response = self._jpush._request('POST', body, common.VALIDATE_PUSH_URL, 'application/json', version=3) - return PushResponse(response) + response = self._jpush._request('POST', body, common.VALIDATE_PUSH_URL, base_url=common.PUSH_BASEURL) + return response -class PushResponse(object): - """Response to a successful push notification send. - Right now this is a fairly simple wrapper around the json payload response, - but making it an object gives us some flexibility to add functionality - later. - - """ - payload = None - status_code = None - - def __init__(self, response): - self.status_code = response.status_code - data = response.json() - self.payload = data - - def get_status_code(self): - return self.status_code - - def __str__(self): - return "Response Payload: {0}".format(self.payload) diff --git a/jpush/push/payload.py b/jpush/push/payload.py index 3fcdf2f..87e3fb7 100644 --- a/jpush/push/payload.py +++ b/jpush/push/payload.py @@ -70,9 +70,9 @@ def ios(alert=None, badge=None, sound=None, content_available=False, def android(alert, title=None, builder_id=None, extras=None): """Android specific platform override payload. - All keyword arguments are optional. - - :keyword alert: String alert text. + :keyword alert: String alert text.If you set alert to a empty string,then the payload + will not display on notification bar. + more info:https://docs.jiguang.cn/jpush/server/push/rest_api_v3_push/#notification :keyword title: String :keyword builder_id: Integer :keyword extras: A set of key/value pairs to include in the push payload diff --git a/jpush/report/core.py b/jpush/report/core.py index cf7ecaa..f80f11c 100644 --- a/jpush/report/core.py +++ b/jpush/report/core.py @@ -9,28 +9,28 @@ class Report(object): def __init__(self, jpush): self._jpush = jpush - def send(self, method, url, body, content_type=None, version=3): + def send(self, method, body,url,base_url=None): """Send the request """ - response = self._jpush._request(method, body,url,content_type,version=3) - return ReportResponse(response) + response = self._jpush._request(method, body,url,common.REPORT_BASEURL) + return response def get_received(self,msg_ids): url=common.RECEIVED_URL+msg_ids body = None - received = self.send("GET", url, body) + received = self.send("GET", body, url ,common.REPORT_BASEURL) return received def get_messages(self, msg_ids): url = common.MESSAGES_URL + msg_ids body = None - messages = self.send("GET", url, body) + messages = self.send("GET", body, url, common.REPORT_BASEURL) return messages def get_users(self, time_unit,start,duration): url = common.USERS_URL + "time_unit="+time_unit+"&start="+start+"&duration="+duration body = None - users = self.send("GET", url, body) + users = self.send("GET", body, url, common.REPORT_BASEURL) return users diff --git a/jpush/schedule/core.py b/jpush/schedule/core.py index 33ce507..6c0d201 100644 --- a/jpush/schedule/core.py +++ b/jpush/schedule/core.py @@ -10,20 +10,22 @@ class Schedule(object): def __init__(self, jpush): self._jpush = jpush - def send(self, method, url, body, content_type=None, version=3): - response = self._jpush._request(method, body, url, content_type, version=3) - return ScheduleResponse(response) + def send(self, method, body,url,base_url=None): + """Send the request + """ + response = self._jpush._request(method, body,url,common.PUSH_BASEURL) + return response def post_schedule(self, schedulepayload): url=common.BASE_SCHEDULEURL body = json.dumps(schedulepayload) - result = self.send("POST", url, body) + result = self.send("POST", body, url) return result def get_schedule_by_id(self, schedule_id): url=common.BASE_SCHEDULEURL + schedule_id body = None - result = self.send("GET", url, body) + result = self.send("GET", body, url) return result def get_schedule_list(self, page_id): @@ -32,19 +34,19 @@ def get_schedule_list(self, page_id): else: url = common.BASE_LISTURL body = None - result = self.send("GET", url, body) + result = self.send("GET",body,url) return result def put_schedule(self, schedulepayload, schedule_id): url = common.BASE_SCHEDULEURL + schedule_id body = json.dumps(schedulepayload) - result = self.send("PUT", url, body) + result = self.send("PUT", body,url) return result def delete_schedule(self,schedule_id): url = common.BASE_SCHEDULEURL + schedule_id body = None - result = self.send("DELETE", url, body) + result = self.send("DELETE",body,url) return result diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..1feaff5 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,3 @@ +hyper==0.7.0 +requests==2.10.0 +setuptools==23.1.0 diff --git a/tests/conf.py b/tests/conf.py index 5b8764c..3fdc12c 100644 --- a/tests/conf.py +++ b/tests/conf.py @@ -1,3 +1,3 @@ # please put your app_key and master_secret here app_key = u'6be9204c30b9473e87bad4dc' -master_secret = u'9349ad7c90292a603c512e92' +master_secret = u'e62664ad421b67270e5c9d5b' diff --git a/tests/devices/conf.py b/tests/devices/conf.py index 5b8764c..c210c48 100644 --- a/tests/devices/conf.py +++ b/tests/devices/conf.py @@ -1,3 +1,3 @@ # please put your app_key and master_secret here app_key = u'6be9204c30b9473e87bad4dc' -master_secret = u'9349ad7c90292a603c512e92' +master_secret = u'e62664ad421b67270e5c9d5b' \ No newline at end of file diff --git a/tests/devices/test_devices.py b/tests/devices/test_devices.py index 1f72dcb..3bf77ea 100644 --- a/tests/devices/test_devices.py +++ b/tests/devices/test_devices.py @@ -7,12 +7,14 @@ _jpush = jpush.JPush(app_key, master_secret) device = _jpush.create_device() -_jpush.set_logging("DEBUG") +import logging + +logging.basicConfig(level=logging.DEBUG,filename='myapp.log',filemode='w') class TestEntity(unittest.TestCase): def test_create_device(self): - reg_id = '1507bfd3f7c466c355c' + reg_id = '160a3797c80d93ce897' entity = jpush.device_tag(jpush.add("ddd", "tageee")) result = device.set_devicemobile(reg_id, entity) self.assertEqual(result.status_code, 200) @@ -24,7 +26,7 @@ def test_aliasuser(self): self.assertEqual(result.status_code, 200) def test_clear_tag(self): - reg_id = '090c1f59f89' + reg_id = '160a3797c80d93ce897' entity = jpush.device_tag("") try: device.set_deviceinfo(reg_id, entity) @@ -34,7 +36,7 @@ def test_clear_tag(self): self.assertEqual(1, 0) def test_get_device(self): - reg_id = '090c1f59f89' + reg_id = '160a3797c80d93ce897' try: device.get_deviceinfo(reg_id) except common.JPushFailure: @@ -56,7 +58,7 @@ def test_remove_tags(self): def test_tag_exist(self): tag = "ddd" - registration_id = '090c1f59f89' + registration_id = '160a3797c80d93ce897' result = device.check_taguserexist(tag, registration_id) self.assertEqual(result.status_code, 200) @@ -66,18 +68,18 @@ def test_tag_list(self): def test_update_tagusers(self): tag = "ddd" - entity = jpush.device_regid(jpush.add("090c1f59f89")) + entity = jpush.device_regid(jpush.add("160a3797c80d93ce897")) result = device.update_tagusers(tag, entity) self.assertEqual(result.status_code, 200) def test_set_device_mobile(self): - reg_id = '1507bfd3f7c466c355c' - entity = jpush.device_tag(jpush.add("ddd", "tageee")) + reg_id = '160a3797c80d93ce897' + entity = jpush.device_tag(jpush.add("ddd", "tag")) result = device.set_devicemobile(reg_id, entity) self.assertEqual(result.status_code, 200) def test_device_mobile(self): - reg_id = '1507bfd3f7c466c355c' - entity = jpush.device_mobile("18588232140") + reg_id = '160a3797c80d93ce897' + entity = jpush.device_mobile("18588888888") result = device.set_devicemobile(reg_id, entity) self.assertEqual(result.status_code, 200) \ No newline at end of file diff --git a/tests/myapp.log b/tests/myapp.log new file mode 100644 index 0000000..50f8b52 Binary files /dev/null and b/tests/myapp.log differ diff --git a/tests/schedule/test_schedule.py b/tests/schedule/test_schedule.py index 848e459..de62505 100644 --- a/tests/schedule/test_schedule.py +++ b/tests/schedule/test_schedule.py @@ -17,25 +17,25 @@ class TestEntity(unittest.TestCase): def test_post_schedule(self): - trigger = jpush.schedulepayload.trigger("2016-07-17 12:00:00") + trigger = jpush.schedulepayload.trigger("2016-12-17 12:00:00") schedulepayload = jpush.schedulepayload.schedulepayload("name", True, trigger, push) result = schedule.post_schedule(schedulepayload) self.assertEqual(result.status_code, 200) def test_post_schedule_periodical(self): - trigger = jpush.schedulepayload.trigger("12:00:00",start="2016-07-17 12:00:00", end="2016-09-17 12:00:00", + trigger = jpush.schedulepayload.trigger("12:00:00",start="2016-07-17 12:00:00", end="2016-12-17 12:00:00", time_unit = "WEEK", frequency = 1, point = ["WED","FRI"]) schedulepayload = jpush.schedulepayload.schedulepayload("periodical", True, trigger, push) result = schedule.post_schedule(schedulepayload) self.assertEqual(result.status_code, 200) def test_get_schedule_by_id(self): - result = schedule.get_schedule_by_id("3fc6e2fa-15a6-11e6-83d4-0021f653c902") + result = schedule.get_schedule_by_id("a7d5ceea-8e98-11e6-8ea0-0021f652c102") self.assertEqual(result.status_code, 200) def test_get_schedule_by_invalid_id(self): try: - result = schedule.get_schedule_by_id("3fc6e2fa-15a6-11e6-83d4-0021f653c222") + result = schedule.get_schedule_by_id("3fc6e2fa-15a6-11e6-03d4-0021f653c222") self.assertNotEqual(result.status_code, 200) except common.JPushFailure as e: self.assertIsInstance(e, common.JPushFailure) @@ -48,7 +48,7 @@ def test_get_schedule_list(self): pass def test_put_invalid_schedule(self): - trigger = jpush.schedulepayload.trigger("2016-07-17 12:00:00") + trigger = jpush.schedulepayload.trigger("2016-12-17 12:00:00") schedulepayload = jpush.schedulepayload.schedulepayload("update a new name", True, trigger, push) try: result = schedule.put_schedule(schedulepayload, "3fc6e2fa-15a6-11e6-83d4-0021f653c902") @@ -57,7 +57,7 @@ def test_put_invalid_schedule(self): pass def test_put_schedule(self): - trigger = jpush.schedulepayload.trigger("2016-07-17 12:00:00") + trigger = jpush.schedulepayload.trigger("2016-12-17 12:00:00") schedulepayload = jpush.schedulepayload.schedulepayload("update_a_new_name", True, trigger, push) try: result = schedule.put_schedule(schedulepayload, "3fc6e2fa-15a6-11e6-83d4-0021f653c902") @@ -67,7 +67,7 @@ def test_put_schedule(self): def test_delete_schedule(self): try: - result = schedule.delete_schedule("e9c553d0-0850-11e6-b6d4-0021f652c102") + result = schedule.delete_schedule("59272e6a-8e98-11e6-85a9-0021f653c902") self.assertNotEqual(result.status_code, 200) except common.JPushFailure as e: self.assertIsInstance(e, jpush.common.JPushFailure)