示例#1
0
class TestFeedReader(unittest.TestCase):
  def setUp(self):
    feedRes = FeedRes('rss.xml', 'tag', 'description', 0, 'Sat, 1 Jan 2011 22:23:26 +0800')
    self.feedReader = FeedReader(feedRes)

  def tearDown(self):
    pass
  
  def test_FeedItems(self):
    items = self.feedReader.getFeedItems()
    expect = ['http://www.178.com/mh/usagidrop/14596.shtml?from=rssReader',
              'http://www.178.com/mh/usagidrop/14445.shtml?from=rssReader']
    self.assertEqual(expect[0], items[0].link)
    self.assertEqual(expect[1], items[1].link)

  def test_FeedItems2(self):
    items = self.feedReader.getFeedItems(FeedReader.noDuplicate)
    #items = self.feedReader.getFeedItems()
    expect = ['http://www.178.com/mh/usagidrop/14596.shtml?from=rssReader',
              'http://www.178.com/mh/usagidrop/14445.shtml?from=rssReader']
    print('print ' + listPrint(items))
    self.assertEqual(expect[0], items[0].link)
    self.assertEqual(expect[1], items[1].link)

#  def test_FillFeedResDate(self):
#    self.assertTrue(self.feedReader.fillFeedResPubDate())

  @unittest.skip('skip tmp test')
  def test_tmpTest(self):
    resOper = ResourceOperator('/dev.sqlite3.db')
    for feedRes in resOper.getFeedResource():
      feedReader = FeedReader(feedRes)
      self.assertTrue(feedReader.fillFeedResPubDate())
示例#2
0
class TestFeedFilter(unittest.TestCase):
  def setUp(self):
    self.filter = FeedFilter() 
#   self.reader = FeedReader('http://manhua.178.com/u/usagidrop/rss.xml')

  def tearDown(self):
    self.filter = None

  def test_filterFeedsExp(self):
    li = [
           MockFeedItem('[枫雪动漫][Hoshizora e Kakaru Hashi 架向星空之桥][12][RMVB+MKV]'),
           MockFeedItem('【旋风字幕组】死神Bleach 第330话「想要活下去!望实的斩魂刀」【RMVB】简体 848x480'), 
           MockFeedItem('动漫之家[DmzJ字幕组][7月新番][Natsume_Yuujinchou_San_夏目友人帐_第三季][02][HDTV][rmvb+mkv]'),
           MockFeedItem('【SOSG字幕团】★4月新番【银魂 Gintama】【第216话】[简体MP4][720p][HDTV]【替代RMVB,享受高清】(RMVB全面停压淘汰)'),
           MockFeedItem('【SOSG字幕團】★4月新番【銀魂 Gintama】【第216話】[繁體MP4][480p][HDTV]【替代RMVB,享受便捷】(RMVB全面停壓淘汰)'),
           MockFeedItem('【异域字幕组】★【7月新番】[夏目友人帐 参][Natsume Yuujinchou San][02][720P][简体][MKV]'),
           MockFeedItem('【AcgmTHK字幕組&K2字幕組】★七月新番【神様のメモ帳 神的記事本】[02][繁體][576P&720P][RV10&Mp4][Http下載、內詳]')
         ]
    result = self.filter.filterFeeds(li)
    errorMsg = listPrint(result)
    self.assertEqual(4, len(result), errorMsg)

  @unittest.skip('reality test skip')
  def test_filterFeeds(self):
    feedRes = FeedRes('popgo.xml', 'tag', 'description', 0, 'Tue, 12 Jul 2011 22:23:26 +0800')
    self.reader = FeedReader(feedRes)
    feeds = self.reader.getFeedItems()
    filtered = self.filter.filterFeeds(feeds)
    filteredLength = len(filtered)
    notFilterLength = len(feeds)
    print('Before: {}\tAfter: {}'.format(notFilterLength, filteredLength))
    f = lambda x:x.title
    print('Filtered -----------\n{}Not filtered ----------\n{}'.format(listPrint(listSub(feeds, filtered), fetchF=f), listPrint(filtered, fetchF=f)))
    self.assertTupleEqual((35, 18), (notFilterLength, filteredLength))
示例#3
0
  def fetchingRes(self):
#TODO: tmep solution
#    try:
    nodes = []
    for feedRes in self.resOper.getFeedResource():
      reader = FeedReader(feedRes)
      newNodes = reader.getFeedItems(FeedReader.noDuplicate)
      if len(newNodes) == 0:
        print('[Info] skip feeds {}'.format(feedRes.id), end='\t')
        continue
      nodes += newNodes
    #nodes = listUnique(nodes, lambda x:x.title)
    validFeeds = self.feedFilter.filterFeeds(nodes)
    filtered = listSub(nodes, validFeeds)
    self._writeToDB(validFeeds, filtered)
    self.results = (validFeeds, filtered)
示例#4
0
 def test_filterFeeds(self):
   feedRes = FeedRes('popgo.xml', 'tag', 'description', 0, 'Tue, 12 Jul 2011 22:23:26 +0800')
   self.reader = FeedReader(feedRes)
   feeds = self.reader.getFeedItems()
   filtered = self.filter.filterFeeds(feeds)
   filteredLength = len(filtered)
   notFilterLength = len(feeds)
   print('Before: {}\tAfter: {}'.format(notFilterLength, filteredLength))
   f = lambda x:x.title
   print('Filtered -----------\n{}Not filtered ----------\n{}'.format(listPrint(listSub(feeds, filtered), fetchF=f), listPrint(filtered, fetchF=f)))
   self.assertTupleEqual((35, 18), (notFilterLength, filteredLength))
示例#5
0
 def test_tmpTest(self):
   resOper = ResourceOperator('/dev.sqlite3.db')
   for feedRes in resOper.getFeedResource():
     feedReader = FeedReader(feedRes)
     self.assertTrue(feedReader.fillFeedResPubDate())
示例#6
0
 def setUp(self):
   feedRes = FeedRes('rss.xml', 'tag', 'description', 0, 'Sat, 1 Jan 2011 22:23:26 +0800')
   self.feedReader = FeedReader(feedRes)