def test_apply_filter(self): config.load(configfile % 'filter') splice.apply(self.feeddata) # verify that index.html is well formed, has content, and xml:lang html = open(os.path.join(workdir, 'index.html')).read() self.assertTrue(html.find(' href="http://example.com/default.css"')>=0)
def test_embedded_license(self): config.load(configfile) for testfeed in testfeeds: doc = splice.splice() splice.apply(doc.toxml('utf-8')) output = open(os.path.join(workdir, 'index.html')).read() self.assertTrue('Attribution 3.0 Unported' in output)
def test_invalid_default_license(self): config.load(configfile) for testfeed in testfeeds: doc = splice.splice() splice.apply(doc.toxml('utf-8')) output = open(os.path.join(workdir, 'index.html')).read() self.assertTrue('title="License information">License</a>' in output)
def test_apply_filter(self): config.load(configfile % 'filter') splice.apply(self.feeddata) # verify that index.html is well formed, has content, and xml:lang html = open(os.path.join(workdir, 'index.html')).read() self.assertTrue( html.find(' href="http://example.com/default.css"') >= 0)
def test_default_license_lookup(self): config.load(configfile) expected_text = 'Reconocimiento-No comercial-Compartir bajo la' + \ ' misma licencia 2.5 Colombia' for testfeed in testfeeds: doc = splice.splice() splice.apply(doc.toxml('utf-8')) output = open(os.path.join(workdir, 'index.html')).read() self.assertTrue(expected_text in output)
def test_apply_fancy(self): config.load(configfile % 'fancy') splice.apply(self.feeddata) # verify that selected files are there for file in ['index.html', 'planet.css', 'images/jdub.png']: path = os.path.join(workdir, file) self.assertTrue(os.path.exists(path), path) self.assertTrue(os.stat(path).st_size > 0) # verify that index.html is well formed, has content, and xml:lang html = open(os.path.join(workdir, 'index.html')).read() self.assertTrue(html.find('<h1>test planet</h1>')>=0) self.assertTrue(html.find( '<h4><a href="http://example.com/2">Venus</a></h4>')>=0)
def apply_fancy(self): # drop slow templates unrelated to test at hand templates = config.parser.get('Planet','template_files').split() templates.remove('rss10.xml.tmpl') templates.remove('rss20.xml.tmpl') config.parser.set('Planet','template_files',' '.join(templates)) splice.apply(self.feeddata) # verify that selected files are there for file in ['index.html', 'planet.css', 'images/jdub.png']: path = os.path.join(workdir, file) self.assertTrue(os.path.exists(path), path) self.assertTrue(os.stat(path).st_size > 0) # verify that index.html is well formed, has content, and xml:lang html = open(os.path.join(workdir, 'index.html')).read() self.assertTrue(html.find('<h1>test planet</h1>')>=0) self.assertTrue(html.find( '<h4><a href="http://example.com/2">Venus</a></h4>')>=0)
def apply_asf(self): splice.apply(self.feeddata) # verify that selected files are there for file in ['index.html', 'default.css', 'images/foaf.png']: path = os.path.join(workdir, file) self.assertTrue(os.path.exists(path)) self.assertTrue(os.stat(path).st_size > 0, file + ' has size 0') # verify that index.html is well formed, has content, and xml:lang html = open(os.path.join(workdir, 'index.html')) doc = minidom.parse(html) list = [] content = lang = 0 for div in doc.getElementsByTagName('div'): if div.getAttribute('class') != 'content': continue content += 1 if div.getAttribute('xml:lang') == 'en-us': lang += 1 html.close() self.assertEqual(12, content) self.assertEqual(3, lang)
def apply_fancy(self): # drop slow templates unrelated to test at hand templates = config.parser.get('Planet', 'template_files').split() templates.remove('rss10.xml.tmpl') templates.remove('rss20.xml.tmpl') config.parser.set('Planet', 'template_files', ' '.join(templates)) splice.apply(self.feeddata) # verify that selected files are there for file in ['index.html', 'planet.css', 'images/jdub.png']: path = os.path.join(workdir, file) self.assertTrue(os.path.exists(path), path) self.assertTrue(os.stat(path).st_size > 0) # verify that index.html is well formed, has content, and xml:lang html = open(os.path.join(workdir, 'index.html')).read() self.assertTrue(html.find('<h1>test planet</h1>') >= 0) self.assertTrue( html.find('<h4><a href="http://example.com/2">Venus</a></h4>') >= 0 )
sources = doc.getElementsByTagName('planet:source') if hide_planet_ns and len(sources) == 1: source = sources[0] feed = source.parentNode child = feed.firstChild while child: next = child.nextSibling if child.nodeName not in ['planet:source','entry']: feed.removeChild(child) child = next while source.hasChildNodes(): child = source.firstChild source.removeChild(child) feed.insertBefore(child, source) atomNS='http://www.w3.org/2005/Atom' for source in doc.getElementsByTagNameNS(atomNS, 'source'): source.parentNode.removeChild(source) splice.apply(doc.toxml('utf-8')) if hide_planet_ns: atom = open(os.path.join(output,'atom.xml')).read() else: atom = open(os.path.join(output,'reconstitute')).read() shutil.rmtree(work) os.removedirs(os.path.dirname(work)) print atom
source=open('tests/data/spider/config.ini') dest1=open('tests/data/splice/config.ini', 'w') dest1.write(source.read().replace('/work/spider/', '/data/splice/')) dest1.close() source.seek(0) dest2=open('tests/work/apply_config.ini', 'w') dest2.write(source.read().replace('[Planet]', '''[Planet] output_theme = asf output_dir = tests/work/apply''')) dest2.close() source.close() # copy splice output to apply input from planet import splice file=open('tests/data/apply/feed.xml', 'w') config.load('tests/data/splice/config.ini') data=splice.splice().toxml('utf-8') file.write(data) file.close() # copy apply output to config/reading-list input config.load('tests/work/apply_config.ini') splice.apply(data) shutil.move('tests/work/apply/opml.xml', 'tests/data/config') shutil.rmtree('tests/work') import runtests
try: spider.spiderPlanet(only_if_new=only_if_new) except Exception, e: print e from planet import splice doc = splice.splice() if debug_splice: from planet import logger logger.info('writing debug.atom') debug = open('debug.atom', 'w') try: from lxml import etree from StringIO import StringIO tree = etree.tostring(etree.parse(StringIO(doc.toxml()))) debug.write(etree.tostring(tree, pretty_print=True)) except: debug.write(doc.toprettyxml(indent=' ', encoding='utf-8')) debug.close splice.apply(doc.toxml('utf-8')) if config.pubsubhubbub_hub() and not no_publish: from planet import publish publish.publish(config) if expunge: from planet import expunge expunge.expungeCache
dest1 = open('tests/data/splice/config.ini', 'w') dest1.write(source.read().replace('/work/spider/', '/data/splice/')) dest1.close() source.seek(0) dest2 = open('tests/work/apply_config.ini', 'w') dest2.write(source.read().replace( '[Planet]', '''[Planet] output_theme = asf output_dir = tests/work/apply''')) dest2.close() source.close() # copy splice output to apply input from planet import splice file = open('tests/data/apply/feed.xml', 'w') config.load('tests/data/splice/config.ini') data = splice.splice().toxml('utf-8') file.write(data) file.close() # copy apply output to config/reading-list input config.load('tests/work/apply_config.ini') splice.apply(data) shutil.move('tests/work/apply/opml.xml', 'tests/data/config') shutil.rmtree('tests/work') import runtests