def test_returns_each_dashboard_once(self): db.session.flush() db.session.add_all([ models.Event(org=self.factory.org, user=self.u1, action="view", object_type="dashboard", object_id=self.w1.dashboard.id), models.Event(org=self.factory.org, user=self.u1, action="view", object_type="dashboard", object_id=self.w1.dashboard.id) ]) db.session.flush() dashboards = list(models.Dashboard.recent(self.u1.org, self.u1.group_ids, None)) self.assertEqual(len(dashboards), 1)
def test_recent_excludes_drafts(self): models.db.session.add_all([ models.Event(org=self.factory.org, user=self.u1, action="view", object_type="dashboard", object_id=self.w1.dashboard.id), models.Event(org=self.factory.org, user=self.u1, action="view", object_type="dashboard", object_id=self.w2.dashboard.id)]) self.w2.dashboard.is_draft = True self.assertIn(self.w1.dashboard, models.Dashboard.recent( self.u1.org, self.u1.group_ids, None)) self.assertNotIn(self.w2.dashboard, models.Dashboard.recent( self.u1.org, self.u1.group_ids, None))
def test_respects_groups(self): q1 = self.factory.create_query() ds = self.factory.create_data_source(group=self.factory.create_group()) q2 = self.factory.create_query(data_source=ds) db.session.flush() models.Event(org=self.factory.org, user=self.factory.user, action="edit", object_type="query", object_id=q1.id) models.Event(org=self.factory.org, user=self.factory.user, action="edit", object_type="query", object_id=q2.id) recent = models.Query.recent([self.factory.default_group.id]) self.assertIn(q1, recent) self.assertNotIn(q2, recent)
def test_returns_recent_dashboards_basic(self): db.session.add(models.Event(org=self.factory.org, user=self.u1, action="view", object_type="dashboard", object_id=self.w1.dashboard.id)) db.session.flush() self.assertIn(self.w1.dashboard, models.Dashboard.recent(self.u1.org, self.u1.group_ids, None)) self.assertNotIn(self.w2.dashboard, models.Dashboard.recent(self.u1.org, self.u1.group_ids, None)) self.assertNotIn(self.w1.dashboard, models.Dashboard.recent(self.u1.org, self.u2.group_ids, None))
def test_recent_excludes_drafts(self): q1 = self.factory.create_query() q2 = self.factory.create_query(is_draft=True) models.db.session.add_all([ models.Event(org=self.factory.org, user=self.factory.user, action="edit", object_type="query", object_id=q1.id), models.Event(org=self.factory.org, user=self.factory.user, action="edit", object_type="query", object_id=q2.id) ]) recent = models.Query.recent([self.factory.default_group.id]) self.assertIn(q1, recent) self.assertNotIn(q2, recent)
def test_returns_recent_dashboards_created_by_user(self): d1 = self.factory.create_dashboard(user=self.u1, is_draft=False) db.session.flush() db.session.add(models.Event(org=self.factory.org, user=self.u1, action="view", object_type="dashboard", object_id=d1.id)) self.assertIn(d1, models.Dashboard.recent(self.u1.org, [0], self.u1.id)) self.assertNotIn(self.w2.dashboard, models.Dashboard.recent(self.u1.org, [0], self.u1.id)) self.assertNotIn(d1, models.Dashboard.recent(self.u2.org, [0], self.u2.id))
def test_returns_recent_dashboards_with_no_visualizations(self): w1 = self.factory.create_widget(visualization=None) w1.dashboard.is_draft = False db.session.flush() db.session.add(models.Event(org=self.factory.org, user=self.u1, action="view", object_type="dashboard", object_id=w1.dashboard.id)) db.session.flush() self.assertIn(w1.dashboard, models.Dashboard.recent(self.u1.org, [0], self.u1.id)) self.assertNotIn(self.w2.dashboard, models.Dashboard.recent(self.u1.org, [0], self.u1.id))
def test_restricts_dashboards_for_user(self): db.session.flush() db.session.add_all([ models.Event(org=self.factory.org, user=self.u1, action="view", object_type="dashboard", object_id=self.w1.dashboard.id), models.Event(org=self.factory.org, user=self.u2, action="view", object_type="dashboard", object_id=self.w2.dashboard.id), models.Event(org=self.factory.org, user=self.u1, action="view", object_type="dashboard", object_id=self.w5.dashboard.id), models.Event(org=self.factory.org, user=self.u2, action="view", object_type="dashboard", object_id=self.w5.dashboard.id) ]) db.session.flush() self.assertIn(self.w1.dashboard, models.Dashboard.recent(self.u1.org, self.u1.group_ids, self.u1.id, for_user=True)) self.assertIn(self.w2.dashboard, models.Dashboard.recent(self.u2.org, self.u2.group_ids, self.u2.id, for_user=True)) self.assertNotIn(self.w1.dashboard, models.Dashboard.recent(self.u2.org, self.u2.group_ids, self.u2.id, for_user=True)) self.assertNotIn(self.w2.dashboard, models.Dashboard.recent(self.u1.org, self.u1.group_ids, self.u1.id, for_user=True)) self.assertIn(self.w5.dashboard, models.Dashboard.recent(self.u1.org, self.u1.group_ids, self.u1.id, for_user=True)) self.assertIn(self.w5.dashboard, models.Dashboard.recent(self.u2.org, self.u2.group_ids, self.u2.id, for_user=True))
def test_global_recent(self): q1 = self.factory.create_query() q2 = self.factory.create_query() db.session.flush() e = models.Event(org=self.factory.org, user=self.factory.user, action="edit", object_type="query", object_id=q1.id) db.session.add(e) recent = models.Query.recent([self.factory.default_group.id]) self.assertIn(q1, recent) self.assertNotIn(q2, recent)
def test_returns_dashboards_from_current_org_only(self): w1 = self.factory.create_widget(visualization=None) w1.dashboard.is_draft = False db.session.flush() db.session.add(models.Event( org=self.factory.org, user=self.u1, action="view", object_type="dashboard", object_id=w1.dashboard.id)) db.session.flush() user = self.factory.create_user(org=self.factory.create_org()) self.assertIn(w1.dashboard, models.Dashboard.recent(self.u1.org, self.u1.group_ids, None)) self.assertNotIn(w1.dashboard, models.Dashboard.recent(user.org, user.group_ids, None))