File tree Expand file tree Collapse file tree 2 files changed +25
-0
lines changed Expand file tree Collapse file tree 2 files changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -322,6 +322,18 @@ cdef class ReadArticle:
322322 """ Get if the article is a redirect"""
323323 return self .c_article.isRedirect()
324324
325+ def get_redirect_article (self ) -> ReadArticle:
326+ """ Target ReadArticle of this one """
327+ if not self.is_redirect:
328+ raise RuntimeError("Article is not a redirect")
329+
330+ cdef wrapper.Article art = self .c_article.getRedirectArticle()
331+ if not art.good():
332+ raise RuntimeError (" Redirect article not found" )
333+
334+ article = ReadArticle.from_read_article(art)
335+ return article
336+
325337 def __repr__ (self ):
326338 return f" {self.__class__.__name__}(url={self.longurl}, title=)"
327339
Original file line number Diff line number Diff line change @@ -114,3 +114,16 @@ def test_get_wrong_article(reader):
114114 reader .get_article_by_id (reader .article_count + 100 )
115115 with pytest .raises (RuntimeError ):
116116 reader .get_article ("A/I_do_not_exists" )
117+
118+
119+ def test_redirects (reader ):
120+ # we can access target article from a redirect one
121+ abundante = reader .get_article ("A/Abundante" )
122+ assert abundante .is_redirect
123+ target = abundante .get_redirect_article ()
124+ assert target .longurl != abundante .longurl
125+
126+ # we can't access a target on non-redirect articles
127+ assert target .is_redirect is False
128+ with pytest .raises (RuntimeError ):
129+ target .get_redirect_article ()
You can’t perform that action at this time.
0 commit comments