def test__update_feed_item__update__if_title_exists(self) -> None: link = 'link' data = {'link': link, 'title': self.feed_item.title} FeedItemUpdater._update_feed_item(self.feed, data) self.feed_item.refresh_from_db() self.assertEqual(self.feed_item.link, link)
def test__update_feed_item__update__if_guid_exists(self) -> None: title = 'test2' data = {'id': self.feed_item.guid, 'title': 'test2'} FeedItemUpdater._update_feed_item(self.feed, data) self.feed_item.refresh_from_db() self.assertEqual(self.feed_item.title, title)
def update_feed_item(feed_id: int, feed_item_data: Dict) -> None: """ Update FeedItem based on Feed. :param feed_id: Feed.id for related FeedItem. :param feed_item_data: Dict with parsed FeedItem data. """ try: FeedItemUpdater.update(feed_id, feed_item_data) except Exception as e: logger.error(e)
def test__update_feed_item__create__if_not_exists(self) -> None: title = 'test2' data = {'title': title} feed_item = FeedItemUpdater._update_feed_item(self.feed, data) self.assertNotEqual(feed_item.id, self.feed_item.id) self.assertEqual(feed_item.title, title)
def test__update_categories__replace_old_categories_with_new(self) -> None: FeedItemCategory.objects.create(item=self.feed_item, keyword='old_keyword') new_keyword = 'keyword' data = { 'tags': [{ 'term': 'keyword', }] } FeedItemUpdater._update_categories(self.feed_item, data) category_count = FeedItemCategory.objects.filter( item=self.feed_item).count() self.assertEqual(category_count, 1) feed_item_category = FeedItemCategory.objects.filter( item=self.feed_item).first() self.assertEqual(feed_item_category.keyword, new_keyword)
def test__get_feed__return_feed__if_exists(self) -> None: feed = FeedItemUpdater._get_feed(self.feed.id) self.assertEqual(feed.id, self.feed.id)
def test__get_feed__raise__if_not_exists(self) -> None: with self.assertRaises(FeedUpdaterDoesntExistError): FeedItemUpdater._get_feed(0)
def test__update__return_feed_item__on_valid_data(self) -> None: data = {'title': self.feed_item.title} feed_item = FeedItemUpdater.update(self.feed.id, data) self.assertEqual(self.feed_item.id, feed_item.id)