Пример #1
0
def test_unsubscribe_raises_error(session):
    topic = "http://test.com"

    with pytest.raises(SubscriberError):
        subscriber.unsubscribe(topic=topic)

    feed = Feed(topic=topic).save()

    with pytest.raises(SubscriberError):
        subscriber.unsubscribe(topic=topic)

    feed.is_push = True

    with pytest.raises(SubscriberError):
        subscriber.unsubscribe(topic=topic)

    feed.hub = "http://test.com/hub"

    with pytest.raises(SubscriberError):
        subscriber.unsubscribe(topic=topic)

    feed.status = STATUS.UNSUBSCRIBED

    with pytest.raises(SubscriberError):
        subscriber.unsubscribe(topic=topic)
Пример #2
0
    def create_or_activate_feed(
        cls, url: str = "", hub: str = "", feedinfo: StatusFeedInfo = None, user=None
    ):
        """
        Creates a Feed, or sets an existing Feed to active.
        If hub then sets the Feed to use Websub.
        If feedinfo then updates the Feed information from feedinfo.
        If user then sets Feed user.

        :param hub: Websub hub URL
        :param user: User who created the feed
        :param url: Feed URL
        :param feedinfo: StatusFeedInfo object
        :return: Feed
        """
        if not url and not feedinfo and not feedinfo.url:
            raise AttributeError("Must have either Url or StatusFeedInfo")

        if feedinfo:
            url = url if url else feedinfo.url
            if not hub and feedinfo.hubs:
                hub = feedinfo.hubs[0]

        if not validators.url(url):
            raise ValueError("URL arg is not a valid URL")

        app.logger.info("Creating or activating Feed with URL %s", url)

        feed = Feed.query.filter_by(topic=url).first()
        if feed:
            app.logger.info("%s activated", feed)
        else:
            feed = Feed(topic=url)
            if user:
                app.logger.info("%s created by %s", feed, user)
                feed.user = user
            else:
                app.logger.info("%s created", feed)

        if feedinfo:
            feed.update_from_feed_info(feedinfo)

        # Sets the Feed to use Websub
        if hub:
            feed.hub = hub
            feed.is_push = True

        # If not Websub feed then set Feed as Fetch only
        if not feed.is_push:
            feed.fetch = True

        # Set the Feed to fetch on the next fetch task
        feed.set_next_scheduled_update(frequency=0, range_percent=0)
        feed.active = True

        feed.save()

        return feed