Beispiel #1
0
    def test_add_remove_multiple_channels(self):
        ch1 = "channel-groups-unit-ch1"
        ch2 = "channel-groups-unit-ch2"
        gr = "channel-groups-unit-cg"
        pubnub = PubNub(pnconf_copy())

        # add
        pubnub.add_channel_to_channel_group() \
            .channels([ch1, ch2]) \
            .channel_group(gr) \
            .pn_async(self.callback)

        self.event.wait()
        assert not self.status.is_error()
        assert isinstance(self.response, PNChannelGroupsAddChannelResult)
        self.event.clear()

        time.sleep(1)

        # list
        pubnub.list_channels_in_channel_group() \
            .channel_group(gr) \
            .pn_async(self.callback)

        self.event.wait()
        assert isinstance(self.response, PNChannelGroupsListResult)
        assert len(self.response.channels) == 2
        assert ch1 in self.response.channels
        assert ch2 in self.response.channels
        self.event.clear()

        # remove
        pubnub.remove_channel_from_channel_group() \
            .channels([ch1, ch2]) \
            .channel_group(gr) \
            .pn_async(self.callback)

        self.event.wait()
        assert isinstance(self.response, PNChannelGroupsRemoveChannelResult)
        self.event.clear()

        time.sleep(1)

        # list
        pubnub.list_channels_in_channel_group() \
            .channel_group(gr) \
            .pn_async(self.callback)

        self.event.wait()
        assert isinstance(self.response, PNChannelGroupsListResult)
        assert len(self.response.channels) == 0
        self.event.clear()
Beispiel #2
0
    def test_add_remove_multiple_channels(self):
        ch1 = "channel-groups-unit-ch1"
        ch2 = "channel-groups-unit-ch2"
        gr = "channel-groups-unit-cg"
        pubnub = PubNub(pnconf_copy())

        # add
        pubnub.add_channel_to_channel_group() \
            .channels([ch1, ch2]) \
            .channel_group(gr) \
            .async(self.callback)

        self.event.wait()
        assert not self.status.is_error()
        assert isinstance(self.response, PNChannelGroupsAddChannelResult)
        self.event.clear()

        time.sleep(1)

        # list
        pubnub.list_channels_in_channel_group() \
            .channel_group(gr) \
            .async(self.callback)

        self.event.wait()
        assert isinstance(self.response, PNChannelGroupsListResult)
        assert len(self.response.channels) == 2
        assert ch1 in self.response.channels
        assert ch2 in self.response.channels
        self.event.clear()

        # remove
        pubnub.remove_channel_from_channel_group() \
            .channels([ch1, ch2]) \
            .channel_group(gr) \
            .async(self.callback)

        self.event.wait()
        assert isinstance(self.response, PNChannelGroupsRemoveChannelResult)
        self.event.clear()

        time.sleep(1)

        # list
        pubnub.list_channels_in_channel_group() \
            .channel_group(gr) \
            .async(self.callback)

        self.event.wait()
        assert isinstance(self.response, PNChannelGroupsListResult)
        assert len(self.response.channels) == 0
        self.event.clear()
Beispiel #3
0
    def test_single_channel(self):
        ch = "channel-groups-unit-ch"
        gr = "channel-groups-unit-cg"
        pubnub = PubNub(pnconf_copy())

        # add
        pubnub.add_channel_to_channel_group() \
            .channels(ch) \
            .channel_group(gr) \
            .async(self.callback)

        self.event.wait()
        assert not self.status.is_error()
        assert isinstance(self.response, PNChannelGroupsAddChannelResult)
        self.event.clear()

        time.sleep(1)

        # list
        pubnub.list_channels_in_channel_group() \
            .channel_group(gr) \
            .async(self.callback)

        self.event.wait()
        assert isinstance(self.response, PNChannelGroupsListResult)
        assert len(self.response.channels) == 1
        assert self.response.channels[0] == ch
        self.event.clear()

        # remove
        pubnub.remove_channel_from_channel_group() \
            .channels(ch) \
            .channel_group(gr) \
            .async(self.callback)

        self.event.wait()
        assert isinstance(self.response, PNChannelGroupsRemoveChannelResult)
        self.event.clear()

        time.sleep(1)

        # list
        pubnub.list_channels_in_channel_group() \
            .channel_group(gr) \
            .async(self.callback)

        self.event.wait()
        assert isinstance(self.response, PNChannelGroupsListResult)
        assert len(self.response.channels) == 0
        self.event.clear()
