-
Notifications
You must be signed in to change notification settings - Fork 4
/
test.py
executable file
·83 lines (65 loc) · 2.23 KB
/
test.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
import pushybullet as pb
import sys
import time
from StringIO import StringIO
try:
APIKEY = sys.argv[1]
except IndexError:
print('Please provide API key for tests as the first argument')
sys.exit(0)
# Monkey patch to delete push on cleanup
def push_delete(self):
try:
self.delete()
except:
pass
pb.Push.__del__ = push_delete
tests_started = time.time()
api = pb.PushBullet(APIKEY)
devices = api.devices()
contacts = api.contacts()
me = api.me()
chrome = api['Chrome']
device = api.create_device('Test Stream Device')
push = pb.NotePush('lorem ipsum dolor set amet', title='test note')
# Pushing via API object
api.push(push) # push object to all devices
api.push(push, device) # push object to device object
api.push(push, device.iden) # push object to device iden
api.push('lorem ipsum dolor set amet', device.iden, title='test note') # text/args to device iden
# Pusing via device object
device.push(push) # push object
device.push('lorem ipsum dolor set amet', title='test note') # text/args
# Sending push object itself
push.send(api) # to API object
push.send(device) # to device object
push.send(device.iden) # to device iden
# Deleting push
push.delete()
# List push
push = pb.ListPush(['one', 'two', 'three'])
device.push(push) # push list
device.push(['one', 'two', 'three']) # push list (implicit object)
device.push(['one', 'two', 'three'], type='note') # push list as a note
push.delete()
# File push
s = "lorem ipsum dolor set amet"
push = pb.FilePush(buffer(s), file_type="text/plain", file_name='note.txt')
device.push(push) # push file
device.push(push) # push file again
device.push(StringIO(s), file_name='note.txt') # push file (implicit object)
device.push(StringIO(s), file_name='note.txt', type='note') # push file as a note
device.push(StringIO(s), file_name='note.txt', file_type='application/octet-stream') # push file with custom parameters
push.delete()
# Implicit link push
chrome.push('https://github.com/kstep/pushybullet')
# Deleting device
device.delete()
for contact in api.contacts():
contact.push("test")
# Deleting test pushes
pushes = api.pushes(since=tests_started)
for push in pushes:
push.delete()
print('OK!')