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
def test_feed_creation(self): topic = 'http://testing.com/feed' hub = 'https://push.superfeedr.com' feed_format = 'json' feed = Feed(topic=topic, hub=hub) feed.save() self.assertEqual(feed.topic, topic) self.assertEqual(feed.hub, hub) self.assertEqual(feed.feed_format, feed_format) self.assertEqual(feed.status, STATUS.UNSUBSCRIBED) self.assertIsNotNone(feed.secret) self.assertIsNotNone(feed.unique_url) secret = feed.secret feed.create_secret() self.assertEqual(feed.secret, secret)
def test_feed_creation(session): topic = "http://testing.com/feed" hub = "https://push.superfeedr.com" feed_format = "atom" feed = Feed(topic=topic, hub=hub) feed.save() assert feed.topic == topic assert feed.hub == hub assert feed.feed_format == feed_format assert feed.status == STATUS.UNSUBSCRIBED assert feed.secret is not None assert feed.unique_url is not None secret = feed.secret feed.create_secret() assert feed.secret == secret