def setUp(self): self.app = get_application().test_client() self.user_id = UserDao.create('t', 't', '*****@*****.**', '1') self.c_id = [ CrawlerDao.create(self.user_id, 1, '', '', ''), CrawlerDao.create(self.user_id, 2, '', '', '') ] for i in self.c_id: CrawlerDao.update_by_id(i, self.user_id, status=1, data_count=10, total=10, finished=datetime.now()) self.app.set_cookie('localhost', 'u_id', str(self.user_id)) with self.app.session_transaction() as session: session[str(self.user_id)] = 't'
def __init__(self, source, c_type, restaurant_id, cookies, args): self.cookies = cookies self.u_id = cookies.get('u_id') self.id = CrawlerDao.create(self.u_id, restaurant_id, source, c_type, args=json.dumps(args)) UserLogDao.create(self.u_id, u'创建{}爬虫'.format(SOURCES.get(source)))