Ejemplo n.º 1
0
    def test_encode_json_base64(self):
        params = dict()
        params["key1"] = "val1"
        params["key2"] = "val2"
        b64 = Config._encode_json_base64(params)
        self.assertEqual("eyJrZXkxIjogInZhbDEiLCAia2V5MiI6ICJ2YWwyIn0", b64)

        params = Config._decode_json_base64(b64)
        self.assertEqual(2, len(params))
        self.assertEqual("val1", params["key1"])
        self.assertEqual("val2", params["key2"])
Ejemplo n.º 2
0
 def test_to_dsn(self):
     c1 = Config(test_url)
     u1 = c1.to_url()
     c2 = Config(u1)
     self.assertEqual(c1.pop_access_id, c2.pop_access_id)
     self.assertEqual(c1.pop_access_secret, c2.pop_access_secret)
     self.assertEqual(c1.curr_project, c2.curr_project)
     self.assertEqual(c1.scheme, c2.scheme)
     self.assertEqual(c1.withs["CustomerId"], c2.withs["CustomerId"])
     self.assertEqual(c1.withs["PluginName"], c2.withs["PluginName"])
     self.assertEqual(c1.withs["Exec"], c2.withs["Exec"])
     self.assertEqual(c1.env["SKYNET_ACCESSKEY"],
                      c2.env["SKYNET_ACCESSKEY"])
Ejemplo n.º 3
0
 def test_dsn_parsing(self):
     cfg = Config(test_url)
     self.assertEqual("pid", cfg.pop_access_id)
     self.assertEqual("psc", cfg.pop_access_secret)
     self.assertEqual("jtest_env", cfg.curr_project)
     self.assertEqual("http", cfg.scheme)
     self.assertEqual("wcd", cfg.withs["CustomerId"])
     self.assertEqual("wpe", cfg.withs["PluginName"])
     self.assertEqual("wec.sh", cfg.withs["Exec"])
     self.assertEqual("SKY", cfg.env["SKYNET_ACCESSKEY"])
Ejemplo n.º 4
0
 def test_exec_sql_exec(self):
     outtbl = "table_2"
     t = Task(Config.from_env())
     code = "CREATE TABLE IF NOT EXISTS {}(c1 STRING);".format(outtbl)
     time.sleep(2)
     t.exec_sql(code, resultful=False)
     code = "DESCRIBE {};".format(outtbl)
     time.sleep(2)
     res = t.exec_sql(code, resultful=True)
     self.assertTrue(len(res["body"]) > 0)
Ejemplo n.º 5
0
 def test_exec_sql_hint_query(self):
     t = Task(Config.from_env())
     hint = "set odps.sql.select.output.format=\"HumanReadable\";"
     qry = "SELECT 1;"
     goodCode = hint + "\n" + qry
     time.sleep(2)
     t.exec_sql(goodCode)
     badCode = hint + qry
     with self.assertRaises(Exception):
         time.sleep(2)
         t.exec_sql(badCode)
Ejemplo n.º 6
0
 def test_exec_sql_query(self):
     t = Task(Config.from_env())
     code = "SELECT \"Alice\" AS name, 28.3 AS age, 56000 AS salary;"
     time.sleep(2)
     res = t.exec_sql(code, resultful=True)
     # check schema, header
     cols = res["columns"]
     self.assertEqual(cols[0]["name"], "name")
     self.assertEqual(cols[0]["typ"], "string")
     self.assertEqual(cols[1]["name"], "age")
     self.assertEqual(cols[1]["typ"], "double")
     self.assertEqual(cols[2]["name"], "salary")
     self.assertEqual(cols[2]["typ"], "bigint")
     # check body
     self.assertEqual(len(res["body"]), 1)
     row = res["body"][0]
     self.assertEqual(len(row), 3)
     self.assertEqual(row[0], "Alice")
     self.assertEqual(row[1], "28.3")
     self.assertEqual(row[2], "56000")
Ejemplo n.º 7
0
    def test_exec_pyodps(self):
        t = Task(Config.from_env())
        outtbl = "table_2"
        time.sleep(2)
        code = "DROP TABLE IF EXISTS {}".format(outtbl)
        t.exec_sql(code)

        code = """import argparse
if __name__ == "__main__":
    input_table_name = args['input_table']
    output_table_name = args['output_table']
    print(input_table_name)
    print(output_table_name)
    input_table = o.get_table(input_table_name)
    print(input_table.schema)
    output_table = o.create_table(output_table_name, input_table.schema)
        """
        args = "input_table=table_1 output_table={}".format(outtbl)
        time.sleep(2)
        res = t.exec_pyodps(code, args)
        print(res)
Ejemplo n.º 8
0
 def test_parse_error(self):
     # no env and with
     dsn = "alisa://*****:*****@dw.a.hk/?scheme=http&verbose=true"
     self.assertRaises(ValueError, lambda: Config(dsn))
Ejemplo n.º 9
0
 def test_to_dsn(self):
     cfg = Config(test_url)
     url = cfg.to_url()
     self.assertEqual(test_url, url)