Exemplo n.º 1
0
    async def test_admin_channel_subscriptions_remove_where(self):
        save = self.ably.push.admin.channel_subscriptions.save
        remove = self.ably.push.admin.channel_subscriptions.remove_where
        list_ = self.ably.push.admin.channel_subscriptions.list

        channel = 'canpublish:testremovewhere'

        # Subscribe device
        device = self.get_device()
        await save(PushChannelSubscription(channel, device_id=device.id))
        list_response = await list_(channel=channel)
        assert device.id in (x.device_id for x in list_response.items)
        remove_response = await remove(channel=channel, device_id=device.id)
        assert remove_response.status_code == 204
        list_response = await list_(channel=channel)
        assert device.id not in (x.device_id for x in list_response.items)

        # Subscribe client
        client_id = self.get_client_id()
        await save(PushChannelSubscription(channel, client_id=client_id))
        list_response = await list_(channel=channel)
        assert client_id in (x.client_id for x in list_response.items)
        remove_response = await remove(channel=channel, client_id=client_id)
        assert remove_response.status_code == 204
        list_response = await list_(channel=channel)
        assert client_id not in (x.client_id for x in list_response.items)

        # Remove again, it doesn't fail
        remove_response = await remove(channel=channel, client_id=client_id)
        assert remove_response.status_code == 204
Exemplo n.º 2
0
    def test_admin_channel_subscriptions_remove(self):
        save = self.ably.push.admin.channel_subscriptions.save
        remove = self.ably.push.admin.channel_subscriptions.remove
        list_ = self.ably.push.admin.channel_subscriptions.list

        channel = 'canpublish:testremove'

        # Subscribe device
        device = self.get_device()
        subscription = save(
            PushChannelSubscription(channel, device_id=device.id))
        assert device.id in (x.device_id for x in list_(channel=channel).items)
        assert remove(subscription).status_code == 204
        assert device.id not in (x.device_id
                                 for x in list_(channel=channel).items)

        # Subscribe client
        client_id = self.get_client_id()
        subscription = save(
            PushChannelSubscription(channel, client_id=client_id))
        assert client_id in (x.client_id for x in list_(channel=channel).items)
        assert remove(subscription).status_code == 204
        assert client_id not in (x.client_id
                                 for x in list_(channel=channel).items)

        # Remove again, it doesn't fail
        assert remove(subscription).status_code == 204
Exemplo n.º 3
0
    def test_admin_channel_subscriptions_save(self):
        save = self.ably.push.admin.channel_subscriptions.save

        # Subscribe
        device = self.get_device()
        channel = 'canpublish:testsave'
        subscription = self.save_subscription(channel, device_id=device.id)
        assert type(subscription) is PushChannelSubscription
        assert subscription.channel == channel
        assert subscription.device_id == device.id
        assert subscription.client_id is None

        # Failures
        client_id = self.get_client_id()
        with pytest.raises(ValueError):
            PushChannelSubscription(channel,
                                    device_id=device.id,
                                    client_id=client_id)

        subscription = PushChannelSubscription('notallowed',
                                               device_id=device.id)
        with pytest.raises(AblyAuthException):
            save(subscription)

        subscription = PushChannelSubscription(channel,
                                               device_id='notregistered')
        with pytest.raises(AblyException):
            save(subscription)
Exemplo n.º 4
0
 async def save_subscription(self, channel, **kw):
     """
     Helper method to register a device, to not have this code repeated
     everywhere. Returns the input dict that was sent to Ably, and the
     device details returned by Ably.
     """
     subscription = PushChannelSubscription(channel, **kw)
     subscription = await self.ably.push.admin.channel_subscriptions.save(subscription)
     self.channels.setdefault(channel, []).append(subscription)
     return subscription
Exemplo n.º 5
0
 async def remove_subscription(self, channel, **kw):
     subscription = PushChannelSubscription(channel, **kw)
     subscription = await self.ably.push.admin.channel_subscriptions.remove(subscription)
     return subscription