<s> """<STR_LIT>""" <EOL> import re <EOL> import unittest <EOL> from urlparse import urljoin <EOL> from solace . tests import SolaceTestCase , html_xpath <EOL> from solace import models , settings <EOL> from solace . database import session <EOL> BASE_URL = '<STR_LIT>' <EOL> MIN_VISITED = <NUM_LIT:12> <EOL> class LinkCheckTestCase ( SolaceTestCase ) : <EOL> def test_only_valid_links ( self ) : <EOL> """<STR_LIT>""" <EOL> settings . LANGUAGE_SECTIONS = [ '<STR_LIT>' ] <EOL> user = models . User ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:default>' ) <EOL> user . is_admin = True <EOL> banned_user = models . User ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:default>' ) <EOL> banned_user . is_banned = True <EOL> topic = models . Topic ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , user ) <EOL> post1 = models . Post ( topic , user , '<STR_LIT>' ) <EOL> post2 = models . Post ( topic , user , '<STR_LIT>' ) <EOL> topic . accept_answer ( post1 ) <EOL> session . commit ( ) <EOL> visited_links = set ( ) <EOL> def visit ( url ) : <EOL> url = urljoin ( BASE_URL , url ) . split ( '<STR_LIT:#>' , <NUM_LIT:1> ) [ <NUM_LIT:0> ] <EOL> if not url . startswith ( BASE_URL ) or url in visited_links : <EOL> return <EOL> visited_links . add ( url ) <EOL> path = '<STR_LIT:/>' + url . split ( '<STR_LIT:/>' , <NUM_LIT:3> ) [ - <NUM_LIT:1> ] <EOL> if path . startswith ( '<STR_LIT>' ) : <EOL> return <EOL> response = self . client . get ( path , follow_redirects = True ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> for link in html_xpath ( response . html , '<STR_LIT>' ) : <EOL> visit ( link . attrib [ '<STR_LIT>' ] ) <EOL> visit ( '<STR_LIT:/>' ) <EOL> self . assert_ ( len ( visited_links ) > MIN_VISITED ) <EOL> visited_links . clear ( ) <EOL> self . login ( '<STR_LIT>' , '<STR_LIT:default>' ) <EOL> visit ( '<STR_LIT:/>' ) <EOL> self . assert_ ( len ( visited_links ) > MIN_VISITED ) <EOL> def suite ( ) : <EOL> suite = unittest . TestSuite ( ) <EOL> suite . addTest ( unittest . makeSuite ( LinkCheckTestCase ) ) <EOL> return suite <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( defaultTest = '<STR_LIT>' ) </s>
