Skip to content
This repository was archived by the owner on Jan 22, 2025. It is now read-only.

Commit e86cb2e

Browse files
authored
feat: add ci and tests (#5)
* add ci and tests * fix * fix * run * fix ci * neat * skip * neat
1 parent e77c2c1 commit e86cb2e

File tree

7 files changed

+64
-100
lines changed

7 files changed

+64
-100
lines changed

.github/workflows/ci.yaml

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,22 @@ jobs:
1414
# image: datafuselabs/databend-query
1515
image: datafuselabs/databend
1616
env:
17-
DATABEND_DEFAULT_USER: databend
18-
DATABEND_DEFAULT_PASSWORD: databend
19-
# options: >-
20-
# --health-cmd "curl -fs http://localhost:8000/v1/health || exit 1"
21-
# --health-interval 10s
22-
# --health-timeout 5s
23-
# --health-retries 5
17+
QUERY_DEFAULT_USER: databend
18+
QUERY_DEFAULT_PASSWORD: databend
2419
ports:
2520
- 8000:8000
2621
steps:
2722
- name: Checkout
2823
uses: actions/checkout@v2
2924

30-
- name: Setup Go
31-
uses: actions/setup-go@v2
25+
- name: Setup Python-3.10
26+
uses: actions/setup-python@v4
3227
with:
33-
go-version: "1.18"
28+
python-version: '3.10'
3429

35-
- name: Unittest
30+
- name: Pip Install
3631
run: |
37-
make test
32+
make install
3833
3934
- name: Verify Service Running
4035
run: |
@@ -44,6 +39,6 @@ jobs:
4439
4540
- name: Test
4641
env:
47-
TEST_DATABEND_DSN: "databend://databend:databend@localhost:8000/default?idle_timeout=1h&presigned_url_disabled=1&sslmode=disable"
42+
TEST_DATABEND_DSN: "http://databend:databend@localhost:8000/default"
4843
run: |
4944
make ci

Makefile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
test:
2+
python tests/test_client.py
3+
4+
ci:
5+
python tests/test_client.py
6+
7+
install:
8+
pip install -r requirements.txt
9+
pip install -e .

requirements.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
environs==9.5.0
2+
mysql_connector_repackaged==0.3.1
3+
pytz==2022.5
4+
requests==2.28.1
5+
setuptools==62.3.2
-1.25 KB
Binary file not shown.

tests/log.py

Lines changed: 0 additions & 27 deletions
This file was deleted.

tests/test_client.py

Lines changed: 42 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1-
from databend_py.client import Client
2-
from tests.testcase import TestCase
1+
from databend_py import Client
2+
from unittest import TestCase
33
import types, os
44

55

6-
class ClientFromUrlTestCase(TestCase):
6+
class DatabendPyTestCase(TestCase):
7+
def __init__(self, databend_url):
8+
super().__init__()
9+
self.databend_url = databend_url
10+
711
def assertHostsEqual(self, client, another, msg=None):
812
self.assertEqual(client.connection.host, another, msg=msg)
913

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

2327
def test_ordinary_query(self):
24-
ss = '''
28+
select_test = '''
2529
select
2630
null as db,
2731
name as name,
@@ -32,36 +36,53 @@ def test_ordinary_query(self):
3236
'''
3337
# if use the host from databend cloud, must set the 'ADDITIONAL_HEADERS':
3438
# os.environ['ADDITIONAL_HEADERS'] = 'X-DATABENDCLOUD-TENANT=TENANT,X-DATABENDCLOUD-WAREHOUSE=WAREHOUSE'
35-
c = Client.from_url('http://root:@localhost:8081')
36-
# r = c.execute("select 1", with_column_types=False)
37-
# self.assertEqual(r, [('1',)])
38-
column_types, r = c.execute(ss, with_column_types=True)
39-
print(r)
40-
print(column_types)
39+
c = Client.from_url(self.databend_url)
40+
_, r = c.execute("select 1", with_column_types=False)
41+
self.assertEqual(r, ([(1,)]))
42+
column_types, _ = c.execute(select_test, with_column_types=True)
43+
self.assertEqual(column_types, [('db', 'NULL'), ('name', 'String'), ('schema', 'String'), ('type', 'String')])
4144

4245
# test with_column_types=True
43-
# r = c.execute("select 1", with_column_types=True)
44-
# self.assertEqual(r, [('1', 'UInt8'), ('1',)])
45-
#
46+
r = c.execute("select 1", with_column_types=True)
47+
self.assertEqual(r, ([('1', 'UInt8')], [(1,)]))
48+
49+
def test_batch_insert(self):
50+
c = Client.from_url(self.databend_url)
51+
4652
c.execute('DROP TABLE IF EXISTS test')
4753
c.execute('CREATE TABLE if not exists test (x Int32,y VARCHAR)')
48-
# c.execute('DESC test')
49-
r1 = c.execute('INSERT INTO test (x,y) VALUES (%,%)', [1, 'yy', 2, 'xx'])
54+
c.execute('DESC test')
55+
_, r1 = c.execute('INSERT INTO test (x,y) VALUES (%,%)', [1, 'yy', 2, 'xx'])
5056
# # insert_rows = 1
51-
# self.assertEqual(r1, 1)
57+
self.assertEqual(r1, 2)
5258
_, ss = c.execute('select * from test')
5359
print(ss)
54-
# self.assertEqual(ss, [('1', 'yy')])
60+
self.assertEqual(ss, [(1, 'yy'), (2, 'xx')])
5561

5662
def test_iter_query(self):
57-
c = Client.from_url('http://root:@localhost:8081')
58-
self.assertEqual(c.connection.user, 'root')
59-
60-
result = c.execute_iter("select 1", with_column_types=False)
63+
client = Client.from_url(self.databend_url)
64+
result = client.execute_iter("select 1", with_column_types=False)
6165

6266
self.assertIsInstance(result, types.GeneratorType)
6367
result_list = [i for i in result]
6468
print(result_list)
6569
self.assertEqual(result_list, [1])
6670

6771
self.assertEqual(list(result), [])
72+
73+
def tearDown(self) -> None:
74+
client = Client.from_url(self.databend_url)
75+
client.execute('DROP TABLE IF EXISTS test')
76+
client.disconnect()
77+
78+
79+
if __name__ == '__main__':
80+
print("start test......")
81+
# os.environ['TEST_DATABEND_DSN'] = "http://root:@localhost:8002"
82+
dt = DatabendPyTestCase(databend_url=os.getenv("TEST_DATABEND_DSN"))
83+
dt.test_simple()
84+
dt.test_ordinary_query()
85+
# dt.test_batch_insert()
86+
dt.test_iter_query()
87+
dt.tearDown()
88+
print("end test.....")

tests/testcase.py

Lines changed: 0 additions & 39 deletions
This file was deleted.

0 commit comments

Comments
 (0)