Esempio n. 1
0
 def setUp(self):
     AsyncTestCase.setUp(self)
     pnconf = PNConfiguration()
     pnconf.publish_key = 'demo'
     pnconf.subscribe_key = 'demo'
     pnconf.enable_subscribe = False
     self.pn = PubNubTornado(pnconf, custom_ioloop=self.io_loop)
Esempio n. 2
0
def test_error_invalid_key(event_loop):
    conf = PNConfiguration()
    conf.publish_key = "fake"
    conf.subscribe_key = "demo"
    conf.enable_subscribe = False

    pubnub = PubNubAsyncio(conf, custom_event_loop=event_loop)

    yield from assert_server_side_error_yield(pubnub.publish().channel(ch).message("hey"), "Invalid Key")
    pubnub.stop()
Esempio n. 3
0
def test_error_invalid_key(event_loop):
    conf = PNConfiguration()
    conf.publish_key = "fake"
    conf.subscribe_key = "demo"
    conf.enable_subscribe = False

    pubnub = PubNubAsyncio(conf, custom_event_loop=event_loop)

    yield from assert_server_side_error_yield(pubnub.publish().channel(ch).message("hey"), "Invalid Key")
    pubnub.stop()
Esempio n. 4
0
    def test_invalid_key(self):
        config = PNConfiguration()
        config.publish_key = "fake"
        config.subscribe_key = "demo"
        config.enable_subscribe = False

        try:
            PubNub(config).publish() \
                .channel("ch1") \
                .message("hey") \
                .sync()

            self.fail(Exception("Should throw exception", 'pnsdk'))
        except PubNubException as e:
            assert "Invalid Key" in str(e)
Esempio n. 5
0
    def test_invalid_key(self):
        config = PNConfiguration()
        config.publish_key = "fake"
        config.subscribe_key = "demo"
        config.enable_subscribe = False

        try:
            PubNub(config).publish() \
                .channel("ch1") \
                .message("hey") \
                .sync()

            self.fail(Exception("Should throw exception", 'pnsdk'))
        except PubNubException as e:
            assert "Invalid Key" in str(e)
Esempio n. 6
0
    def test_invalid_key(self):
        self.invalid_key_message = ""
        config = PNConfiguration()
        config.publish_key = "fake"
        config.subscribe_key = "demo"
        config.enable_subscribe = False

        PubNub(config).publish() \
            .channel("ch1") \
            .message("hey") \
            .async(self.callback)

        self.event.wait()

        assert self.status.is_error()
        assert self.status.category is PNStatusCategory.PNBadRequestCategory
        assert self.status.original_response[0] is 0
        assert self.status.original_response[1] == 'Invalid Key'
        assert "HTTP Client Error (400):" in str(self.status.error_data.exception)
        assert "Invalid Key" in str(self.status.error_data.exception)
    def test_invalid_key(self):
        self.invalid_key_message = ""
        config = PNConfiguration()
        config.publish_key = "fake"
        config.subscribe_key = "demo"
        config.enable_subscribe = False

        PubNub(config).publish() \
            .channel("ch1") \
            .message("hey") \
            .pn_async(self.callback)

        self.event.wait()

        assert self.status.is_error()
        assert self.status.category is PNStatusCategory.PNBadRequestCategory
        assert self.status.original_response[0] == 0
        assert self.status.original_response[1] == 'Invalid Key'
        assert "HTTP Client Error (400):" in str(
            self.status.error_data.exception)
        assert "Invalid Key" in str(self.status.error_data.exception)
# PubNub HereNow usage example
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()
Esempio n. 9
0
pub_key = "pub-c-739aa0fc-3ed5-472b-af26-aca1b333ec52"
sub_key = "sub-c-33f55052-190b-11e6-bfbc-02ee2ddab7fe"

pub_key_mock = "pub-c-mock-key"
sub_key_mock = "sub-c-mock-key"
uuid_mock = "uuid-mock"

