Пример #1
0
    def test_error_forbidden(self):
        pubnub = PubNubTwisted(pnconf_pam_copy())
        with pytest.raises(PubNubTwistedException) as exception:
            yield pubnub.publish().channel("not_permitted_channel").message(
                "hey").deferred()

        self.assertEqual(
            exception.value.status.error_data.information,
            "HTTP Client Error (403): {u'status': 403, u'message': u'Forbidden', u'payload':"
            " {u'channels': [u'not_permitted_channel']}, u'service': u'Access Manager', u'error': True}"
        )
Пример #2
0
    def test_error_invalid_key(self):
        conf = PNConfiguration()
        conf.publish_key = "fake"
        conf.subscribe_key = "demo"
        pubnub = PubNubTwisted(conf)
        with pytest.raises(PubNubTwistedException) as exception:
            yield pubnub.publish().channel(channel).message("hey").deferred()

        self.assertEqual(
            exception.value.status.error_data.information,
            "HTTP Client Error (400): [0, u'Invalid Key', u'14767989321048626']"
        )
import sys

import time

sys.path.append("../../")

from pubnub.callbacks import SubscribeCallback
from pubnub.pnconfiguration import PNConfiguration
from pubnub.pubnub_twisted import PubNubTwisted

pnconf = PNConfiguration()
pnconf.publish_key = "demo"
pnconf.subscribe_key = "demo"
pnconf.enable_subscribe = True

pubnub = PubNubTwisted(pnconf)


class MyListener(SubscribeCallback):
    def status(self, pubnub, status):
        print("status changed: %s" % status)

    def message(self, pubnub, message):
        print("new message: %s" % message)

    def presence(self, pubnub, presence):
        pass


my_listener = MyListener()
Пример #4
0
 def setUp(self):
     self.pool = HTTPConnectionPool(reactor, persistent=False)
     self.pubnub = PubNubTwisted(pnconf, reactor=reactor, pool=self.pool)
Пример #5
0
 def assert_success_encrypted_publish_get(self, message):
     pubnub = PubNubTwisted(pnconf_enc_copy())
     publish = pubnub.publish().channel(channel).message(message)
     envelope = yield self.deferred(publish)
     self.assert_valid_publish_envelope(envelope)
     returnValue(envelope)
Пример #6
0
 def setUp(self):
     pnconf_uuid_set = copy(pnconf)
     pnconf_uuid_set.uuid = 'someuuid'
     self.pool = HTTPConnectionPool(reactor, persistent=False)
     self.pubnub = PubNubTwisted(pnconf_uuid_set, reactor=reactor, pool=self.pool)