Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pusher/pusher_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ def trigger_batch(self, batch=[], already_encoded=False):
http://pusher.com/docs/rest_api#method-post-batch-events
"""
if not already_encoded:
batch = [event.copy() for event in batch]
for event in batch:
validate_channel(event['channel'])

Expand Down
24 changes: 24 additions & 0 deletions pusher_tests/test_pusher_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,30 @@


class TestPusherClient(unittest.TestCase):
def test_trigger_batch_preserves_event_data(self):
payload = {'message': 'hello'}
event = {'channel': 'public-test', 'name': 'test', 'data': payload}
self.pusher_client.trigger_batch.make_request([event])
self.assertIs(event['data'], payload)

def test_trigger_batch_can_repeat_encrypted_events(self):
channel = 'private-encrypted-test'
client = PusherClient(
app_id='4', key='key', secret='secret',
encryption_master_key_base64='OHRXNUZRTG5pUTFzQlFGd3J3N3Q2VFZFc0paZDEweVk=',
)
payload = {'message': 'hello'}
batch = [{'channel': channel, 'name': 'test', 'data': payload}]
box = nacl.secret.SecretBox(generate_shared_secret(
channel.encode('utf-8'), client._encryption_master_key))
for _ in range(2):
request = client.trigger_batch.make_request(batch)
encrypted = json.loads(request.params['batch'][0]['data'])
decoded = box.decrypt(base64.b64decode(encrypted['ciphertext']),
base64.b64decode(encrypted['nonce']))
self.assertEqual(json.loads(decoded), payload)
self.assertIs(batch[0]['data'], payload)

def setUp(self):
self.pusher_client = PusherClient(app_id=u'4', key=u'key', secret=u'secret', host=u'somehost')

Expand Down