Beispiel #4
0
    def test_single_channel(self):
        ch = "channel-groups-unit-ch"
        gr = "channel-groups-unit-cg"
        pubnub = PubNub(pnconf_copy())

        # add
        pubnub.add_channel_to_channel_group() \
            .channels(ch) \
            .channel_group(gr) \
            .pn_async(self.callback)

        self.event.wait()
        assert not self.status.is_error()
        assert isinstance(self.response, PNChannelGroupsAddChannelResult)
        self.event.clear()

        time.sleep(1)

        # list
        pubnub.list_channels_in_channel_group() \
            .channel_group(gr) \
            .pn_async(self.callback)

        self.event.wait()
        assert isinstance(self.response, PNChannelGroupsListResult)
        assert len(self.response.channels) == 1
        assert self.response.channels[0] == ch
        self.event.clear()

        # remove
        pubnub.remove_channel_from_channel_group() \
            .channels(ch) \
            .channel_group(gr) \
            .pn_async(self.callback)

        self.event.wait()
        assert isinstance(self.response, PNChannelGroupsRemoveChannelResult)
        self.event.clear()

        time.sleep(1)

        # list
        pubnub.list_channels_in_channel_group() \
            .channel_group(gr) \
            .pn_async(self.callback)

        self.event.wait()
        assert isinstance(self.response, PNChannelGroupsListResult)
        assert len(self.response.channels) == 0
        self.event.clear()
Beispiel #5
0
    def test_add_remove_multiple_channels(self):
        ch1 = "channel-groups-unit-ch1"
        ch2 = "channel-groups-unit-ch2"
        gr = "channel-groups-unit-cg"
        pubnub = PubNub(pnconf_copy())

        # cleanup
        envelope = pubnub.remove_channel_group() \
            .channel_group(gr) \
            .sync()

        assert isinstance(envelope.result, PNChannelGroupsRemoveGroupResult)

        # add
        envelope = pubnub.add_channel_to_channel_group() \
            .channels([ch1, ch2]) \
            .channel_group(gr) \
            .sync()

        assert isinstance(envelope.result, PNChannelGroupsAddChannelResult)

        time.sleep(1)

        # list
        envelope = pubnub.list_channels_in_channel_group() \
            .channel_group(gr) \
            .sync()

        assert isinstance(envelope.result, PNChannelGroupsListResult)
        assert len(envelope.result.channels) == 2
        assert ch1 in envelope.result.channels
        assert ch2 in envelope.result.channels

        # remove
        envelope = pubnub.remove_channel_from_channel_group() \
            .channels([ch1, ch2]) \
            .channel_group(gr) \
            .sync()

        assert isinstance(envelope.result, PNChannelGroupsRemoveChannelResult)

        time.sleep(1)

        # list
        envelope = pubnub.list_channels_in_channel_group() \
            .channel_group(gr) \
            .sync()

        assert isinstance(envelope.result, PNChannelGroupsListResult)
        assert len(envelope.result.channels) == 0
Beispiel #6
0
    def test_single_channel(self):
        ch = "channel-groups-native-ch"
        gr = "channel-groups-native-cg"
        pubnub = PubNub(pnconf_copy())

        # cleanup
        envelope = pubnub.remove_channel_group() \
            .channel_group(gr) \
            .sync()

        assert isinstance(envelope.result, PNChannelGroupsRemoveGroupResult)

        # add
        envelope = pubnub.add_channel_to_channel_group() \
            .channels(ch) \
            .channel_group(gr) \
            .sync()

        assert isinstance(envelope.result, PNChannelGroupsAddChannelResult)

        time.sleep(2)

        # list
        envelope = pubnub.list_channels_in_channel_group() \
            .channel_group(gr) \
            .sync()

        assert isinstance(envelope.result, PNChannelGroupsListResult)
        assert len(envelope.result.channels) == 1
        assert envelope.result.channels[0] == ch

        # remove
        envelope = pubnub.remove_channel_from_channel_group() \
            .channels(ch) \
            .channel_group(gr) \
            .sync()

        assert isinstance(envelope.result, PNChannelGroupsRemoveChannelResult)

        time.sleep(2)

        # list
        envelope = pubnub.list_channels_in_channel_group() \
            .channel_group(gr) \
            .sync()

        assert isinstance(envelope.result, PNChannelGroupsListResult)
        assert len(envelope.result.channels) == 0
Beispiel #7
0
pnconfig.subscribe_key = "sub-c-7ba2ac4c-4836-11e6-85a4-0619f8945a4f"
pnconfig.secret_key = "sec-c-MGFkMjQxYjMtNTUxZC00YzE3LWFiZGYtNzUwMjdjNmM3NDhk"

pubnub = PubNub(pnconfig)


def grant_handler(result, status):
    if status.is_error():
        # handle error
        return

    print(result)


pubnub.add_channel_to_channel_group().\
    channels(["ch1", "ch2"]).\
    channel_group("cg1").\
    sync()

pubnub.list_channels_in_channel_group().\
    channel_group("cg1").\
    sync()

pubnub.remove_channel_from_channel_group().\
    channels(["ch1", "ch2"]).\
    channel_group("cg1").\
    sync()

pubnub.remove_channel_group().\
    channel_group("cg1").sync()