class Scheduleit(): def setUp(self): fpath = os.path.realpath(__file__) cfgfile = os.path.dirname(fpath) + '/dev.cfg' prxyval = Helper.getconfigvalue(cfgfile,'http_proxy',None) if prxyval is not None: self.prxydict = {'http_proxy':prxyval} else: self.prxydict = None dburl = Helper.getconfigvalue(cfgfile,'DATABASE_URI',None) dbname = Helper.getconfigvalue(cfgfile,'DBNAME',None) self.db = pymongo.MongoClient(dburl)[dbname] self.feed = Feed() self.log = logging.getLogger('scheduleit') def schedule(self): if len(sys.argv) > 1 and sys.argv[1].lower()=='cron': self.log.info("Executing updateall at %s" % (datetime.now())) notobj = self.feed.updateall(self.db,self.prxydict) else: while True: self.log.info("Executing updateall at %s" % (datetime.now())) notobj = self.feed.updateall(self.db,self.prxydict) time.sleep(10*60)
def setUp(self): fpath = os.path.realpath(__file__) cfgfile = os.path.dirname(fpath) + "/dev.cfg" dburl = Helper.getconfigvalue(cfgfile, 'DATABASE_URI', None) dbname = Helper.getconfigvalue(cfgfile, 'DBNAME', None) self.db = pymongo.MongoClient(dburl)[dbname] self.feed = Feed() self.log = logging.getLogger('archiver')
def refreshfeed(**kwargs): # app.logger.info(kwargs['email']) feed = Feed() nobj = feed.updatefeed(db.connection,request.args.get('feedurl'), {'http_proxy':app.config.get('HTTP_PROXY',None)}) if not nobj.haserrors: user = User() nobj = user.getfeeddata(db.connection,kwargs['email'],request.args.get('feedurl')) # app.logger.info(nobj) return buildresponse(nobj,{'http_status':200})
def refreshfeed(**kwargs): # app.logger.info(kwargs['email']) feed = Feed() nobj = feed.updatefeed(db.connection, request.args.get('feedurl'), {'http_proxy': app.config['HTTP_PROXY']}) if not nobj.haserrors: user = User() nobj = user.getfeeddata(db.connection, kwargs['email'], request.args.get('feedurl')) # app.logger.info(nobj) return buildresponse(nobj, {'http_status': 200})
def setUp(self): fpath = os.path.realpath(__file__) cfgfile = os.path.dirname(fpath) + '/dev.cfg' prxyval = Helper.getconfigvalue(cfgfile,'http_proxy',None) if prxyval is not None: self.prxydict = {'http_proxy':prxyval} else: self.prxydict = None dburl = Helper.getconfigvalue(cfgfile,'DATABASE_URI',None) dbname = Helper.getconfigvalue(cfgfile,'DBNAME',None) self.db = pymongo.MongoClient(dburl)[dbname] self.feed = Feed() self.log = logging.getLogger('scheduleit')
def setUp(self): fpath = os.path.realpath(__file__) cfgfile = os.path.dirname(fpath) + "/dev.cfg" dburl = Helper.getconfigvalue(cfgfile,'DATABASE_URI',None) dbname = Helper.getconfigvalue(cfgfile,'DBNAME',None) self.db = pymongo.MongoClient(dburl)[dbname] self.feed = Feed() self.log = logging.getLogger('archiver')
def setUp(self): prxyval = Helper.getconfigvalue('dev.cfg', 'http_proxy', None) if prxyval is not None: self.prxydict = {'http_proxy': prxyval} else: self.prxydict = None dburl = Helper.getconfigvalue('dev.cfg', 'DATABASE_URI', None) dbname = Helper.getconfigvalue('dev.cfg', 'DBNAME', None) self.db = pymongo.MongoClient(dburl)[dbname] self.feed = Feed() self.log = logging.getLogger('scheduleit') self.user = api.User() self.feed = api.Feed() self.log = logging.getLogger('apitest') self.testfeedurl = 'http://feeds.harvardbusiness.org/harvardbusiness/bregman/'
class Archiver(): def setUp(self): fpath = os.path.realpath(__file__) cfgfile = os.path.dirname(fpath) + "/dev.cfg" dburl = Helper.getconfigvalue(cfgfile, 'DATABASE_URI', None) dbname = Helper.getconfigvalue(cfgfile, 'DBNAME', None) self.db = pymongo.MongoClient(dburl)[dbname] self.feed = Feed() self.log = logging.getLogger('archiver') def schedule(self): if len(sys.argv) > 1 and sys.argv[1].lower() == 'cron': self.log.info("Executing archiver at %s" % (datetime.now())) notobj = self.feed.archivefeeds(self.db, 5) else: while True: self.log.info("Executing archiver at %s" % (datetime.now())) notobj = self.feed.archivefeeds(self.db, 5) time.sleep(120 * 60)
class Archiver(): def setUp(self): fpath = os.path.realpath(__file__) cfgfile = os.path.dirname(fpath) + "/dev.cfg" dburl = Helper.getconfigvalue(cfgfile,'DATABASE_URI',None) dbname = Helper.getconfigvalue(cfgfile,'DBNAME',None) self.db = pymongo.MongoClient(dburl)[dbname] self.feed = Feed() self.log = logging.getLogger('archiver') def schedule(self): if len(sys.argv) > 1 and sys.argv[1].lower()=='cron': self.log.info("Executing archiver at %s" % (datetime.now())) notobj = self.feed.archivefeeds(self.db,5) else: while True: self.log.info("Executing archiver at %s" % (datetime.now())) notobj = self.feed.archivefeeds(self.db,5) time.sleep(120*60)
class Scheduleit(): def setUp(self): self.db = pymongo.MongoClient("localhost", 27017, safe=True).feedtest self.feed = Feed() self.log = logging.getLogger('scheduleit') self.prxydict = {'http_proxy': 'http://www-proxy.au.oracle.com:80'} def schedule(self): while True: self.log.info("Excuting updateall at %s" % (datetime.now())) notobj = self.feed.updateall(self.db, self.prxydict) time.sleep(15 * 60)
class Scheduleit(): def setUp(self): self.db = pymongo.MongoClient("localhost",27017,safe=True).feedtest self.feed = Feed() self.log = logging.getLogger('scheduleit') self.prxydict = {'http_proxy':'http://www-proxy.au.oracle.com:80'} def schedule(self): while True: self.log.info("Excuting updateall at %s" % (datetime.now())) notobj = self.feed.updateall(self.db,self.prxydict) time.sleep(15*60)
def test_make_output_file_name(config): feed = Feed(config, sport="NBA", season="current", season_type="regular", date="20150101", output_type="csv") feed.make_url("daily_game_schedule") player_stats = None team_stats = None awayteam = "ATL" hometeam = "PHL" feed.add_params({"playerstats": player_stats, "teamstats": team_stats, "gameid": "{date}-{away}-{home}".format(date=feed.config.params["fordate"], away=awayteam, home=hometeam) }) assert feed.make_output_filename() == "nba-daily_game_schedule-20150101-current-20150101-atl-phl.csv"
def setUp(self): prxyval = Helper.getconfigvalue('dev.cfg','http_proxy',None) if prxyval is not None: self.prxydict = {'http_proxy':prxyval} else: self.prxydict = None dburl = Helper.getconfigvalue('dev.cfg','DATABASE_URI',None) dbname = Helper.getconfigvalue('dev.cfg','DBNAME',None) self.db = pymongo.MongoClient(dburl)[dbname] self.feed = Feed() self.log = logging.getLogger('scheduleit') self.user = api.User() self.feed = api.Feed() self.log = logging.getLogger('apitest') self.testfeedurl = 'http://feeds.harvardbusiness.org/harvardbusiness/bregman/'
class UserTest(unittest.TestCase): def setUp(self): prxyval = Helper.getconfigvalue('dev.cfg', 'http_proxy', None) if prxyval is not None: self.prxydict = {'http_proxy': prxyval} else: self.prxydict = None dburl = Helper.getconfigvalue('dev.cfg', 'DATABASE_URI', None) dbname = Helper.getconfigvalue('dev.cfg', 'DBNAME', None) self.db = pymongo.MongoClient(dburl)[dbname] self.feed = Feed() self.log = logging.getLogger('scheduleit') self.user = api.User() self.feed = api.Feed() self.log = logging.getLogger('apitest') self.testfeedurl = 'http://feeds.harvardbusiness.org/harvardbusiness/bregman/' def tearDown(self): self.db.users.remove() self.db.feeds.remove() def test_user_wronglogin(self): notobj = self.user.save(self.db, '*****@*****.**', 'abc', 'xyz') self.assertFalse(notobj.haserrors) self.assertIsNone(self.user.login(self.db, '*****@*****.**', 'bb').result) def test_user_login(self): notobj = self.user.save(self.db, '*****@*****.**', 'abc', 'xyz') self.assertFalse(notobj.haserrors) self.assertIsNotNone(self.user.login(self.db, '*****@*****.**', 'xyz').result) def test_save_user_wrongemail(self): notobj = self.user.save(self.db, 'wrongmail', 'abc', 'xyz') self.assertTrue(notobj.haserrors) def test_save__user_wrongname(self): notobj = self.user.save(self.db, '*****@*****.**', '', 'xyz') self.assertTrue(notobj.haserrors) def test_save_user_samenamepwd(self): notobj = self.user.save(self.db, '*****@*****.**', 'abc', 'abc') self.assertTrue(notobj.haserrors) def test_save_user(self): notobj = self.user.save(self.db, '*****@*****.**', 'abc', 'xyz') self.assertFalse(notobj.haserrors) self.assertFalse( self.db.users.find_one({ '_id': '*****@*****.**', 'name': 'abc', 'pwd': 'xyz' }) is None) def test_addcategory_wrongemail(self): notobj = self.user.addcategory(self.db, '', 'abc') self.assertTrue(notobj.haserrors) def test_addcategory_wrongemail_emptycat(self): notobj = self.user.addcategory(self.db, '', '') self.assertTrue(notobj.haserrors) def test_removecategory_blankcategory(self): notobj = self.user.save(self.db, '*****@*****.**', 'abc', 'xyz') self.assertFalse(notobj.haserrors) notobj = self.user.addcategory(self.db, '*****@*****.**', 'fun') self.assertFalse(notobj.haserrors) notobj = self.user.removecategory(self.db, '*****@*****.**', '') self.assertTrue(notobj.haserrors) def test_removecategory_removal(self): notobj = self.user.save(self.db, '*****@*****.**', 'abc', 'xyz') self.assertFalse(notobj.haserrors) notobj = self.user.addcategory(self.db, '*****@*****.**', 'fun') self.assertFalse(notobj.haserrors) notobj = self.user.removecategory(self.db, '*****@*****.**', 'fun') self.assertFalse(notobj.haserrors) self.assertTrue( self.db.users.find_one({ '_id': '*****@*****.**', 'categories': 'fun', 'subs.category': 'fun' }) is None) def test_renamecategory_wrongnewcat(self): notobj = self.user.save(self.db, '*****@*****.**', 'abc', 'xyz') self.assertFalse(notobj.haserrors) notobj = self.user.addcategory(self.db, '*****@*****.**', 'fun') self.assertFalse(notobj.haserrors) notobj = self.user.renamecategory(self.db, '*****@*****.**', 'fun', '') self.assertTrue(notobj.haserrors) def test_renamecategory_wrongoldcat(self): notobj = self.user.save(self.db, '*****@*****.**', 'abc', 'xyz') self.assertFalse(notobj.haserrors) notobj = self.user.addcategory(self.db, '*****@*****.**', 'fun') self.assertFalse(notobj.haserrors) notobj = self.user.renamecategory(self.db, '*****@*****.**', '', 'money') self.assertTrue(notobj.haserrors) def test_renamecategory_wrongemail(self): notobj = self.user.save(self.db, '*****@*****.**', 'abc', 'xyz') self.assertFalse(notobj.haserrors) notobj = self.user.addcategory(self.db, '*****@*****.**', 'fun') self.assertFalse(notobj.haserrors) notobj = self.user.renamecategory(self.db, '', 'fun', 'money') self.assertTrue(notobj.haserrors) def test_renamecategory_save(self): notobj = self.user.save(self.db, '*****@*****.**', 'abc', 'xyz') self.assertFalse(notobj.haserrors) notobj = self.user.addcategory(self.db, '*****@*****.**', 'fun') self.assertFalse(notobj.haserrors) notobj = self.user.renamecategory(self.db, '*****@*****.**', 'fun', 'money') self.assertFalse(notobj.haserrors) self.assertIsNone( self.db.users.find_one({ '_id': '*****@*****.**', 'categories': 'fun' })) self.assertIsNotNone( self.db.users.find_one({ '_id': '*****@*****.**', 'categories': 'money' })) def test_changecategory_save(self): testurl = 'https://news.ycombinator.com/rss' notobj = self.user.save(self.db, '*****@*****.**', 'abc', 'xyz') self.assertFalse(notobj.haserrors) notobj = self.user.addcategory(self.db, '*****@*****.**', 'fun') self.assertFalse(notobj.haserrors) notobj = self.user.addcategory(self.db, '*****@*****.**', 'money') self.assertFalse(notobj.haserrors) notobj = self.user.addfeed(self.db, '*****@*****.**', testurl, 'fun', self.prxydict) self.assertFalse(notobj.haserrors) notobj = self.user.changecategory(self.db, '*****@*****.**', testurl, 'money') self.assertFalse(notobj.haserrors) rec = self.db.users.find_one({'_id': '*****@*****.**'}) thissub = None for sub in rec['subs']: if sub['_id'] == 'https://news.ycombinator.com/rss': thissub = sub break self.assertTrue(thissub is not None) self.assertTrue(thissub['category'] == 'money') def test_addfeed_wrongurl(self): notobj = self.user.save(self.db, '*****@*****.**', 'abc', 'xyz') self.assertFalse(notobj.haserrors) notobj = self.user.addcategory(self.db, '*****@*****.**', 'fun') self.assertFalse(notobj.haserrors) notobj = self.user.addfeed(self.db, '*****@*****.**', 'y.com', 'fun', self.prxydict) self.assertTrue(notobj.haserrors) def test_addfeed_save(self): notobj = self.user.save(self.db, '*****@*****.**', 'abc', 'xyz') self.assertFalse(notobj.haserrors) notobj = self.user.addcategory(self.db, '*****@*****.**', 'fun') self.assertFalse(notobj.haserrors) notobj = self.user.addfeed( self.db, '*****@*****.**', 'http://devinder-sharma.blogspot.com/feeds/posts/default', 'fun', self.prxydict) self.assertFalse(notobj.haserrors) def test_getfeeddata_wrongemail(self): notobj = self.user.save(self.db, '*****@*****.**', 'abc', 'xyz') self.assertFalse(notobj.haserrors) notobj = self.user.addcategory(self.db, '*****@*****.**', 'fun') self.assertFalse(notobj.haserrors) notobj = self.user.addfeed(self.db, '*****@*****.**', self.testfeedurl, 'fun', self.prxydict) self.assertFalse(notobj.haserrors) notobj = self.user.getfeeddata(self.db, '*****@*****.**', self.testfeedurl) self.assertTrue(notobj.haserrors) def test_getfeeddata_allfeeds(self): notobj = self.user.save(self.db, '*****@*****.**', 'abc', 'xyz') self.assertFalse(notobj.haserrors) notobj = self.user.addcategory(self.db, '*****@*****.**', 'fun') self.assertFalse(notobj.haserrors) notobj = self.user.addfeed( self.db, '*****@*****.**', 'http://devinder-sharma.blogspot.com/feeds/posts/default', 'money', self.prxydict) self.assertFalse(notobj.haserrors) notobj = self.user.addfeed(self.db, '*****@*****.**', 'http://www.readwriteweb.com/hack/rss.xml', 'fun', self.prxydict) self.assertFalse(notobj.haserrors) notobj = self.user.addfeed( self.db, '*****@*****.**', 'http://feeds.feedburner.com/typepad/sethsmainblog', 'fun', self.prxydict) self.assertFalse(notobj.haserrors) notobj = self.user.getfeeddata(self.db, '*****@*****.**', None) self.assertFalse(notobj.haserrors) def test_getfeeddata_wrongfeedurl(self): notobj = self.user.save(self.db, '*****@*****.**', 'abc', 'xyz') self.assertFalse(notobj.haserrors) notobj = self.user.addcategory(self.db, '*****@*****.**', 'fun') self.assertFalse(notobj.haserrors) notobj = self.user.addfeed(self.db, '*****@*****.**', self.testfeedurl, 'fun', self.prxydict) self.assertFalse(notobj.haserrors) notobj = self.user.getfeeddata(self.db, '*****@*****.**', 'www.self.com') self.assertTrue(notobj.haserrors) def test_getfeeddata_success(self): notobj = self.user.save(self.db, '*****@*****.**', 'abc', 'xyz') self.assertFalse(notobj.haserrors) notobj = self.user.addcategory(self.db, '*****@*****.**', 'fun') self.assertFalse(notobj.haserrors) notobj = self.user.addfeed(self.db, '*****@*****.**', self.testfeedurl, 'fun', self.prxydict) self.assertFalse(notobj.haserrors) notobj = self.user.getfeeddata(self.db, '*****@*****.**', self.testfeedurl) self.assertFalse(notobj.haserrors) def test_removefeed_wrongfeed(self): notobj = self.user.save(self.db, '*****@*****.**', 'abc', 'xyz') self.assertFalse(notobj.haserrors) notobj = self.user.addcategory(self.db, '*****@*****.**', 'fun') self.assertFalse(notobj.haserrors) notobj = self.user.addfeed(self.db, '*****@*****.**', self.testfeedurl, 'fun', self.prxydict) self.assertFalse(notobj.haserrors) notobj = self.user.removefeed(self.db, '*****@*****.**', 'www.google.com') self.assertTrue(notobj.haserrors) def test_removefeed_remove(self): notobj = self.user.save(self.db, '*****@*****.**', 'abc', 'xyz') self.assertFalse(notobj.haserrors) notobj = self.user.addcategory(self.db, '*****@*****.**', 'fun') self.assertFalse(notobj.haserrors) notobj = self.user.addfeed(self.db, '*****@*****.**', self.testfeedurl, 'fun', self.prxydict) self.assertFalse(notobj.haserrors) notobj = self.user.removefeed(self.db, '*****@*****.**', self.testfeedurl) self.assertFalse(notobj.haserrors) def test_changefeedcategory_change(self): notobj = self.user.save(self.db, '*****@*****.**', 'abc', 'xyz') self.assertFalse(notobj.haserrors) notobj = self.user.addcategory(self.db, '*****@*****.**', 'fun') self.assertFalse(notobj.haserrors) notobj = self.user.addfeed(self.db, '*****@*****.**', self.testfeedurl, 'fun', self.prxydict) self.assertFalse(notobj.haserrors) notobj = self.user.changefeedcategory(self.db, '*****@*****.**', self.testfeedurl, 'tech') self.assertFalse(notobj.haserrors) self.assertFalse( self.db.users.find_one({ '_id': '*****@*****.**', 'subs._id': self.testfeedurl, 'subs.category': 'tech' }) is None) def test_updatefeeditem_update(self): notobj = self.user.save(self.db, '*****@*****.**', 'abc', 'xyz') self.assertFalse(notobj.haserrors) notobj = self.user.addcategory(self.db, '*****@*****.**', 'fun') self.assertFalse(notobj.haserrors) notobj = self.user.addfeed(self.db, '*****@*****.**', self.testfeedurl, 'fun', self.prxydict) self.assertFalse(notobj.haserrors) feeditem = self.db.users.find_one({ '_id': '*****@*****.**', 'subs._id': self.testfeedurl }) self.assertFalse(feeditem is None) flist = feeditem['subs'][0]['items'].items() fitem = None for i in flist: fitem = i self.assertFalse( self.user.updatefeeditem(self.db, '*****@*****.**', self.testfeedurl, fitem[0], True, False).haserrors) self.assertIsNotNone( self.db.users.find_one({ '_id': '*****@*****.**', ('subs.items.%s.isread' % fitem[0]): True, ('subs.items.%s.isstarred' % fitem[0]): False })) def test_getfeedtree_checkmail(self): notobj = self.user.save(self.db, '*****@*****.**', 'abc', 'xyz') self.assertFalse(notobj.haserrors) notobj = self.user.addcategory(self.db, '*****@*****.**', 'fun') self.assertFalse(notobj.haserrors) notobj = self.user.addfeed( self.db, '*****@*****.**', 'http://devinder-sharma.blogspot.com/feeds/posts/default', 'money', self.prxydict) self.assertFalse(notobj.haserrors) notobj = self.user.addfeed(self.db, '*****@*****.**', 'http://www.readwriteweb.com/hack/rss.xml', 'fun', self.prxydict) self.assertFalse(notobj.haserrors) notobj = self.user.addfeed( self.db, '*****@*****.**', 'http://feeds.feedburner.com/typepad/sethsmainblog', 'fun', self.prxydict) self.assertFalse(notobj.haserrors) notobj = self.user.getfeedlist(self.db, '*****@*****.**') self.assertTrue(notobj.haserrors) def test_getfeedtree_checkorder(self): notobj = self.user.save(self.db, '*****@*****.**', 'abc', 'xyz') self.assertFalse(notobj.haserrors) notobj = self.user.addcategory(self.db, '*****@*****.**', 'fun') self.assertFalse(notobj.haserrors) notobj = self.user.addfeed( self.db, '*****@*****.**', 'http://devinder-sharma.blogspot.com/feeds/posts/default', 'money', self.prxydict) self.assertFalse(notobj.haserrors) notobj = self.user.addfeed(self.db, '*****@*****.**', 'http://www.readwriteweb.com/hack/rss.xml', 'fun', self.prxydict) self.assertFalse(notobj.haserrors) notobj = self.user.addfeed( self.db, '*****@*****.**', 'http://feeds.feedburner.com/typepad/sethsmainblog', 'fun', self.prxydict) self.assertFalse(notobj.haserrors) notobj = self.user.getfeedlist(self.db, '*****@*****.**') self.assertFalse(notobj.haserrors) self.assertTrue(notobj.result[0]['category'] == 'fun') def test_getfeeddata_checkindb(self): notobj = self.user.save(self.db, '*****@*****.**', 'abc', 'xyz') self.assertFalse(notobj.haserrors) notobj = self.user.addcategory(self.db, '*****@*****.**', 'fun') self.assertFalse(notobj.haserrors) notobj = self.user.addfeed( self.db, '*****@*****.**', 'http://devinder-sharma.blogspot.com/feeds/posts/default', 'money', self.prxydict) self.assertFalse(notobj.haserrors) notobj = self.user.getfeeddata( self.db, '*****@*****.**', 'http://devinder-sharma.blogspot.com/feeds/posts/default') self.assertFalse(notobj.haserrors) feedinfo = self.db.feeds.find_one({ '_id': 'http://devinder-sharma.blogspot.com/feeds/posts/default', 'items._id': notobj.result[0]['_id'] }) self.assertIsNotNone(feedinfo) self.assertTrue(len(feedinfo['items']) == len(notobj.result)) def test_updateall(self): notobj = self.user.save(self.db, '*****@*****.**', 'abc', 'xyz') self.assertFalse(notobj.haserrors) notobj = self.user.addcategory(self.db, '*****@*****.**', 'fun') self.assertFalse(notobj.haserrors) notobj = self.user.addfeed( self.db, '*****@*****.**', 'http://devinder-sharma.blogspot.com/feeds/posts/default', 'money', self.prxydict) self.assertFalse(notobj.haserrors) notobj = self.user.addfeed(self.db, '*****@*****.**', 'http://www.readwriteweb.com/hack/rss.xml', 'fun', self.prxydict) self.assertFalse(notobj.haserrors) notobj = self.user.addfeed( self.db, '*****@*****.**', 'http://feeds.feedburner.com/typepad/sethsmainblog', 'fun', self.prxydict) self.assertFalse(notobj.haserrors) notobj = self.user.addfeed( self.db, '*****@*****.**', 'http://zeenut.blogspot.com/feeds/posts/default?alt=rss', 'fun', self.prxydict) self.assertFalse(notobj.haserrors) notobj = self.user.addfeed( self.db, '*****@*****.**', 'http://www.spiegel.de/international/index.rss ', 'fun', self.prxydict) self.assertFalse(notobj.haserrors) notobj = self.feed.updateall(self.db, self.prxydict) self.assertFalse(notobj.haserrors) def test_archivefeeds(self): from datetime import datetime, timedelta from time import mktime from api import Helper notobj = self.user.save(self.db, '*****@*****.**', 'abc', 'xyz') self.assertFalse(notobj.haserrors) notobj = self.user.addcategory(self.db, '*****@*****.**', 'fun') self.assertFalse(notobj.haserrors) notobj = self.user.addfeed(self.db, '*****@*****.**', 'https://news.ycombinator.com/rss', 'fun', self.prxydict) self.assertFalse(notobj.haserrors) notobj = self.feed.archivefeeds(self.db, 1) self.assertFalse(notobj.haserrors) notobj = self.user.getfeeddata(self.db, '*****@*****.**', 'https://news.ycombinator.com/rss') self.assertFalse(notobj.haserrors) olderthandate = datetime.now() - timedelta(days=1) olderthandate_ts = Helper.datetotimestamp(olderthandate) for item in notobj.result: self.assertTrue(item['published_date'] is None or item['published_date'] >= olderthandate_ts) def test_markallread(self): from datetime import datetime from time import mktime ts = mktime( datetime.now().timetuple()) + 1e-6 * datetime.now().microsecond notobj = self.user.save(self.db, '*****@*****.**', 'abc', 'xyz') self.assertFalse(notobj.haserrors) notobj = self.user.addcategory(self.db, '*****@*****.**', 'fun') self.assertFalse(notobj.haserrors) notobj = self.user.addfeed( self.db, '*****@*****.**', 'http://feeds.feedburner.com/TheInvestorBlog', 'fun', self.prxydict) self.assertFalse(notobj.haserrors) notobj = self.user.getfeeddata( self.db, '*****@*****.**', 'http://feeds.feedburner.com/TheInvestorBlog') self.assertFalse(notobj.haserrors) notobj = self.user.markallread( self.db, '*****@*****.**', 'http://feeds.feedburner.com/TheInvestorBlog', ts) self.assertFalse(notobj.haserrors) def test_updatefeed(self): import time from datetime import datetime feedurl = 'https://news.ycombinator.com/rss' notobj = self.user.save(self.db, '*****@*****.**', 'abc', 'xyz') self.assertFalse(notobj.haserrors) notobj = self.user.addcategory(self.db, '*****@*****.**', 'fun') self.assertFalse(notobj.haserrors) notobj = self.user.addfeed(self.db, '*****@*****.**', feedurl, 'fun', self.prxydict) self.assertFalse(notobj.haserrors) # print " This is going to sleep for 2 minutes. so pl. wait ..." # time.sleep(120) notobj = self.feed.updatefeed(self.db, feedurl, self.prxydict) self.assertFalse(notobj.haserrors) #now get updated feed data notobj = FeedGateway.getfeed(feedurl, self.prxydict) self.assertFalse(notobj.haserrors) #now check that latest feed is available in DB feed_data = notobj.result fitemdb = None for fitem in feed_data["entries"]: # search if item is already available in DB if fitem.has_key('published_parsed'): pdate = fitem['published_parsed'] else: if fitem.has_key('published'): #http://stackoverflow.com/questions/9516025/parsing-datetime-in-python pdate = parse(fitem['published']) else: pdate = datetime.today() if fitemdb is None: fitemdb = {'uri': fitem['link'], 'pdate': pdate} if Helper.datetotimestamp(pdate) > Helper.datetotimestamp( fitemdb['pdate']): fitemdb = {'uri': fitem['link'], 'pdate': pdate} self.assertIsNotNone(fitemdb) # print fitemdb # notobj = self.db.feed.find_one({'_id':feedurl}) # self.assertIsNotNone(notobj) # for itm in notobj['items']: # print itm['link'] notobj = self.db.feeds.find_one( { '_id': feedurl, 'items.link': fitemdb['uri'] }, {'_id': 1}) self.assertIsNotNone(notobj)
class UserTest(unittest.TestCase): def setUp(self): prxyval = Helper.getconfigvalue('dev.cfg','http_proxy',None) if prxyval is not None: self.prxydict = {'http_proxy':prxyval} else: self.prxydict = None dburl = Helper.getconfigvalue('dev.cfg','DATABASE_URI',None) dbname = Helper.getconfigvalue('dev.cfg','DBNAME',None) self.db = pymongo.MongoClient(dburl)[dbname] self.feed = Feed() self.log = logging.getLogger('scheduleit') self.user = api.User() self.feed = api.Feed() self.log = logging.getLogger('apitest') self.testfeedurl = 'http://feeds.harvardbusiness.org/harvardbusiness/bregman/' def tearDown(self): self.db.users.remove() self.db.feeds.remove() def test_user_wronglogin(self): notobj = self.user.save(self.db,'*****@*****.**','abc','xyz') self.assertFalse(notobj.haserrors) self.assertIsNone(self.user.login(self.db,'*****@*****.**','bb').result) def test_user_login(self): notobj = self.user.save(self.db,'*****@*****.**','abc','xyz') self.assertFalse(notobj.haserrors) self.assertIsNotNone(self.user.login(self.db,'*****@*****.**','xyz').result) def test_save_user_wrongemail(self): notobj = self.user.save(self.db,'wrongmail','abc','xyz') self.assertTrue(notobj.haserrors) def test_save__user_wrongname(self): notobj = self.user.save(self.db,'*****@*****.**','','xyz') self.assertTrue(notobj.haserrors) def test_save_user_samenamepwd(self): notobj = self.user.save(self.db,'*****@*****.**','abc','abc') self.assertTrue(notobj.haserrors) def test_save_user(self): notobj = self.user.save(self.db,'*****@*****.**','abc','xyz') self.assertFalse(notobj.haserrors) self.assertFalse(self.db.users.find_one({'_id':'*****@*****.**','name':'abc','pwd':'xyz'}) is None) def test_addcategory_wrongemail(self): notobj = self.user.addcategory(self.db,'','abc') self.assertTrue(notobj.haserrors) def test_addcategory_wrongemail_emptycat(self): notobj = self.user.addcategory(self.db,'','') self.assertTrue(notobj.haserrors) def test_removecategory_blankcategory(self): notobj = self.user.save(self.db,'*****@*****.**','abc','xyz') self.assertFalse(notobj.haserrors) notobj = self.user.addcategory(self.db,'*****@*****.**','fun') self.assertFalse(notobj.haserrors) notobj = self.user.removecategory(self.db,'*****@*****.**','') self.assertTrue(notobj.haserrors) def test_removecategory_removal(self): notobj = self.user.save(self.db,'*****@*****.**','abc','xyz') self.assertFalse(notobj.haserrors) notobj = self.user.addcategory(self.db,'*****@*****.**','fun') self.assertFalse(notobj.haserrors) notobj = self.user.removecategory(self.db,'*****@*****.**','fun') self.assertFalse(notobj.haserrors) self.assertTrue(self.db.users.find_one({'_id':'*****@*****.**','categories':'fun','subs.category':'fun'}) is None) def test_renamecategory_wrongnewcat(self): notobj = self.user.save(self.db,'*****@*****.**','abc','xyz') self.assertFalse(notobj.haserrors) notobj = self.user.addcategory(self.db,'*****@*****.**','fun') self.assertFalse(notobj.haserrors) notobj = self.user.renamecategory(self.db,'*****@*****.**','fun','') self.assertTrue(notobj.haserrors) def test_renamecategory_wrongoldcat(self): notobj = self.user.save(self.db,'*****@*****.**','abc','xyz') self.assertFalse(notobj.haserrors) notobj = self.user.addcategory(self.db,'*****@*****.**','fun') self.assertFalse(notobj.haserrors) notobj = self.user.renamecategory(self.db,'*****@*****.**','','money') self.assertTrue(notobj.haserrors) def test_renamecategory_wrongemail(self): notobj = self.user.save(self.db,'*****@*****.**','abc','xyz') self.assertFalse(notobj.haserrors) notobj = self.user.addcategory(self.db,'*****@*****.**','fun') self.assertFalse(notobj.haserrors) notobj = self.user.renamecategory(self.db,'','fun','money') self.assertTrue(notobj.haserrors) def test_renamecategory_save(self): notobj = self.user.save(self.db,'*****@*****.**','abc','xyz') self.assertFalse(notobj.haserrors) notobj = self.user.addcategory(self.db,'*****@*****.**','fun') self.assertFalse(notobj.haserrors) notobj = self.user.renamecategory(self.db,'*****@*****.**','fun','money') self.assertFalse(notobj.haserrors) self.assertIsNone(self.db.users.find_one({'_id':'*****@*****.**','categories':'fun'})) self.assertIsNotNone(self.db.users.find_one({'_id':'*****@*****.**','categories':'money'})) def test_changecategory_save(self): testurl= 'https://news.ycombinator.com/rss' notobj = self.user.save(self.db,'*****@*****.**','abc','xyz') self.assertFalse(notobj.haserrors) notobj = self.user.addcategory(self.db,'*****@*****.**','fun') self.assertFalse(notobj.haserrors) notobj = self.user.addcategory(self.db,'*****@*****.**','money') self.assertFalse(notobj.haserrors) notobj = self.user.addfeed(self.db,'*****@*****.**',testurl,'fun',self.prxydict) self.assertFalse(notobj.haserrors) notobj = self.user.changecategory(self.db,'*****@*****.**',testurl,'money') self.assertFalse(notobj.haserrors) rec= self.db.users.find_one({'_id':'*****@*****.**'}) thissub = None for sub in rec['subs']: if sub['_id'] == 'https://news.ycombinator.com/rss': thissub = sub break self.assertTrue(thissub is not None) self.assertTrue(thissub['category'] == 'money') def test_addfeed_wrongurl(self): notobj = self.user.save(self.db,'*****@*****.**','abc','xyz') self.assertFalse(notobj.haserrors) notobj = self.user.addcategory(self.db,'*****@*****.**','fun') self.assertFalse(notobj.haserrors) notobj = self.user.addfeed(self.db,'*****@*****.**','y.com','fun',self.prxydict) self.assertTrue(notobj.haserrors) def test_addfeed_save(self): notobj = self.user.save(self.db,'*****@*****.**','abc','xyz') self.assertFalse(notobj.haserrors) notobj = self.user.addcategory(self.db,'*****@*****.**','fun') self.assertFalse(notobj.haserrors) notobj = self.user.addfeed(self.db,'*****@*****.**','http://devinder-sharma.blogspot.com/feeds/posts/default','fun',self.prxydict) self.assertFalse(notobj.haserrors) def test_getfeeddata_wrongemail(self): notobj = self.user.save(self.db,'*****@*****.**','abc','xyz') self.assertFalse(notobj.haserrors) notobj = self.user.addcategory(self.db,'*****@*****.**','fun') self.assertFalse(notobj.haserrors) notobj = self.user.addfeed(self.db,'*****@*****.**',self.testfeedurl,'fun',self.prxydict) self.assertFalse(notobj.haserrors) notobj = self.user.getfeeddata(self.db,'*****@*****.**',self.testfeedurl) self.assertTrue(notobj.haserrors) def test_getfeeddata_allfeeds(self): notobj = self.user.save(self.db,'*****@*****.**','abc','xyz') self.assertFalse(notobj.haserrors) notobj = self.user.addcategory(self.db,'*****@*****.**','fun') self.assertFalse(notobj.haserrors) notobj = self.user.addfeed(self.db,'*****@*****.**','http://devinder-sharma.blogspot.com/feeds/posts/default','money',self.prxydict) self.assertFalse(notobj.haserrors) notobj = self.user.addfeed(self.db,'*****@*****.**','http://www.readwriteweb.com/hack/rss.xml','fun',self.prxydict) self.assertFalse(notobj.haserrors) notobj = self.user.addfeed(self.db,'*****@*****.**','http://feeds.feedburner.com/typepad/sethsmainblog','fun',self.prxydict) self.assertFalse(notobj.haserrors) notobj = self.user.getfeeddata(self.db,'*****@*****.**',None) self.assertFalse(notobj.haserrors) def test_getfeeddata_wrongfeedurl(self): notobj = self.user.save(self.db,'*****@*****.**','abc','xyz') self.assertFalse(notobj.haserrors) notobj = self.user.addcategory(self.db,'*****@*****.**','fun') self.assertFalse(notobj.haserrors) notobj = self.user.addfeed(self.db,'*****@*****.**',self.testfeedurl,'fun',self.prxydict) self.assertFalse(notobj.haserrors) notobj = self.user.getfeeddata(self.db,'*****@*****.**','www.self.com') self.assertTrue(notobj.haserrors) def test_getfeeddata_success(self): notobj = self.user.save(self.db,'*****@*****.**','abc','xyz') self.assertFalse(notobj.haserrors) notobj = self.user.addcategory(self.db,'*****@*****.**','fun') self.assertFalse(notobj.haserrors) notobj = self.user.addfeed(self.db,'*****@*****.**',self.testfeedurl,'fun',self.prxydict) self.assertFalse(notobj.haserrors) notobj = self.user.getfeeddata(self.db,'*****@*****.**',self.testfeedurl) self.assertFalse(notobj.haserrors) def test_removefeed_wrongfeed(self): notobj = self.user.save(self.db,'*****@*****.**','abc','xyz') self.assertFalse(notobj.haserrors) notobj = self.user.addcategory(self.db,'*****@*****.**','fun') self.assertFalse(notobj.haserrors) notobj = self.user.addfeed(self.db,'*****@*****.**',self.testfeedurl,'fun',self.prxydict) self.assertFalse(notobj.haserrors) notobj = self.user.removefeed(self.db,'*****@*****.**','www.google.com') self.assertTrue(notobj.haserrors) def test_removefeed_remove(self): notobj = self.user.save(self.db,'*****@*****.**','abc','xyz') self.assertFalse(notobj.haserrors) notobj = self.user.addcategory(self.db,'*****@*****.**','fun') self.assertFalse(notobj.haserrors) notobj = self.user.addfeed(self.db,'*****@*****.**',self.testfeedurl,'fun',self.prxydict) self.assertFalse(notobj.haserrors) notobj = self.user.removefeed(self.db,'*****@*****.**',self.testfeedurl) self.assertFalse(notobj.haserrors) def test_changefeedcategory_change(self): notobj = self.user.save(self.db,'*****@*****.**','abc','xyz') self.assertFalse(notobj.haserrors) notobj = self.user.addcategory(self.db,'*****@*****.**','fun') self.assertFalse(notobj.haserrors) notobj = self.user.addfeed(self.db,'*****@*****.**',self.testfeedurl,'fun',self.prxydict) self.assertFalse(notobj.haserrors) notobj = self.user.changefeedcategory(self.db,'*****@*****.**',self.testfeedurl,'tech') self.assertFalse(notobj.haserrors) self.assertFalse(self.db.users.find_one({'_id':'*****@*****.**','subs._id':self.testfeedurl,'subs.category':'tech'}) is None) def test_updatefeeditem_update(self): notobj = self.user.save(self.db,'*****@*****.**','abc','xyz') self.assertFalse(notobj.haserrors) notobj = self.user.addcategory(self.db,'*****@*****.**','fun') self.assertFalse(notobj.haserrors) notobj = self.user.addfeed(self.db,'*****@*****.**',self.testfeedurl,'fun',self.prxydict) self.assertFalse(notobj.haserrors) feeditem = self.db.users.find_one({'_id':'*****@*****.**','subs._id':self.testfeedurl}) self.assertFalse(feeditem is None) flist = feeditem['subs'][0]['items'].items() fitem = None for i in flist: fitem = i self.assertFalse(self.user.updatefeeditem(self.db,'*****@*****.**',self.testfeedurl,fitem[0],True,False).haserrors) self.assertIsNotNone(self.db.users.find_one({'_id':'*****@*****.**',('subs.items.%s.isread' % fitem[0]) :True,('subs.items.%s.isstarred' % fitem[0]): False})) def test_getfeedtree_checkmail(self): notobj = self.user.save(self.db,'*****@*****.**','abc','xyz') self.assertFalse(notobj.haserrors) notobj = self.user.addcategory(self.db,'*****@*****.**','fun') self.assertFalse(notobj.haserrors) notobj = self.user.addfeed(self.db,'*****@*****.**','http://devinder-sharma.blogspot.com/feeds/posts/default','money',self.prxydict) self.assertFalse(notobj.haserrors) notobj = self.user.addfeed(self.db,'*****@*****.**','http://www.readwriteweb.com/hack/rss.xml','fun',self.prxydict) self.assertFalse(notobj.haserrors) notobj = self.user.addfeed(self.db,'*****@*****.**','http://feeds.feedburner.com/typepad/sethsmainblog','fun',self.prxydict) self.assertFalse(notobj.haserrors) notobj = self.user.getfeedlist(self.db,'*****@*****.**') self.assertTrue(notobj.haserrors) def test_getfeedtree_checkorder(self): notobj = self.user.save(self.db,'*****@*****.**','abc','xyz') self.assertFalse(notobj.haserrors) notobj = self.user.addcategory(self.db,'*****@*****.**','fun') self.assertFalse(notobj.haserrors) notobj = self.user.addfeed(self.db,'*****@*****.**','http://devinder-sharma.blogspot.com/feeds/posts/default','money',self.prxydict) self.assertFalse(notobj.haserrors) notobj = self.user.addfeed(self.db,'*****@*****.**','http://www.readwriteweb.com/hack/rss.xml','fun',self.prxydict) self.assertFalse(notobj.haserrors) notobj = self.user.addfeed(self.db,'*****@*****.**','http://feeds.feedburner.com/typepad/sethsmainblog','fun',self.prxydict) self.assertFalse(notobj.haserrors) notobj = self.user.getfeedlist(self.db,'*****@*****.**') self.assertFalse(notobj.haserrors) self.assertTrue(notobj.result[0]['category']=='fun') def test_getfeeddata_checkindb(self): notobj = self.user.save(self.db,'*****@*****.**','abc','xyz') self.assertFalse(notobj.haserrors) notobj = self.user.addcategory(self.db,'*****@*****.**','fun') self.assertFalse(notobj.haserrors) notobj = self.user.addfeed(self.db,'*****@*****.**','http://devinder-sharma.blogspot.com/feeds/posts/default','money',self.prxydict) self.assertFalse(notobj.haserrors) notobj = self.user.getfeeddata(self.db,'*****@*****.**','http://devinder-sharma.blogspot.com/feeds/posts/default') self.assertFalse(notobj.haserrors) feedinfo = self.db.feeds.find_one({'_id':'http://devinder-sharma.blogspot.com/feeds/posts/default', 'items._id':notobj.result[0]['_id']}) self.assertIsNotNone(feedinfo) self.assertTrue(len(feedinfo['items']) == len(notobj.result)) def test_updateall(self): notobj = self.user.save(self.db,'*****@*****.**','abc','xyz') self.assertFalse(notobj.haserrors) notobj = self.user.addcategory(self.db,'*****@*****.**','fun') self.assertFalse(notobj.haserrors) notobj = self.user.addfeed(self.db,'*****@*****.**','http://devinder-sharma.blogspot.com/feeds/posts/default','money',self.prxydict) self.assertFalse(notobj.haserrors) notobj = self.user.addfeed(self.db,'*****@*****.**','http://www.readwriteweb.com/hack/rss.xml','fun',self.prxydict) self.assertFalse(notobj.haserrors) notobj = self.user.addfeed(self.db,'*****@*****.**','http://feeds.feedburner.com/typepad/sethsmainblog','fun',self.prxydict) self.assertFalse(notobj.haserrors) notobj = self.user.addfeed(self.db,'*****@*****.**','http://zeenut.blogspot.com/feeds/posts/default?alt=rss','fun',self.prxydict) self.assertFalse(notobj.haserrors) notobj = self.user.addfeed(self.db,'*****@*****.**','http://www.spiegel.de/international/index.rss ','fun',self.prxydict) self.assertFalse(notobj.haserrors) notobj = self.feed.updateall(self.db,self.prxydict) self.assertFalse(notobj.haserrors) def test_archivefeeds(self): from datetime import datetime,timedelta from time import mktime from api import Helper notobj = self.user.save(self.db,'*****@*****.**','abc','xyz') self.assertFalse(notobj.haserrors) notobj = self.user.addcategory(self.db,'*****@*****.**','fun') self.assertFalse(notobj.haserrors) notobj = self.user.addfeed(self.db,'*****@*****.**','https://news.ycombinator.com/rss','fun',self.prxydict) self.assertFalse(notobj.haserrors) notobj = self.feed.archivefeeds(self.db,1) self.assertFalse(notobj.haserrors) notobj = self.user.getfeeddata(self.db,'*****@*****.**','https://news.ycombinator.com/rss') self.assertFalse(notobj.haserrors) olderthandate = datetime.now() - timedelta(days=1) olderthandate_ts = Helper.datetotimestamp(olderthandate) for item in notobj.result: self.assertTrue(item['published_date'] is None or item['published_date'] >= olderthandate_ts) def test_markallread(self): from datetime import datetime from time import mktime ts = mktime(datetime.now().timetuple())+1e-6*datetime.now().microsecond notobj = self.user.save(self.db,'*****@*****.**','abc','xyz') self.assertFalse(notobj.haserrors) notobj = self.user.addcategory(self.db,'*****@*****.**','fun') self.assertFalse(notobj.haserrors) notobj = self.user.addfeed(self.db,'*****@*****.**','http://feeds.feedburner.com/TheInvestorBlog','fun',self.prxydict) self.assertFalse(notobj.haserrors) notobj = self.user.getfeeddata(self.db,'*****@*****.**','http://feeds.feedburner.com/TheInvestorBlog') self.assertFalse(notobj.haserrors) notobj = self.user.markallread(self.db,'*****@*****.**','http://feeds.feedburner.com/TheInvestorBlog',ts) self.assertFalse(notobj.haserrors) def test_updatefeed(self): import time from datetime import datetime feedurl = 'https://news.ycombinator.com/rss' notobj = self.user.save(self.db,'*****@*****.**','abc','xyz') self.assertFalse(notobj.haserrors) notobj = self.user.addcategory(self.db,'*****@*****.**','fun') self.assertFalse(notobj.haserrors) notobj = self.user.addfeed(self.db,'*****@*****.**',feedurl,'fun',self.prxydict) self.assertFalse(notobj.haserrors) # print " This is going to sleep for 2 minutes. so pl. wait ..." # time.sleep(120) notobj = self.feed.updatefeed(self.db,feedurl,self.prxydict) self.assertFalse(notobj.haserrors) #now get updated feed data notobj = FeedGateway.getfeed(feedurl,self.prxydict) self.assertFalse(notobj.haserrors) #now check that latest feed is available in DB feed_data = notobj.result fitemdb=None for fitem in feed_data["entries"]: # search if item is already available in DB if fitem.has_key('published_parsed'): pdate = fitem['published_parsed'] else: if fitem.has_key('published'): #http://stackoverflow.com/questions/9516025/parsing-datetime-in-python pdate = parse(fitem['published']) else: pdate = datetime.today() if fitemdb is None: fitemdb = {'uri': fitem['link'],'pdate':pdate} if Helper.datetotimestamp(pdate) > Helper.datetotimestamp(fitemdb['pdate']): fitemdb = {'uri': fitem['link'],'pdate':pdate} self.assertIsNotNone(fitemdb) # print fitemdb # notobj = self.db.feed.find_one({'_id':feedurl}) # self.assertIsNotNone(notobj) # for itm in notobj['items']: # print itm['link'] notobj = self.db.feeds.find_one({'_id':feedurl,'items.link':fitemdb['uri']},{'_id':1}) self.assertIsNotNone(notobj)
def updatefeeds(): feed = Feed() settings = {'http_proxy': 'http://www-proxy.au.oracle.com:80'} db = MongoClient('mongodb://localhost:27017')['feedtest'] feed.updateall(db, settings)
def feed(): config = MsfLib(version="1.0") feed_ = Feed(config) return feed_
def setUp(self): self.db = pymongo.MongoClient("localhost",27017,safe=True).feedtest self.feed = Feed() self.log = logging.getLogger('scheduleit') self.prxydict = {'http_proxy':'http://www-proxy.au.oracle.com:80'}
def setUp(self): self.db = pymongo.MongoClient("localhost", 27017, safe=True).feedtest self.feed = Feed() self.log = logging.getLogger('scheduleit') self.prxydict = {'http_proxy': 'http://www-proxy.au.oracle.com:80'}
import time sys.path.append('../src/') from api import DATABASE, add_index, update_index, INDEX, get_attachment_info, Feed for db_name in DATABASE.database_names(): try: print INDEX.delete_index(db_name) except: continue for db_name in DATABASE.database_names(): print db_name db = DATABASE[db_name] for i in db.stream.find(): record = Feed(i) if record.is_note(): content = record.details.content type_ = 'doc' elif record.is_event(): content = i['name'] + '\n' + i.get('details', '') type_ = 'event' elif record.is_task(): content = i.get('message') type_ = 'task' elif record.is_email(): content = i.get('email') type_ = 'email' elif record.is_file(): content = record.details.name type_ = 'file'