pub_key_pam = "pub-c-98863562-19a6-4760-bf0b-d537d1f5c582"
sub_key_pam = "sub-c-7ba2ac4c-4836-11e6-85a4-0619f8945a4f"
sec_key_pam = "sec-c-MGFkMjQxYjMtNTUxZC00YzE3LWFiZGYtNzUwMjdjNmM3NDhk"

pnconf = PNConfiguration()
pnconf.publish_key = pub_key
pnconf.subscribe_key = sub_key
pnconf.enable_subscribe = False
pnconf.uuid = uuid_mock

pnconf_sub = PNConfiguration()
pnconf_sub.publish_key = pub_key
pnconf_sub.subscribe_key = sub_key
pnconf_sub.uuid = uuid_mock

pnconf_enc = PNConfiguration()
pnconf_enc.publish_key = pub_key
pnconf_enc.subscribe_key = sub_key
pnconf_enc.cipher_key = "testKey"
pnconf_enc.enable_subscribe = False
pnconf_enc.uuid = uuid_mock

pnconf_enc_sub = PNConfiguration()
Esempio n. 10
0
import logging

import asyncio
from pubnub.pnconfiguration import PNConfiguration
from pubnub.pubnub_asyncio import PubNubAsyncio

pnconfig = PNConfiguration()

pnconfig.publish_key = "pub-c-98863562-19a6-4760-bf0b-d537d1f5c582"
pnconfig.subscribe_key = "sub-c-7ba2ac4c-4836-11e6-85a4-0619f8945a4f"
pnconfig.secret_key = "sec-c-MGFkMjQxYjMtNTUxZC00YzE3LWFiZGYtNzUwMjdjNmM3NDhk"
pnconfig.auth_key = "blah"
pnconfig.enable_subscribe = False

pubnub = PubNubAsyncio(pnconfig)


async def grant():
    envelope = await pubnub.grant().auth_keys("blah").channels(
        "history_channel").read(True).write(True).ttl(0).future()
    print("Grant access: %r" % envelope.status.is_error())


logger = logging.getLogger("pubnub")


async def publish500():
    for i in range(0, 500):
        envelope = await pubnub.publish()\
            .message(['message#', i])\
            .channel('history_channel')\
Esempio n. 11
0
from pubnub.pnconfiguration import PNConfiguration

pnconf = PNConfiguration()

pnconf.subscribe_key = "demo"
pnconf.publish_key = "demo"
pnconf.enable_subscribe = False
Esempio n. 12
0
# PubNub HereNow usage example
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

Esempio n. 13
0
try:
    from mock import patch
except ImportError:
    from unittest.mock import patch  # noqa: F401

pub_key = "pub-c-739aa0fc-3ed5-472b-af26-aca1b333ec52"
sub_key = "sub-c-33f55052-190b-11e6-bfbc-02ee2ddab7fe"

pub_key_pam = "pub-c-98863562-19a6-4760-bf0b-d537d1f5c582"
sub_key_pam = "sub-c-7ba2ac4c-4836-11e6-85a4-0619f8945a4f"
sec_key_pam = "sec-c-MGFkMjQxYjMtNTUxZC00YzE3LWFiZGYtNzUwMjdjNmM3NDhk"

pnconf = PNConfiguration()
pnconf.publish_key = pub_key
pnconf.subscribe_key = sub_key
pnconf.enable_subscribe = False

pnconf_sub = PNConfiguration()
pnconf_sub.publish_key = pub_key
pnconf_sub.subscribe_key = sub_key

pnconf_enc = PNConfiguration()
pnconf_enc.publish_key = pub_key
pnconf_enc.subscribe_key = sub_key
pnconf_enc.cipher_key = "testKey"
pnconf_enc.enable_subscribe = False

pnconf_enc_sub = PNConfiguration()
pnconf_enc_sub.publish_key = pub_key
pnconf_enc_sub.subscribe_key = sub_key
pnconf_enc_sub.cipher_key = "testKey"
Esempio n. 14
0
def pnconf():
    pnconf = PNConfiguration()
    pnconf.publish_key = 'demo'
    pnconf.subscribe_key = 'demo'
    pnconf.enable_subscribe = False
    return pnconf