text: # -*- coding: utf-8 -*-
  
  from __future__ import print_function, absolute_import, division
  
  import unittest
  
  from pusher import Config, Pusher
  from pusher.util import GET
  
  try:
      import unittest.mock as mock
  except ImportError:
      import mock
  
  class TestPusher(unittest.TestCase):
      def setUp(self):
          self.pusher = Pusher(config=Config.from_url(u'http://key:secret@somehost/apps/4'))
  
      def test_trigger_success_case(self):
          json_dumped = u'{"message": "hello world"}'
  
          with mock.patch('json.dumps', return_value=json_dumped) as json_dumps_mock:
              request = self.pusher.trigger.make_request([u'some_channel'], u'some_event', {u'message': u'hello world'})
  
              self.assertEqual(request.path, u'/apps/4/events')
              self.assertEqual(request.method, u'POST')
  
              expected_params = {
                  u'channels': [u'some_channel'],
                  u'data': json_dumped,
                  u'name': u'some_event'
              }
  
              self.assertEqual(request.params, expected_params)
  
          json_dumps_mock.assert_called_once({u'message': u'hello world'})
  
      def test_trigger_disallow_single_channel(self):
          self.assertRaises(TypeError, lambda:
              self.pusher.trigger.make_request(u'some_channel', u'some_event', {u'message': u'hello world'}))
  
      def test_trigger_disallow_invalid_channels(self):
          self.assertRaises(ValueError, lambda:
              self.pusher.trigger.make_request([u'some_channel!'], u'some_event', {u'message': u'hello world'}))
  
      def test_channels_info_default_success_case(self):
          request = self.pusher.channels_info.make_request()
  
          self.assertEqual(request.method, GET)
          self.assertEqual(request.path, u'/apps/4/channels')
          self.assertEqual(request.params, {})
  
      def test_channels_info_with_prefix_success_case(self):
          request = self.pusher.channels_info.make_request(prefix_filter='test')
  
          self.assertEqual(request.method, GET)
          self.assertEqual(request.path, u'/apps/4/channels')
          self.assertEqual(request.params, {u'filter_by_prefix': u'test'})
  
      def test_channels_info_with_attrs_success_case(self):
          request = self.pusher.channels_info.make_request(attributes=[u'attr1', u'attr2'])
  
          self.assertEqual(request.method, GET)
          self.assertEqual(request.path, u'/apps/4/channels')
          self.assertEqual(request.params, {u'info': u'attr1,attr2'})
  
      def test_channel_info_success_case(self):
          request = self.pusher.channel_info.make_request(u'some_channel')
  
          self.assertEqual(request.method, GET)
          self.assertEqual(request.path, u'/apps/4/channels/some_channel')
          self.assertEqual(request.params, {})
  
      def test_channel_info_with_attrs_success_case(self):
          request = self.pusher.channel_info.make_request(u'some_channel', attributes=[u'attr1', u'attr2'])
  
          self.assertEqual(request.method, GET)
          self.assertEqual(request.path, u'/apps/4/channels/some_channel')
          self.assertEqual(request.params, {u'info': u'attr1,attr2'})
  
      def test_user_info_success_case(self):
          request = self.pusher.users_info.make_request(u'presence-channel')
  
          self.assertEqual(request.method, GET)
          self.assertEqual(request.path, u'/apps/4/channels/presence-channel/users')
          self.assertEqual(request.params, {})
  
  if __name__ == '__main__':
      unittest.main()
  