Skip to content

Commit b6b4a71

Browse files
add ci test for different databases
1 parent f4dba25 commit b6b4a71

File tree

6 files changed

+76
-8
lines changed

6 files changed

+76
-8
lines changed

.github/workflows/ci-build.yml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,72 @@ jobs:
114114
token: ${{ secrets.CODECOV_TOKEN }}
115115
verbose: true
116116

117+
databases:
118+
name: Database Unit Tests
119+
runs-on: ubuntu-latest
120+
strategy:
121+
matrix:
122+
include:
123+
- database: postgres
124+
sync_url: postgresql://test_user:password@localhost/test
125+
async_url: postgresql+asyncpg://test_user:password@localhost/test
126+
- database: mysql
127+
sync_url: mysql+pymysql://test_user:password@localhost/test
128+
async_url: mysql+aiomysql://test_user:password@localhost/test
129+
services:
130+
postgres:
131+
image: postgres:16
132+
env:
133+
POSTGRES_USER: test_user
134+
POSTGRES_PASSWORD: password
135+
POSTGRES_DB: test
136+
ports:
137+
- 5432:5432
138+
mysql:
139+
image: mysql:8.0
140+
env:
141+
MYSQL_USER: test_user
142+
MYSQL_PASSWORD: password
143+
MYSQL_DATABASE: test
144+
MYSQL_RANDOM_ROOT_PASSWORD: "yes"
145+
ports:
146+
- 3306:3306
147+
steps:
148+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
149+
with:
150+
persist-credentials: false
151+
- name: Set up Python ${{ env.LATEST_SUPPORTED_PY }}
152+
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
153+
with:
154+
python-version: ${{ env.LATEST_SUPPORTED_PY }}
155+
cache: pip
156+
- name: Install dependencies
157+
run: |
158+
pip install -U pip
159+
pip install -r requirements/testing.txt
160+
pip install -r requirements/optional.txt
161+
pip install -r requirements/databases.txt
162+
- name: Run sync tests (${{ matrix.database }})
163+
env:
164+
TEST_DATABASE_URL: ${{ matrix.sync_url }}
165+
run: |
166+
PYTHONPATH=$PWD:$PYTHONPATH pytest tests/slack_sdk/oauth/installation_store/test_sqlalchemy.py
167+
PYTHONPATH=$PWD:$PYTHONPATH pytest tests/slack_sdk/oauth/state_store/test_sqlalchemy.py
168+
- name: Run async tests (${{ matrix.database }})
169+
env:
170+
ASYNC_TEST_DATABASE_URL: ${{ matrix.async_url }}
171+
run: |
172+
PYTHONPATH=$PWD:$PYTHONPATH pytest tests/slack_sdk/oauth/installation_store/test_async_sqlalchemy.py
173+
PYTHONPATH=$PWD:$PYTHONPATH pytest tests/slack_sdk/oauth/state_store/test_async_sqlalchemy.py
174+
117175
notifications:
118176
name: Regression notifications
119177
runs-on: ubuntu-latest
120178
needs:
121179
- lint
122180
- typecheck
123181
- unittest
182+
- databases
124183
if: ${{ !success() && github.ref == 'refs/heads/main' && github.event_name != 'workflow_dispatch' }}
125184
steps:
126185
- name: Send notifications of failing tests

requirements/databases.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Database drivers for CI testing
2+
3+
# PostgreSQL drivers
4+
psycopg2-binary>=2.9,<3
5+
asyncpg>=0.27,<1
6+
7+
# MySQL drivers
8+
PyMySQL>=1.0,<2
9+
aiomysql>=0.1,<1

tests/slack_sdk/oauth/installation_store/test_async_sqlalchemy.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import os
12
import unittest
23
from tests.helpers import async_test
34
from sqlalchemy.ext.asyncio import AsyncEngine, create_async_engine
@@ -11,7 +12,7 @@ class TestAsyncSQLAlchemy(unittest.TestCase):
1112

