Commit b745fa26 authored by fendouai's avatar fendouai

add status_code ,add create device test

parent 25300fa5
...@@ -5,4 +5,6 @@ _jpush = jpush.JPush(app_key, master_secret) ...@@ -5,4 +5,6 @@ _jpush = jpush.JPush(app_key, master_secret)
device = _jpush.create_device() device = _jpush.create_device()
reg_id = '1507bfd3f7c466c355c' reg_id = '1507bfd3f7c466c355c'
entity = jpush.device_tag(jpush.add("ddd", "tageee")) entity = jpush.device_tag(jpush.add("ddd", "tageee"))
device.set_devicemobile(reg_id, entity) result=device.set_devicemobile(reg_id, entity)
print result.status_code
print result.payload
\ No newline at end of file
...@@ -66,8 +66,7 @@ class JPushFailure(Exception): ...@@ -66,8 +66,7 @@ class JPushFailure(Exception):
"Request failed with status %d: '%s %s': %s", "Request failed with status %d: '%s %s': %s",
response.status_code, error_code, error, json.dumps(details)) response.status_code, error_code, error, json.dumps(details))
return cls(error, error_code, details, response, response.status_code, return cls(error, error_code, details, response, response.status_code, response.content)
response.content)
class APIConnectionException(Exception): class APIConnectionException(Exception):
......
...@@ -73,6 +73,8 @@ class JPush(object): ...@@ -73,6 +73,8 @@ class JPush(object):
logging.basicConfig(level=logging.DEBUG) logging.basicConfig(level=logging.DEBUG)
if (level == "NOTSET"): if (level == "NOTSET"):
logging.basicConfig(level=logging.NOTSET) logging.basicConfig(level=logging.NOTSET)
else:
print "set logging level failed ,the level is invalid."
else: else:
print "set logging level failed ,the level is invalid." print "set logging level failed ,the level is invalid."
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
from jpush import common from jpush import common
import json import json
class Device(object): class Device(object):
"""Device info query/update.. """Device info query/update..
...@@ -14,8 +15,7 @@ class Device(object): ...@@ -14,8 +15,7 @@ class Device(object):
"""Send the request """Send the request
""" """
response = self._jpush._request(method, body, response = self._jpush._request(method, body, url, content_type, version=3)
url, content_type, version=3)
return DeviceResponse(response) return DeviceResponse(response)
def get_taglist(self): def get_taglist(self):
...@@ -109,7 +109,8 @@ class Device(object): ...@@ -109,7 +109,8 @@ class Device(object):
info = self.send("GET", url, body) info = self.send("GET", url, body)
print (info) print (info)
return info return info
class DeviceResponse(object): class DeviceResponse(object):
"""Response to a successful device request send. """Response to a successful device request send.
...@@ -119,13 +120,18 @@ class DeviceResponse(object): ...@@ -119,13 +120,18 @@ class DeviceResponse(object):
""" """
payload = None payload = None
status_code = None
def __init__(self, response): def __init__(self, response):
self.status_code = response.status_code
if 0 != len(response.content): if 0 != len(response.content):
data = response.json() data = response.json()
self.payload = data self.payload = data
elif 200 == response.status_code: elif 200 == response.status_code:
self.payload = "success" self.payload = "success"
def get_status_code(self):
return self.status_code
def __str__(self): def __str__(self):
return "Device response Payload: {0}".format(self.payload) return "Device response Payload: {0}".format(self.payload)
#!/usr/bin/env python #!/usr/bin/env python
#-*- coding:utf8 -*- # -*- coding:utf8 -*-
import sys import sys
if 2 != sys.version_info[0]: if 2 != sys.version_info[0]:
......
...@@ -5,6 +5,7 @@ from jpush import common ...@@ -5,6 +5,7 @@ from jpush import common
logger = logging.getLogger('jpush') logger = logging.getLogger('jpush')
class Push(object): class Push(object):
"""A push notification. Set audience, message, etc, and send.""" """A push notification. Set audience, message, etc, and send."""
......
app_key = u'6be9204c30b9473e87bad4dc'
master_secret = u'9349ad7c90292a603c512e92'
\ No newline at end of file
import unittest import unittest
import requests from jpush import device
import jpush import jpush as jpush
from conf import app_key, master_secret
_jpush = jpush.JPush(app_key, master_secret)
device = _jpush.create_device()
class TestEntity(unittest.TestCase):
def test_create_device(self):
reg_id = '1507bfd3f7c466c355c'
entity = jpush.device_tag(jpush.add("ddd", "tageee"))
result = device.set_devicemobile(reg_id, entity)
self.assertEqual(result.status_code, 200)
import unittest import unittest
import jpush import jpush
class TestEntity(unittest.TestCase): class TestEntity(unittest.TestCase):
def test_basic_entity(self): def test_basic_entity(self):
......
import unittest import unittest
import jpush as jpush import jpush as jpush
class TestAudience(unittest.TestCase): class TestAudience(unittest.TestCase):
def test_basic_selectors(self): def test_basic_selectors(self):
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
import unittest import unittest
import jpush as jpush import jpush as jpush
class TestMessage(unittest.TestCase): class TestMessage(unittest.TestCase):
def test_simple_alert(self): def test_simple_alert(self):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment