示例#1
0
    def test_pub_with_auth(self):
        conf = copy.copy(pnconf)
        conf.auth_key = "my_auth"

        pubnub = MagicMock(
            spec=PubNub,
            config=conf,
            sdk_name=sdk_name,
            uuid="UUID_PublishUnitTest",
            _publish_sequence_manager=self.sm
        )
        pubnub._telemetry_manager = TelemetryManager()
        pub = Publish(pubnub)
        message = "hey"
        encoded_message = url_encode(message)
        pub.channel("ch1").message(message)

        self.assertEquals(pub.build_path(), "/publish/%s/%s/0/ch1/0/%s"
                          % (pnconf.publish_key, pnconf.subscribe_key, encoded_message))

        self.assertEqual(pub.build_params_callback()({}), {
            'pnsdk': sdk_name,
            'uuid': pubnub.uuid,
            'auth': conf.auth_key,
        })
示例#2
0
    def test_pub_message(self):
        message = "hi"
        encoded_message = url_encode(message)

        self.pub.channel("ch1").message(message)

        self.assertEquals(self.pub.build_path(), "/publish/%s/%s/0/ch1/0/%s"
                          % (pnconf.publish_key, pnconf.subscribe_key, encoded_message))

        self.assertEqual(self.pub.build_params_callback()({}), {
            'pnsdk': sdk_name,
            'uuid': self.pubnub.uuid,
        })
示例#3
0
    def test_pub_do_not_store(self):
        self.pubnub.uuid = "UUID_PublishUnitTest"

        message = ["hi", "hi2", "hi3"]
        encoded_message = url_encode(message)

        self.pub.channel("ch1").message(message).should_store(False)

        self.assertEquals(self.pub.build_path(), "/publish/%s/%s/0/ch1/0/%s"
                          % (pnconf.publish_key, pnconf.subscribe_key, encoded_message))

        self.assertEqual(self.pub.build_params_callback()({}), {
            'pnsdk': sdk_name,
            'uuid': self.pubnub.uuid,
            'store': '0',
        })
示例#4
0
    def test_pub_with_meta(self):
        self.pubnub.uuid = "UUID_PublishUnitTest"

        message = ["hi", "hi2", "hi3"]
        encoded_message = url_encode(message)
        meta = ['m1', 'm2']

        self.pub.channel("ch1").message(message).meta(meta)

        self.assertEquals(self.pub.build_path(), "/publish/%s/%s/0/ch1/0/%s"
                          % (pnconf.publish_key, pnconf.subscribe_key, encoded_message))

        self.assertEqual(self.pub.build_params_callback()({}), {
            'pnsdk': sdk_name,
            'uuid': self.pubnub.uuid,
            'meta': '%5B%22m1%22%2C%20%22m2%22%5D',
        })
示例#5
0
from pubnub.pubnub import PubNub
from pubnub.endpoints.pubsub.fire import Fire
from tests.helper import url_encode, pnconf_copy
import json

pnconf = pnconf_copy()

SUB_KEY = pnconf.subscribe_key
PUB_KEY = pnconf.publish_key
CHAN = 'chan'
MSG = 'x'
MSG_ENCODED = url_encode(MSG)
META = ['m1', 'm2']
AUTH = 'auth'


def test_fire():
    pnconf.auth_key = AUTH
    fire = PubNub(pnconf).fire()

    fire.channel(CHAN).message(MSG)
    assert fire.build_path() == Fire.FIRE_GET_PATH % (PUB_KEY, SUB_KEY, CHAN,
                                                      0, MSG_ENCODED)
    fire.use_post(True)
    assert fire.build_path() == Fire.FIRE_POST_PATH % (PUB_KEY, SUB_KEY, CHAN,
                                                       0)

    params = fire.custom_params()
    assert params['store'] == '0'
    assert params['norep'] == '1'