def test_recent_for_user(self): q1 = self.factory.create_query() q2 = self.factory.create_query() db.session.flush() e = Event(org=self.factory.org, user=self.factory.user, action="edit", object_type="query", object_id=q1.id) db.session.add(e) recent = Query.recent([self.factory.default_group.id], user_id=self.factory.user.id) self.assertIn(q1, recent) self.assertNotIn(q2, recent) recent = Query.recent([self.factory.default_group.id], user_id=self.factory.user.id + 1) self.assertNotIn(q1, recent) self.assertNotIn(q2, recent)
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() Event(org=self.factory.org, user=self.factory.user, action="edit", object_type="query", object_id=q1.id) Event(org=self.factory.org, user=self.factory.user, action="edit", object_type="query", object_id=q2.id) recent = Query.recent([self.factory.default_group.id]) self.assertIn(q1, recent) self.assertNotIn(q2, recent)
def test_recent_excludes_drafts(self): q1 = self.factory.create_query() q2 = self.factory.create_query(is_draft=True) db.session.add_all([ Event(org=self.factory.org, user=self.factory.user, action="edit", object_type="query", object_id=q1.id), Event(org=self.factory.org, user=self.factory.user, action="edit", object_type="query", object_id=q2.id) ]) recent = Query.recent([self.factory.default_group.id]) self.assertIn(q1, recent) self.assertNotIn(q2, recent)