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 test_new_task_runs(self): """Test JOB dashboard returns new task runs.""" day = datetime.utcnow() - timedelta(days=2) TaskRunFactory.create(finish_time=day.isoformat()) day = datetime.utcnow() - timedelta(days=1) TaskRunFactory.create(finish_time=day.isoformat()) new_task_runs_week() sql = "select * from dashboard_week_new_task_run;" results = db.session.execute(sql) for row in results: assert row.day_task_runs == 1, row.day_task_runs
def test_materialized_view_refreshed(self, db_mock): """Test JOB dashboard materialized view is refreshed.""" result = MagicMock() result.exists = True results = [result] db_mock.slave_session.execute.return_value = results res = new_task_runs_week() assert db_mock.session.execute.called assert res == 'Materialized view refreshed'
def test_admin_dashboard_admin_user_data(self): """Test ADMIN dashboard admins can access it with data""" url = '/admin/dashboard/' self.register() self.new_project() self.new_task(1) import pybossa.dashboard.jobs as dashboard dashboard.active_anon_week() dashboard.active_users_week() dashboard.new_users_week() dashboard.new_tasks_week() dashboard.new_task_runs_week() dashboard.new_projects_week() dashboard.update_projects_week() dashboard.returning_users_week() res = self.app.get(url, follow_redirects=True) err_msg = "It should return 200" assert res.status_code == 200, err_msg assert "No data" not in res.data, res.data assert "New Users" in res.data, res.data