Skip to content

Commit 0c63e87

Browse files
authored
Merge pull request #5 from cortze/feat/clickhouse-support
Feat/clickhouse support
2 parents 143ed75 + a8cde77 commit 0c63e87

16 files changed

+238
-135
lines changed

.clickhouse.env

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
DB_DRIVER="clickhouse"
2+
DB_USER="test_user"
3+
DB_PASSWORD="password"
4+
DB_HOST="localhost"
5+
DB_PORT="8123"
6+
DB_DATABASE="test_database"
7+
DB_URL="${DB_DRIVER}://${DB_USER}:${DB_PASSWORD}@${DB_HOSTs}:${DB_PORT}/${DB_DATABASE}?x-multi-statement=true"

.env

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

.github/workflows/module_tests.yml

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,39 @@ jobs:
2626
POSTGRES_USER: ${{ env.PG_USER }}
2727
POSTGRES_PASSWORD: ${{ env.PGPASSWORD }}
2828
POSTGRES_DB: ${{ env.PG_DATABASE }}
29+
2930
options: >-
3031
--health-cmd pg_isready
3132
--health-interval 10s
3233
--health-timeout 5s
3334
--health-retries 5
3435
36+
clickhouse:
37+
image: clickhouse/clickhouse-server
38+
env:
39+
CLICKHOUSE_DB: ${{ env.PG_DATABASE }}
40+
CLICKHOUSE_USER: ${{ env.PG_USER }}
41+
CLICKHOUSE_DEFAULT_ACCESS_MANAGEMENT: 1
42+
CLICKHOUSE_PASSWORD: ${{ env.PGPASSWORD }}
43+
ports:
44+
- "8123:8123"
45+
- "9000:9000"
46+
3547
steps:
3648
- uses: actions/checkout@v3
3749

38-
- name: Check psql mounting point
39-
run: |
40-
psql -h localhost -U ${{ env.PG_USER }} -d ${{ env.PG_DATABASE }} -a -f psql/init_test_db.sql
50+
# Install ClickHouse client
51+
- name: Install ClickHouse client
52+
run: curl https://clickhouse.com/ | sh
53+
54+
- name: Init psql database with .sql
55+
run: |
56+
psql -h localhost -U ${{ env.PG_USER }} -d ${{ env.PG_DATABASE }} -a -f sql/docker_init_postgresql_test_db.sql
57+
58+
- name: Init clickhouse database with .sql
59+
run: |
60+
./clickhouse client --user ${{ env.PG_USER }} --password ${{ env.PGPASSWORD }} --multiquery < sql/docker_init_clickhouse_test_db.sql
61+
4162
4263
- name: Set up Python ${{ matrix.python-version }}
4364
uses: actions/setup-python@v3

.postgresql.env

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
DB_DRIVER="postgresql"
2+
DB_USER="test_user"
3+
DB_PASSWORD="password"
4+
DB_HOST="localhost"
5+
DB_PORT="5432"
6+
DB_DATABASE="test_database"
7+
DB_URL="${DB_DRIVER}://${DB_USER}:${DB_PASSWORD}@${DB_HOST}:${DB_PORT}/${DB_DATABASE}"

.template.env

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
DB_DRIVER="postgresql"
2+
DB_USER="test_user"
3+
DB_PASSWORD="password"
4+
DB_HOST="localhost"
5+
DB_PORT="5432"
6+
DB_DATABASE="test_database"
7+
DB_URL="${DB_DRIVER}://${DB_USER}:${DB_PASSWORD}@${DB_HOST}:${DB_PORT}/${DB_DATABASE}"

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,10 @@ from unit_db_test.testcase import DBintegrityTest
4444
```
4545

4646
3. Create a `DBintegrityTest` as if it was a `unittest.TestCase`. It is important to define the path to the `.env` that keeps the Postgres DB credentials:
47+
4748
```python
4849
class TestDBTestModule(DBintegrityTest):
49-
db_config_file = '.env'
50+
db_config_file = '.postgresql.env'
5051
```
5152

5253
4. Create as many `test` functions as pleased:

docker-compose.yaml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,17 @@ services:
1010
- POSTGRES_PASSWORD=${DB_PASSWORD}
1111
- POSTGRES_DB=${DB_DATABASE}
1212
volumes:
13-
- ./psql/docker_init_test_db.sql:/docker-entrypoint-initdb.d/docker_postgres_init.sql
13+
- sql/docker_init_test_db.sql:/docker-entrypoint-initdb.d/docker_postgres_init.sql
14+
15+
clickhouse:
16+
image: clickhouse/clickhouse-server
17+
environment:
18+
- CLICKHOUSE_DB=${DB_DATABASE}
19+
- CLICKHOUSE_USER=${DB_USER}
20+
- CLICKHOUSE_DEFAULT_ACCESS_MANAGEMENT=1
21+
- CLICKHOUSE_PASSWORD=${DB_PASSWORD}
22+
volumes:
23+
- sql/docker_init_clickhouse_test_db.sql:/docker-entrypoint-initdb.d/docker_init_test_db.sql
24+
ports:
25+
- "8123:8123"
26+
- "9000:9000"

psql/init_test_db.sql

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

requirements.txt

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,30 @@
1+
asynch==0.2.3
2+
build==1.0.3
3+
certifi==2023.11.17
4+
charset-normalizer==3.3.2
5+
ciso8601==2.3.1
6+
clickhouse-connect==0.7.0
7+
clickhouse-driver==0.2.6
8+
clickhouse-sqlalchemy==0.3.0
19
greenlet==2.0.2
10+
idna==3.6
11+
leb128==1.0.5
12+
lz4==4.3.3
213
numpy==1.24.4
14+
packaging==23.1
315
pandas==2.0.3
416
psycopg2-binary==2.9.7
17+
pyproject_hooks==1.0.0
518
python-dateutil==2.8.2
619
python-dotenv==1.0.0
720
pytz==2023.3.post1
21+
requests==2.31.0
22+
setuptools-scm==8.0.2
823
six==1.16.0
924
SQLAlchemy==2.0.21
10-
typing-extensions==4.8.0
25+
typing_extensions==4.8.0
1126
tzdata==2023.3
27+
tzlocal==5.2
28+
urllib3==2.2.0
29+
zstandard==0.22.0
30+
zstd==1.5.5.1
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
-- Create custom tables for the testing
2+
CREATE TABLE test_table(
3+
id INT,
4+
integer INT NULL,
5+
text_col TEXT,
6+
attribute_col TEXT NULL,
7+
bool_col BOOL
8+
)
9+
ENGINE = MergeTree
10+
PRIMARY KEY(id);
11+
12+
-- Insert dummy data into test_table
13+
INSERT INTO test_table(
14+
id,
15+
integer,
16+
text_col,
17+
attribute_col,
18+
bool_col)
19+
VALUES
20+
(1, 1, 'first', 'attr_1', false);
21+
22+
INSERT INTO test_table(
23+
id,
24+
integer,
25+
text_col,
26+
attribute_col,
27+
bool_col)
28+
VALUES
29+
(2, 2, 'second', NULL, true);
30+
31+
INSERT INTO test_table(
32+
id,
33+
integer,
34+
text_col,
35+
attribute_col,
36+
bool_col)
37+
VALUES
38+
(3, NULL, 'third', 'attr_1', false);
39+
40+
INSERT INTO test_table(
41+
id,
42+
integer,
43+
text_col,
44+
attribute_col,
45+
bool_col)
46+
VALUES
47+
(4, 4, 'fourth', 'attr_3', true);

0 commit comments

Comments
 (0)