|
| 1 | +import requests |
| 2 | + |
| 3 | + |
| 4 | +query_url = "http://localhost:8000/v1/query" |
| 5 | +streaming_url = "http://localhost:8000/v1/streaming_load" |
| 6 | +upload_url = "http://localhost:8000/v1/upload_to_stage" |
| 7 | +auth = ("root", "") |
| 8 | + |
| 9 | + |
| 10 | +def execute_sql(sql): |
| 11 | + payload = {"sql": sql, "pagination": {"wait_time_secs": 6}} |
| 12 | + response = requests.post( |
| 13 | + query_url, auth=auth, headers={"Content-Type": "application/json"}, json=payload |
| 14 | + ) |
| 15 | + return response.json() |
| 16 | + |
| 17 | + |
| 18 | +def missing_at_upload(): |
| 19 | + return {"upload": (None, "./abc.json")} |
| 20 | + |
| 21 | + |
| 22 | +def test_upload_to_stage_requires_file_upload(): |
| 23 | + stage_name = "missing_at_stage" |
| 24 | + assert execute_sql(f"drop stage if exists {stage_name}")["error"] == None |
| 25 | + assert execute_sql(f"create stage {stage_name}")["error"] == None |
| 26 | + |
| 27 | + try: |
| 28 | + response = requests.put( |
| 29 | + upload_url, |
| 30 | + auth=auth, |
| 31 | + headers={"x-databend-stage-name": stage_name}, |
| 32 | + files=missing_at_upload(), |
| 33 | + ) |
| 34 | + |
| 35 | + assert response.status_code == 400 |
| 36 | + assert "expected a file upload with a filename" in response.text |
| 37 | + assert "did you forget the '@'" in response.text.lower() |
| 38 | + assert "upload=@/path/to/file" in response.text |
| 39 | + finally: |
| 40 | + assert execute_sql(f"drop stage if exists {stage_name}")["error"] == None |
| 41 | + |
| 42 | + |
| 43 | +def test_streaming_load_requires_file_upload(): |
| 44 | + table_name = "missing_at_streaming" |
| 45 | + assert execute_sql(f"drop table if exists {table_name}")["error"] == None |
| 46 | + assert execute_sql(f"create table {table_name} (a string)")["error"] == None |
| 47 | + |
| 48 | + try: |
| 49 | + response = requests.put( |
| 50 | + streaming_url, |
| 51 | + auth=auth, |
| 52 | + headers={ |
| 53 | + "X-Databend-SQL": f"insert into {table_name} from @_databend_load file_format = (type = csv)", |
| 54 | + "x-databend-query-id": "missing-at-streaming-load", |
| 55 | + }, |
| 56 | + files=missing_at_upload(), |
| 57 | + ) |
| 58 | + |
| 59 | + assert response.status_code == 400 |
| 60 | + assert "expected a file upload with a filename" in response.text |
| 61 | + assert "did you forget the '@'" in response.text.lower() |
| 62 | + assert "upload=@/path/to/file" in response.text |
| 63 | + finally: |
| 64 | + assert execute_sql(f"drop table if exists {table_name}")["error"] == None |
0 commit comments