-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.py
executable file
·83 lines (54 loc) · 1.68 KB
/
tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/env python2.6
#
# tests.py
# wrapper
#
# Created by max klymyshyn on 11/15/09.
# Copyright (c) 2009 Sonettic. All rights reserved.
#
from APNSWrapper import *
def badge(wrapper, token):
message = APNSNotification()
message.tokenBase64(token)
message.badge(3)
print message.build()
wrapper.append(message)
def sound(wrapper, token):
message = APNSNotification()
message.tokenBase64(token)
message.sound("default")
print message.build()
wrapper.append(message)
def alert(wrapper, token):
message = APNSNotification()
message.tokenBase64(token)
alert = APNSAlert()
alert.body("Very important alert message")
alert.loc_key("ALERTMSG")
alert.loc_args(["arg1", "arg2"])
alert.action_loc_key("OPEN")
message.alert(alert)
# properties wrapper
property = APNSProperty("acme", (1, "custom string argument"))
message.appendProperty(property)
print message.build()
wrapper.append(message)
def testAPNSWrapper():
cert_path = 'com.onpatient.phr.pem'
pass_path = 'passphrase.txt'
"""
Method to testing apns-wrapper module.
"""
encoded_token = '0/w68oJxIYlFpDDC/4eeo/bpt/44JTzZ6ZEXEgVvU6c='
wrapper = APNSNotificationWrapper(cert_path, \
sandbox = True, force_ssl_command = True, \
passphrase = pass_path)
badge(wrapper, encoded_token)
sound(wrapper, encoded_token)
alert(wrapper, encoded_token)
wrapper.notify()
feedback = APNSFeedbackWrapper(cert_path, sandbox = True)
feedback.receive()
print "\n".join(["> " + base64.standard_b64encode(y) for x, y in feedback])
if __name__ == "__main__":
testAPNSWrapper()