def test_serialize_with_test(): client = APNSProxyClient('localhost', 9999, '10') client.publisher.send = mock.Mock() client.send(TEST_TOKEN, 'Hey Hey', badge=123, test=True) send_data = client.publisher.send.call_args[0][0] body = json.loads(send_data[1:]) eq_(True, body['test'])
def test_serialize_with_badge(): client = APNSProxyClient('localhost', 9999, '10') client.publisher.send = mock.Mock() client.send(TEST_TOKEN, 'Hey Hey', badge=123) send_data = client.publisher.send.call_args[0][0] body = json.loads(send_data[1:]) eq_(123, body['aps']['badge'])
def test_serialize_with_content_available(): client = APNSProxyClient('localhost', 9999, '10') client.publisher.send = mock.Mock() client.send(TEST_TOKEN, 'Hey Hey', content_available=True) send_data = client.publisher.send.call_args[0][0] body = json.loads(send_data[1:]) eq_(True, body['aps']['content_available'])
def test_serialize_with_content_available_False(): client = APNSProxyClient('localhost', 9999, '10') client.publisher.send = mock.Mock() client.send(TEST_TOKEN, 'Hey Hey', content_available=False) send_data = client.publisher.send.call_args[0][0] body = json.loads(send_data[1:]) ok_(not 'content_available' in body)
def test_serialize_with_priority(): client = APNSProxyClient('localhost', 9999, '10') client.publisher.send = mock.Mock() client.send(TEST_TOKEN, 'Hey Hey', priority=5) send_data = client.publisher.send.call_args[0][0] body = json.loads(send_data[1:]) eq_(5, body['priority'])
def test_serialize_with_invalid_json_alert1(): client = APNSProxyClient('localhost', 9999, '10') client.send(TEST_TOKEN, { 'body': 'JSON ALERT', 'action-loc-key': None, 'loc-key': None, 'loc-args': ['one', 'two'], 'launch-image': 'image1' })
def test_serialize_with_expiry(): client = APNSProxyClient('localhost', 9999, '10') client.publisher.send = mock.Mock() one_hour = int(time.time()) + (60 * 60) client.send(TEST_TOKEN, 'Hey Hey', expiry=one_hour) send_data = client.publisher.send.call_args[0][0] body = json.loads(send_data[1:]) eq_(one_hour, body['expiry'])
def test_serialize_with_invalid_json_alert1(): client = APNSProxyClient('localhost', 9999, '10') client.send( TEST_TOKEN, { 'body': 'JSON ALERT', 'action-loc-key': None, 'loc-key': None, 'loc-args': ['one', 'two'], 'launch-image': 'image1' })
def con1(): client = APNSProxyClient(host="localhost", port=5556, application_id="14") with client: print("start send roop 1") cnt = 0 msg = u"これはメッセージです" for i in xrange(100000): cnt += 1 token = "a7ae2fcdb2d325a2de86d572103bff6dd272576d43677544778c43a674407ec1" client.send(token, msg, badge=1, test=True) if i % 3000 == 0: print("Con1 Sended %i" % i)
def main(): client = APNSProxyClient(host="localhost", port=5556, application_id="14") with client: token = valid_token i = 0 interval = 120 while i < 1000: i += 1 client.send(token, 'Hey Hey'+ str(i), badge=i) print("Send %i" % i) if interval < 20 * 60: interval = int(interval * 1.4) time.sleep(interval)
def main(): client = APNSProxyClient(host="localhost", port=5556, application_id="14") with client: token = valid_token i = 0 interval = 120 while i < 1000: i += 1 client.send(token, 'Hey Hey' + str(i), badge=i) print("Send %i" % i) if interval < 20 * 60: interval = int(interval * 1.4) time.sleep(interval)
def test_serialize_silent_message(): client = APNSProxyClient('localhost', 9999, '10') client.publisher.send = mock.Mock() client.send(TEST_TOKEN, None, None, content_available=True) send_data = client.publisher.send.call_args[0][0] eq_(COMMAND_SEND, send_data[:1]) eq_({ 'token': TEST_TOKEN, 'appid': '10', 'test': False, 'aps': { 'content_available': True } }, json.loads(send_data[1:]))
def test_serialize_with_sound(): client = APNSProxyClient('localhost', 9999, '10') client.publisher.send = mock.Mock() client.send(TEST_TOKEN, 'Hey Hey', sound='xxxx') send_data = client.publisher.send.call_args[0][0] eq_(COMMAND_SEND, send_data[:1]) eq_({ 'token': TEST_TOKEN, 'appid': '10', 'test': False, 'aps': { 'alert': 'Hey Hey', 'sound': 'xxxx' } }, json.loads(send_data[1:]))
def test_serialize_silent_message(): client = APNSProxyClient('localhost', 9999, '10') client.publisher.send = mock.Mock() client.send(TEST_TOKEN, None, None, content_available=True) send_data = client.publisher.send.call_args[0][0] eq_(COMMAND_SEND, send_data[:1]) eq_( { 'token': TEST_TOKEN, 'appid': '10', 'test': False, 'aps': { 'content_available': True } }, json.loads(send_data[1:]))
def test_serialize_with_sound(): client = APNSProxyClient('localhost', 9999, '10') client.publisher.send = mock.Mock() client.send(TEST_TOKEN, 'Hey Hey', sound='xxxx') send_data = client.publisher.send.call_args[0][0] eq_(COMMAND_SEND, send_data[:1]) eq_( { 'token': TEST_TOKEN, 'appid': '10', 'test': False, 'aps': { 'alert': 'Hey Hey', 'sound': 'xxxx' } }, json.loads(send_data[1:]))
def test_serialize_with_custom_field(): client = APNSProxyClient('localhost', 9999, '10') client.publisher.send = mock.Mock() client.send(TEST_TOKEN, 'Hey Hey', custom={ 'APP_CUSTOM1': 200, 'APP_CUSTOM2': { 'foo': 'bar', 'boo': False } }) send_data = client.publisher.send.call_args[0][0] body = json.loads(send_data[1:]) eq_({ 'APP_CUSTOM1': 200, 'APP_CUSTOM2': { 'foo': 'bar', 'boo': False } }, body['aps']['custom'])
def test_serialize_with_json_alert(): client = APNSProxyClient('localhost', 9999, '10') client.publisher.send = mock.Mock() client.send(TEST_TOKEN, { 'body': 'JSON ALERT', 'action_loc_key': None, 'loc_key': None, 'loc_args': ['one', 'two'], 'launch_image': 'image1' }) send_data = client.publisher.send.call_args[0][0] body = json.loads(send_data[1:]) eq_({ 'body': 'JSON ALERT', 'action_loc_key': None, 'loc_key': None, 'loc_args': ['one', 'two'], 'launch_image': 'image1' }, body['aps']['alert'])
def test_serialize_with_json_alert(): client = APNSProxyClient('localhost', 9999, '10') client.publisher.send = mock.Mock() client.send( TEST_TOKEN, { 'body': 'JSON ALERT', 'action_loc_key': None, 'loc_key': None, 'loc_args': ['one', 'two'], 'launch_image': 'image1' }) send_data = client.publisher.send.call_args[0][0] body = json.loads(send_data[1:]) eq_( { 'body': 'JSON ALERT', 'action_loc_key': None, 'loc_key': None, 'loc_args': ['one', 'two'], 'launch_image': 'image1' }, body['aps']['alert'])
def main(): client = APNSProxyClient(host="localhost", port=5556, application_id="14") with client: i = 1 client.send(valid_token, "This message should reach " + str(i), badge=i) i += 1 client.send(valid_token, "This message should reach " + str(i), badge=i) i += 1 client.send(invalid_token, "error" + str(i), badge=i) time.sleep(2) i += 1 client.send(valid_token, "This message should reach " + str(i), badge=i) i += 1 client.send(valid_token, "This message should reach " + str(i), badge=i) time.sleep(2) i += 1 client.send(invalid_token, "error" + str(i), badge=i) time.sleep(0.5) i += 1 client.send(valid_token, "This message should reach " + str(i), badge=i) time.sleep(0.5) i += 1 client.send(valid_token, "This message should reach " + str(i), badge=i) time.sleep(0.5) i += 1 client.send(valid_token, "This message should reach " + str(i), badge=i)
def main(): client = APNSProxyClient(host="localhost", port=5556, application_id="myapp") i = 0 with client: token = valid_token client.send(token, 'Alert with default sound') time.sleep(2) client.send(token, 'Alert with custom sound', sound='custom') time.sleep(2) client.send(token, 'I am silent', sound=None) time.sleep(2) client.send(token, 'Alert with badge', badge=2) time.sleep(2) client.send(token, None, badge=99, sound=None) time.sleep(2) one_hour_later = int(time.time()) + (60 * 60) client.send(token, 'I am long life', expiry=one_hour_later) time.sleep(2) client.send(token, 'I am low priority', priority=5) time.sleep(2) # For background fetch client.send(token, None, sound=None, content_available=True) time.sleep(2) client.send(token, 'With custom field', custom={ 'foo': True, 'bar': [200, 300], 'boo': "Hello" }) time.sleep(2) client.send(token, { 'body': 'This is JSON alert', 'action_loc_key': None, 'loc_key': 'loc key', 'loc_args': ['one', 'two'], 'launch_image': 'aa.png' }) client.send(token, 'This message never send to device', test=True)
def main(): client = APNSProxyClient(host="localhost", port=5556, application_id="myapp") i = 0 with client: token = valid_token client.send(token, 'Alert with default sound') time.sleep(2) client.send(token, 'Alert with custom sound', sound='custom') time.sleep(2) client.send(token, 'I am silent', sound=None) time.sleep(2) client.send(token, 'Alert with badge', badge=2) time.sleep(2) client.send(token, None, badge=99, sound=None) time.sleep(2) one_hour_later = int(time.time()) + (60 * 60) client.send(token, 'I am long life', expiry=one_hour_later) time.sleep(2) client.send(token, 'I am low priority', priority=5) time.sleep(2) # For background fetch client.send(token, None, sound=None, content_available=True) time.sleep(2) client.send(token, 'With custom field', custom={ 'foo': True, 'bar': [200, 300], 'boo': "Hello" }) time.sleep(2) client.send( token, { 'body': 'This is JSON alert', 'action_loc_key': None, 'loc_key': 'loc key', 'loc_args': ['one', 'two'], 'launch_image': 'aa.png' }) client.send(token, 'This message never send to device', test=True)
def test_send_method_called(): client = APNSProxyClient('localhost', 9999, '10') client.publisher.send = mock.Mock() client.send(TEST_TOKEN, 'Hey Hey') ok_(client.publisher.send.called)
def test_invalid_token(): client = APNSProxyClient('localhost', 9999, '10') client.send('Invalid Token', 'Hey Hey')
def test_serialize_with_invalid_custom_filed(): client = APNSProxyClient('localhost', 9999, '10') client.send(TEST_TOKEN, 'Go Go', custom='Boooooo')