1213
@async_test
1314
async def setUp(self):
14-
self.engine = create_async_engine("sqlite+aiosqlite:///:memory:")
15+
self.engine = create_async_engine(os.environ.get("ASYNC_TEST_DATABASE_URL", "sqlite+aiosqlite:///:memory:"))
1516
self.store = AsyncSQLAlchemyInstallationStore(client_id="111.222", engine=self.engine)
1617
async with self.engine.begin() as conn:
1718
await conn.run_sync(self.store.metadata.create_all)
@@ -298,7 +299,6 @@ async def test_issue_1441_mixing_user_and_bot_installations(self):
298299
self.assertIsNone(installation)
299300

300301
async def test_timezone_aware_datetime_compatibility(self):
301-
"""Test that timezone-aware datetimes work with database storage"""
302302
installation = Installation(
303303
app_id="A111",
304304
enterprise_id="E111",

tests/slack_sdk/oauth/installation_store/test_sqlalchemy.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import os
12
import unittest
23

34
import sqlalchemy
@@ -11,7 +12,7 @@ class TestSQLAlchemy(unittest.TestCase):
1112
engine: Engine
1213

1314
def setUp(self):
14-
self.engine = sqlalchemy.create_engine("sqlite:///:memory:")
15+
self.engine = sqlalchemy.create_engine(os.environ.get("TEST_DATABASE_URL", "sqlite:///:memory:"))
1516
self.store = SQLAlchemyInstallationStore(client_id="111.222", engine=self.engine)
1617
self.store.metadata.create_all(self.engine)
1718

@@ -291,7 +292,6 @@ def test_issue_1441_mixing_user_and_bot_installations(self):
291292
self.assertIsNone(installation)
292293

293294
def test_timezone_aware_datetime_compatibility(self):
294-
"""Test that timezone-aware datetimes work with database storage"""
295295
installation = Installation(
296296
app_id="A111",
297297
enterprise_id="E111",

tests/slack_sdk/oauth/state_store/test_async_sqlalchemy.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import asyncio
2+
import os
23
import unittest
34
from tests.helpers import async_test
45
from sqlalchemy.ext.asyncio import AsyncEngine, create_async_engine
@@ -11,7 +12,7 @@ class TestSQLAlchemy(unittest.TestCase):
1112

1213
@async_test
1314
async def setUp(self):
14-
self.engine = create_async_engine("sqlite+aiosqlite:///:memory:")
15+
self.engine = create_async_engine(os.environ.get("ASYNC_TEST_DATABASE_URL", "sqlite+aiosqlite:///:memory:"))
1516
self.store = AsyncSQLAlchemyOAuthStateStore(engine=self.engine, expiration_seconds=2)
1617
async with self.engine.begin() as conn:
1718
await conn.run_sync(self.store.metadata.create_all)
@@ -39,7 +40,6 @@ async def test_expiration(self):
3940

4041
@async_test
4142
async def test_timezone_aware_datetime_compatibility(self):
42-
"""Test that timezone-aware datetimes work with database storage"""
4343
# Issue a state (tests INSERT with timezone-aware datetime)
4444
state = await self.store.async_issue()
4545
self.assertIsNotNone(state)

tests/slack_sdk/oauth/state_store/test_sqlalchemy.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import os
12
import time
23
import unittest
34

@@ -11,7 +12,7 @@ class TestSQLAlchemy(unittest.TestCase):
1112
engine: Engine
1213

1314
def setUp(self):
14-
self.engine = sqlalchemy.create_engine("sqlite:///:memory:")
15+
self.engine = sqlalchemy.create_engine(os.environ.get("TEST_DATABASE_URL", "sqlite:///:memory:"))
1516
self.store = SQLAlchemyOAuthStateStore(engine=self.engine, expiration_seconds=2)
1617
self.store.metadata.create_all(self.engine)
1718

@@ -33,7 +34,6 @@ def test_expiration(self):
3334
self.assertFalse(result)
3435

3536
def test_timezone_aware_datetime_compatibility(self):
36-
"""Test that timezone-aware datetimes work with database storage"""
3737
# Issue a state (tests INSERT with timezone-aware datetime)
3838
state = self.store.issue()
3939
self.assertIsNotNone(state)

0 commit comments

Comments
 (0)