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)
device = _jpush.create_device()
reg_id = '1507bfd3f7c466c355c'
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):
"Request failed with status %d: '%s %s': %s",
response.status_code, error_code, error, json.dumps(details))
return cls(error, error_code, details, response, response.status_code,
response.content)
return cls(error, error_code, details, response, response.status_code, response.content)
class APIConnectionException(Exception):
......
......@@ -73,6 +73,8 @@ class JPush(object):
logging.basicConfig(level=logging.DEBUG)
if (level == "NOTSET"):
logging.basicConfig(level=logging.NOTSET)
else:
print "set logging level failed ,the level is invalid."
else:
print "set logging level failed ,the level is invalid."
......
......@@ -2,6 +2,7 @@
from jpush import common
import json
class Device(object):
"""Device info query/update..
......@@ -14,8 +15,7 @@ class Device(object):
"""Send the request
"""
response = self._jpush._request(method, body,
url, content_type, version=3)
response = self._jpush._request(method, body, url, content_type, version=3)
return DeviceResponse(response)
def get_taglist(self):
......@@ -109,7 +109,8 @@ class Device(object):
info = self.send("GET", url, body)
print (info)
return info
class DeviceResponse(object):
"""Response to a successful device request send.
......@@ -119,13 +120,18 @@ class DeviceResponse(object):
"""
payload = None
status_code = None
def __init__(self, response):
self.status_code = response.status_code
if 0 != len(response.content):
data = response.json()
self.payload = data
elif 200 == response.status_code:
self.payload = "success"
def get_status_code(self):
return self.status_code
def __str__(self):
return "Device response Payload: {0}".format(self.payload)
#!/usr/bin/env python
#-*- coding:utf8 -*-
# -*- coding:utf8 -*-
import sys
if 2 != sys.version_info[0]:
......
......@@ -5,6 +5,7 @@ from jpush import common
logger = logging.getLogger('jpush')
class Push(object):
"""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 requests
import jpush
from jpush import device
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 jpush
class TestEntity(unittest.TestCase):
def test_basic_entity(self):
......
import unittest
import jpush as jpush
class TestAudience(unittest.TestCase):
def test_basic_selectors(self):
......
......@@ -2,6 +2,7 @@
import unittest
import jpush as jpush
class TestMessage(unittest.TestCase):
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