Пример #1
0
    def test_api_database(self):
        self.login("admin")
        self.create_fake_db()
        get_example_database()
        get_main_database()

        arguments = {
            "keys": [],
            "filters": [{
                "col": "expose_in_sqllab",
                "opr": "eq",
                "value": True
            }],
            "order_column": "database_name",
            "order_direction": "asc",
            "page": 0,
            "page_size": -1,
        }
        url = f"api/v1/database/?q={prison.dumps(arguments)}"

        self.assertEqual(
            {"examples", "fake_db_100", "main"},
            {
                r.get("database_name")
                for r in self.get_json_resp(url)["result"]
            },
        )
        self.delete_fake_db()
Пример #2
0
    def create_queries(self):
        with self.create_app().app_context():
            queries = []
            admin_id = self.get_user("admin").id
            alpha_id = self.get_user("alpha").id
            example_database_id = get_example_database().id
            main_database_id = get_main_database().id
            for cx in range(QUERIES_FIXTURE_COUNT - 1):
                queries.append(
                    self.insert_query(
                        example_database_id,
                        admin_id,
                        self.get_random_string(),
                        sql=f"SELECT col1, col2 from table{cx}",
                        rows=cx,
                        status=QueryStatus.SUCCESS if
                        (cx % 2) == 0 else QueryStatus.RUNNING,
                    ))
            queries.append(
                self.insert_query(
                    main_database_id,
                    alpha_id,
                    self.get_random_string(),
                    sql=f"SELECT col1, col2 from table{QUERIES_FIXTURE_COUNT}",
                    rows=QUERIES_FIXTURE_COUNT,
                    status=QueryStatus.SUCCESS,
                ))

            yield queries

            # rollback changes
            for query in queries:
                db.session.delete(query)
            db.session.commit()
Пример #3
0
 def test_get_list_query_filter_database(self):
     """
     Query API: Test get list query filter database
     """
     self.login(username="******")
     database_id = get_main_database().id
     arguments = {
         "filters": [{"col": "database", "opr": "rel_o_m", "value": database_id}]
     }
     uri = f"api/v1/query/?q={prison.dumps(arguments)}"
     rv = self.client.get(uri)
     assert rv.status_code == 200
     data = json.loads(rv.data.decode("utf-8"))
     assert data["count"] == 1
Пример #4
0
 def quote_name(self, name: str):
     if get_main_database().backend in {"presto", "hive"}:
         return get_example_database(
         ).inspector.engine.dialect.identifier_preparer.quote_identifier(
             name)
     return name