<s> """<STR_LIT>""" <EOL> import re <EOL> import sys <EOL> import unittest <EOL> from simplejson import loads <EOL> from urllib2 import urlopen , Request , URLError <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> VALIDATOR_URL = '<STR_LIT>' <EOL> BASE_URL = '<STR_LIT>' <EOL> MIN_VISITED = <NUM_LIT:12> <EOL> class ValidatorTestCase ( SolaceTestCase ) : <EOL> def doExternalValidation ( self , url , response , content_type ) : <EOL> """<STR_LIT>""" <EOL> request = Request ( VALIDATOR_URL + '<STR_LIT>' , <EOL> response , { '<STR_LIT:Content-Type>' : content_type } ) <EOL> response = urlopen ( request ) <EOL> body = loads ( response . read ( ) ) <EOL> response . close ( ) <EOL> for message in body [ '<STR_LIT>' ] : <EOL> if message [ '<STR_LIT:type>' ] == '<STR_LIT:error>' : <EOL> detail = u'<STR_LIT>' % ( <EOL> message [ '<STR_LIT>' ] , <EOL> message [ '<STR_LIT>' ] , <EOL> message [ '<STR_LIT:message>' ] <EOL> ) <EOL> self . fail ( ( u'<STR_LIT>' % <EOL> ( url , detail ) ) . encode ( '<STR_LIT:utf-8>' ) ) <EOL> def test_pages ( self ) : <EOL> """<STR_LIT>""" <EOL> settings . LANGUAGE_SECTIONS = [ '<STR_LIT>' ] <EOL> user = models . User ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:default>' ) <EOL> user . active = 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 = url . split ( '<STR_LIT:/>' , <NUM_LIT:3> ) [ - <NUM_LIT:1> ] <EOL> response = self . client . get ( path , follow_redirects = True ) <EOL> content_type = response . headers [ '<STR_LIT:Content-Type>' ] <EOL> if content_type . split ( '<STR_LIT:;>' ) [ <NUM_LIT:0> ] . strip ( ) == '<STR_LIT>' : <EOL> self . doExternalValidation ( url , response . data , content_type ) <EOL> for link in html_xpath ( response . html , '<STR_LIT>' ) : <EOL> visit ( link . attrib [ '<STR_LIT>' ] ) <EOL> self . login ( '<STR_LIT>' , '<STR_LIT:default>' ) <EOL> visit ( '<STR_LIT:/>' ) <EOL> def suite ( ) : <EOL> suite = unittest . TestSuite ( ) <EOL> try : <EOL> urlopen ( VALIDATOR_URL ) <EOL> except URLError : <EOL> print >> sys . stderr , '<STR_LIT>' <EOL> return suite <EOL> suite . addTest ( unittest . makeSuite ( ValidatorTestCase ) ) <EOL> return suite <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( defaultTest = '<STR_LIT>' ) </s>
