Skip to content
This repository was archived by the owner on Jan 22, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 8 additions & 13 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,22 @@ jobs:
# image: datafuselabs/databend-query
image: datafuselabs/databend
env:
DATABEND_DEFAULT_USER: databend
DATABEND_DEFAULT_PASSWORD: databend
# options: >-
# --health-cmd "curl -fs http://localhost:8000/v1/health || exit 1"
# --health-interval 10s
# --health-timeout 5s
# --health-retries 5
QUERY_DEFAULT_USER: databend
QUERY_DEFAULT_PASSWORD: databend
ports:
- 8000:8000
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Setup Go
uses: actions/setup-go@v2
- name: Setup Python-3.10
uses: actions/setup-python@v4
with:
go-version: "1.18"
python-version: '3.10'

- name: Unittest
- name: Pip Install
run: |
make test
make install

- name: Verify Service Running
run: |
Expand All @@ -44,6 +39,6 @@ jobs:

- name: Test
env:
TEST_DATABEND_DSN: "databend://databend:databend@localhost:8000/default?idle_timeout=1h&presigned_url_disabled=1&sslmode=disable"
TEST_DATABEND_DSN: "http://databend:databend@localhost:8000/default"
run: |
make ci
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
test:
python tests/test_client.py

ci:
python tests/test_client.py

install:
pip install -r requirements.txt
pip install -e .
5 changes: 5 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
environs==9.5.0
mysql_connector_repackaged==0.3.1
pytz==2022.5
requests==2.28.1
setuptools==62.3.2
Binary file removed tests/__pycache__/testcase.cpython-39.pyc
Binary file not shown.
27 changes: 0 additions & 27 deletions tests/log.py

This file was deleted.

63 changes: 42 additions & 21 deletions tests/test_client.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
from databend_py.client import Client
from tests.testcase import TestCase
from databend_py import Client
from unittest import TestCase
import types, os


class ClientFromUrlTestCase(TestCase):
class DatabendPyTestCase(TestCase):
def __init__(self, databend_url):
super().__init__()
self.databend_url = databend_url

def assertHostsEqual(self, client, another, msg=None):
self.assertEqual(client.connection.host, another, msg=msg)

Expand All @@ -21,7 +25,7 @@ def test_simple(self):
self.assertEqual(c.connection.password, '')

def test_ordinary_query(self):
ss = '''
select_test = '''
select
null as db,
name as name,
Expand All @@ -32,36 +36,53 @@ def test_ordinary_query(self):
'''
# if use the host from databend cloud, must set the 'ADDITIONAL_HEADERS':
# os.environ['ADDITIONAL_HEADERS'] = 'X-DATABENDCLOUD-TENANT=TENANT,X-DATABENDCLOUD-WAREHOUSE=WAREHOUSE'
c = Client.from_url('http://root:@localhost:8081')
# r = c.execute("select 1", with_column_types=False)
# self.assertEqual(r, [('1',)])
column_types, r = c.execute(ss, with_column_types=True)
print(r)
print(column_types)
c = Client.from_url(self.databend_url)
_, r = c.execute("select 1", with_column_types=False)
self.assertEqual(r, ([(1,)]))
column_types, _ = c.execute(select_test, with_column_types=True)
self.assertEqual(column_types, [('db', 'NULL'), ('name', 'String'), ('schema', 'String'), ('type', 'String')])

# test with_column_types=True
# r = c.execute("select 1", with_column_types=True)
# self.assertEqual(r, [('1', 'UInt8'), ('1',)])
#
r = c.execute("select 1", with_column_types=True)
self.assertEqual(r, ([('1', 'UInt8')], [(1,)]))

def test_batch_insert(self):
c = Client.from_url(self.databend_url)

c.execute('DROP TABLE IF EXISTS test')
c.execute('CREATE TABLE if not exists test (x Int32,y VARCHAR)')
# c.execute('DESC test')
r1 = c.execute('INSERT INTO test (x,y) VALUES (%,%)', [1, 'yy', 2, 'xx'])
c.execute('DESC test')
_, r1 = c.execute('INSERT INTO test (x,y) VALUES (%,%)', [1, 'yy', 2, 'xx'])
# # insert_rows = 1
# self.assertEqual(r1, 1)
self.assertEqual(r1, 2)
_, ss = c.execute('select * from test')
print(ss)
# self.assertEqual(ss, [('1', 'yy')])
self.assertEqual(ss, [(1, 'yy'), (2, 'xx')])

def test_iter_query(self):
c = Client.from_url('http://root:@localhost:8081')
self.assertEqual(c.connection.user, 'root')

result = c.execute_iter("select 1", with_column_types=False)
client = Client.from_url(self.databend_url)
result = client.execute_iter("select 1", with_column_types=False)

self.assertIsInstance(result, types.GeneratorType)
result_list = [i for i in result]
print(result_list)
self.assertEqual(result_list, [1])

self.assertEqual(list(result), [])

def tearDown(self) -> None:
client = Client.from_url(self.databend_url)
client.execute('DROP TABLE IF EXISTS test')
client.disconnect()


if __name__ == '__main__':
print("start test......")
# os.environ['TEST_DATABEND_DSN'] = "http://root:@localhost:8002"
dt = DatabendPyTestCase(databend_url=os.getenv("TEST_DATABEND_DSN"))
dt.test_simple()
dt.test_ordinary_query()
# dt.test_batch_insert()
dt.test_iter_query()
dt.tearDown()
print("end test.....")
39 changes: 0 additions & 39 deletions tests/testcase.py

This file was deleted.