def test_format_new_task_runs_emtpy(self, db_mock): """Test format new task_runs empty works.""" db_mock.slave_session.execute.return_value = [] new_task_runs_week() res = format_new_task_runs() assert len(res['labels']) == 1 day = datetime.utcnow().strftime('%Y-%m-%d') assert res['labels'][0] == day, res assert len(res['series']) == 1 assert res['series'][0][0] == 0, res['series'][0][0]
def test_format_new_task_runs(self): """Test format new task_runs works.""" TaskRunFactory.create() AnonymousTaskRunFactory.create() new_task_runs_week() res = format_new_task_runs() assert len(res['labels']) == 1 day = datetime.utcnow().strftime('%Y-%m-%d') assert res['labels'][0] == day, res assert len(res['series']) == 1 assert res['series'][0][0] == 2, res['series'][0][0]
def dashboard(): """Show PYBOSSA Dashboard.""" try: if request.args.get('refresh') == '1': db_jobs = get_dashboard_jobs() for j in db_jobs: DASHBOARD_QUEUE.enqueue(j['name']) msg = gettext('Dashboard jobs enqueued,' ' refresh page in a few minutes') flash(msg) active_users_last_week = dashb.format_users_week() active_anon_last_week = dashb.format_anon_week() draft_projects_last_week = dashb.format_draft_projects() published_projects_last_week = dashb.format_published_projects() update_projects_last_week = dashb.format_update_projects() new_tasks_week = dashb.format_new_tasks() new_task_runs_week = dashb.format_new_task_runs() new_users_week = dashb.format_new_users() returning_users_week = dashb.format_returning_users() update_feed = get_update_feed() response = dict( template='admin/dashboard.html', title=gettext('Dashboard'), active_users_last_week=active_users_last_week, active_anon_last_week=active_anon_last_week, draft_projects_last_week=draft_projects_last_week, published_projects_last_week=published_projects_last_week, update_projects_last_week=update_projects_last_week, new_tasks_week=new_tasks_week, new_task_runs_week=new_task_runs_week, new_users_week=new_users_week, returning_users_week=returning_users_week, update_feed=update_feed, wait=False) return handle_content_type(response) except ProgrammingError as e: response = dict(template='admin/dashboard.html', title=gettext('Dashboard'), wait=True) return handle_content_type(response) except Exception as e: # pragma: no cover current_app.logger.error(e) return abort(500)