def test_search_logs(self): """ Test the search_logs function. """ self.test_add_package() # Wrong limit self.assertRaises(pkgdblib.PkgdbException, pkgdblib.search_logs, self.session, limit='a') # Wrong offset self.assertRaises(pkgdblib.PkgdbException, pkgdblib.search_logs, self.session, page='a') # Wrong package name self.assertRaises(pkgdblib.PkgdbException, pkgdblib.search_logs, self.session, package='asdads') logs = pkgdblib.search_logs(self.session) self.assertEqual(len(logs), 21) self.assertEqual( logs[0].description, "user: admin created " "package: guake on branch: F-18 for poc: ralph") self.assertEqual(logs[0].user, "admin") self.assertEqual( logs[3].description, "user: admin set acl: " "watchcommits of package: guake from: Approved to:" " Approved on branch: F-18") logs = pkgdblib.search_logs(self.session, limit=3, page=2) self.assertEqual(len(logs), 3) self.assertEqual( logs[0].description, "user: admin set acl: " "watchcommits of package: guake from: Approved to:" " Approved on branch: F-18") self.assertEqual(logs[0].user, "admin") exp = "Log(user=u'admin', description=u'user: admin set acl: " \ "watchcommits of package: guake from: Approved to:" \ " Approved on branch: F-18" self.assertTrue(logs[0].__repr__().startswith(exp)) logs = pkgdblib.search_logs(self.session, count=True) self.assertEqual(logs, 21) logs = pkgdblib.search_logs(self.session, from_date=date.today()) self.assertEqual(len(logs), 21) logs = pkgdblib.search_logs(self.session, from_date=date.today(), package='guake') self.assertEqual(len(logs), 5)
def test_search_logs(self): """ Test the search_logs function. """ self.test_add_package() # Wrong limit self.assertRaises(pkgdblib.PkgdbException, pkgdblib.search_logs, self.session, limit='a' ) # Wrong offset self.assertRaises(pkgdblib.PkgdbException, pkgdblib.search_logs, self.session, page='a' ) # Wrong package name self.assertRaises(pkgdblib.PkgdbException, pkgdblib.search_logs, self.session, package='asdads' ) logs = pkgdblib.search_logs(self.session) self.assertEqual(len(logs), 21) self.assertEqual(logs[0].description, "user: admin created " "package: guake on branch: F-18 for poc: ralph") self.assertEqual(logs[0].user, "admin") self.assertEqual(logs[3].description, "user: admin set acl: " "watchcommits of package: guake from: Approved to:" " Approved on branch: F-18") logs = pkgdblib.search_logs(self.session, limit=3, page=2) self.assertEqual(len(logs), 3) self.assertEqual(logs[0].description, "user: admin set acl: " "watchcommits of package: guake from: Approved to:" " Approved on branch: F-18") self.assertEqual(logs[0].user, "admin") exp = "Log(user=u'admin', description=u'user: admin set acl: " \ "watchcommits of package: guake from: Approved to:" \ " Approved on branch: F-18" self.assertTrue(logs[0].__repr__().startswith(exp)) logs = pkgdblib.search_logs(self.session, count=True) self.assertEqual(logs, 21) logs = pkgdblib.search_logs(self.session, from_date=date.today()) self.assertEqual(len(logs), 21) logs = pkgdblib.search_logs( self.session, from_date=date.today(), package='guake') self.assertEqual(len(logs), 5)
def admin_log(): """ Return the logs as requested by the user. """ cnt_logs = pkgdblib.search_logs(SESSION, count=True) from_date = flask.request.args.get('from_date', None) package = flask.request.args.get('package', None) refresh = flask.request.args.get('refresh', False) limit = flask.request.args.get('limit', APP.config['ITEMS_PER_PAGE']) page = flask.request.args.get('page', 1) try: page = int(page) except ValueError: page = 1 try: int(limit) except ValueError: limit = APP.config['ITEMS_PER_PAGE'] flask.flash('Incorrect limit provided, using default', 'errors') if from_date: try: from_date = parser.parse(from_date) except (ValueError, TypeError): flask.flash( 'Incorrect from_date provided, using default', 'errors') from_date = None if from_date: from_date = from_date.date() logs = [] try: logs = pkgdblib.search_logs( SESSION, package=package or None, from_date=from_date, page=page, limit=limit, ) except pkgdblib.PkgdbException, err: flask.flash(err, 'errors')
def admin_log(): """ Return the logs as requested by the user. """ cnt_logs = pkgdblib.search_logs(SESSION, count=True) from_date = flask.request.args.get('from_date', None) package = flask.request.args.get('package', None) limit = flask.request.args.get('limit', APP.config['ITEMS_PER_PAGE']) page = flask.request.args.get('page', 1) try: page = int(page) except ValueError: page = 1 try: int(limit) except ValueError: limit = APP.config['ITEMS_PER_PAGE'] flask.flash('Incorrect limit provided, using default', 'errors') if from_date: try: from_date = parser.parse(from_date).date() except ValueError: flask.flash( 'Incorrect from_date provided, using default', 'errors') from_date = None logs = [] try: logs = pkgdblib.search_logs( SESSION, package=package or None, from_date=from_date, page=page, limit=limit, ) except pkgdblib.PkgdbException, err: flask.flash(err, 'errors')