示例#1
0
    def create_charts(self):
        with self.create_app().app_context():
            charts = []
            admin = self.get_user("admin")
            for cx in range(CHARTS_FIXTURE_COUNT - 1):
                charts.append(self.insert_chart(
                    f"name{cx}",
                    [admin.id],
                    1,
                ))
            fav_charts = []
            for cx in range(round(CHARTS_FIXTURE_COUNT / 2)):
                fav_star = FavStar(user_id=admin.id,
                                   class_name="slice",
                                   obj_id=charts[cx].id)
                db.session.add(fav_star)
                db.session.commit()
                fav_charts.append(fav_star)
            yield charts

            # rollback changes
            for chart in charts:
                db.session.delete(chart)
            for fav_chart in fav_charts:
                db.session.delete(fav_chart)
            db.session.commit()
示例#2
0
    def create_saved_queries(self):
        with self.create_app().app_context():
            saved_queries = []
            admin = self.get_user("admin")
            for cx in range(SAVED_QUERIES_FIXTURE_COUNT - 1):
                saved_queries.append(
                    self.insert_default_saved_query(label=f"label{cx}",
                                                    schema=f"schema{cx}"))
            saved_queries.append(
                self.insert_default_saved_query(
                    label=f"label{SAVED_QUERIES_FIXTURE_COUNT}",
                    schema=f"schema{SAVED_QUERIES_FIXTURE_COUNT}",
                    username="******",
                ))

            fav_saved_queries = []
            for cx in range(round(SAVED_QUERIES_FIXTURE_COUNT / 2)):
                fav_star = FavStar(user_id=admin.id,
                                   class_name="query",
                                   obj_id=saved_queries[cx].id)
                db.session.add(fav_star)
                db.session.commit()
                fav_saved_queries.append(fav_star)

            yield saved_queries

            # rollback changes
            for saved_query in saved_queries:
                db.session.delete(saved_query)
            for fav_saved_query in fav_saved_queries:
                db.session.delete(fav_saved_query)
            db.session.commit()
    def create_dashboards(self):
        with self.create_app().app_context():
            dashboards = []
            admin = self.get_user("admin")
            for cx in range(DASHBOARDS_FIXTURE_COUNT - 1):
                dashboards.append(
                    self.insert_dashboard(f"title{cx}", f"slug{cx}", [admin.id])
                )
            fav_dashboards = []
            for cx in range(round(DASHBOARDS_FIXTURE_COUNT / 2)):
                fav_star = FavStar(
                    user_id=admin.id, class_name="Dashboard", obj_id=dashboards[cx].id
                )
                db.session.add(fav_star)
                db.session.commit()
                fav_dashboards.append(fav_star)
            yield dashboards

            # rollback changes
            for dashboard in dashboards:
                db.session.delete(dashboard)
            for fav_dashboard in fav_dashboards:
                db.session.delete(fav_dashboard)
            db.session.commit()