Пример #1
0
    def test_news_from_content_article(self):
        """Testing parsing an article"""
        content = self.load_resource(FILE_NEWS_ARTICLE)
        news = News.from_content(content)

        self.assertIsInstance(news, News)
        self.assertEqual(news.category, NewsCategory.DEVELOPMENT)
        self.assertIsInstance(news.date, datetime.date)
        self.assertEqual(news.title, "Sign Up for the VANGUARD Tournament")
        self.assertEqual(news.thread_id, 4725194)
Пример #2
0
    def test_news_from_content_ticker(self):
        """Testing parsing a news ticker"""
        content = self.load_resource(FILE_NEWS_TICKER)
        news = News.from_content(content)

        self.assertIsInstance(news, News)
        self.assertEqual(news.category, NewsCategory.TECHNICAL_ISSUES)
        self.assertIsInstance(news.date, datetime.date)
        self.assertEqual(news.title, "News Ticker")
        self.assertIsNone(news.thread_id)
Пример #3
0
    async def fetch_news(self, news_id):
        """Fetches a news entry by its id from Tibia.com

        Parameters
        ----------
        news_id: :class:`int`
            The id of the news entry.

        Returns
        -------
        :class:`News`
            The news entry if found, ``None`` otherwise.

        Raises
        ------
        Forbidden
            If a 403 Forbidden error was returned.
            This usually means that Tibia.com is rate-limiting the client because of too many requests.
        NetworkError
            If there's any connection errors during the request.
        """
        content = await self._get(News.get_url(news_id))
        news = News.from_content(content, news_id)
        return news
Пример #4
0
 def test_news_from_content_unrelated(self):
     """Testing parsing an unrelated section"""
     content = self.load_resource(self.FILE_UNRELATED_SECTION)
     with self.assertRaises(InvalidContent):
         News.from_content(content)
Пример #5
0
 def test_news_from_content_empty(self):
     """Testing parsing an empty news article"""
     content = self.load_resource(FILE_NEWS_EMPTY)
     news = News.from_content(content)
     self.assertIsNone(news)