Skip to content

Commit 5fe8302

Browse files
committed
Update test unit
1 parent f2ae71e commit 5fe8302

File tree

5 files changed

+151
-27
lines changed

5 files changed

+151
-27
lines changed

.github/workflows/python-package.yml

Lines changed: 45 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,14 @@ name: Build
55

66
on:
77
push:
8-
branches: [ main ]
8+
branches:
9+
- 'master'
10+
- '[0-9].[0-9]+' # matches to backport branches, e.g. 3.6
11+
- dev
912
pull_request:
10-
branches: [ main ]
13+
branches:
14+
- 'master'
15+
- '[0-9].[0-9]+'
1116
schedule:
1217
- cron: '0 9 1 * *' # Runs at 09:00 UTC on the 1st of every month
1318

@@ -17,26 +22,44 @@ jobs:
1722
runs-on: ${{ matrix.os }}
1823
strategy:
1924
matrix:
20-
os: [macos-latest, ubuntu-latest, windows-latest]
25+
os: [ubuntu-latest]
2126
python-version: ['3.7' , '3.8' , '3.9']
2227

2328
steps:
24-
- uses: actions/checkout@v2
25-
- name: Set up Python ${{ matrix.python-version }}
26-
uses: actions/setup-python@v2
27-
with:
28-
python-version: ${{ matrix.python-version }}
29-
- name: Install dependencies
30-
run: |
31-
python -m pip install --upgrade pip
32-
python -m pip install flake8 pytest pytest-asyncio
33-
pip install -r requirements.txt
34-
- name: Lint with flake8
35-
run: |
36-
# stop the build if there are Python syntax errors or undefined names
37-
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
38-
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
39-
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
40-
- name: Test with pytest
41-
run: |
42-
pytest
29+
- name: Checkout
30+
uses: actions/checkout@v2 # You need to checkout first, then you can use your repo in following actions.
31+
with:
32+
repository: GoodManWEN/oracle-client-action
33+
- name: Setup Oracledb client
34+
uses: GoodManWEN/oracle-client-action@main
35+
- name: Checkout
36+
uses: actions/checkout@v2
37+
with:
38+
repository: GoodManWEN/oracle-11g-server-action
39+
- name: Setup Oracledb 11gR2 server
40+
uses: GoodManWEN/oracle-11g-server-action@main
41+
with:
42+
host port: 1521
43+
oracle version: '1.0.0'
44+
- name: Checkout
45+
uses: actions/checkout@v2
46+
- name: Set up Python ${{ matrix.python-version }}
47+
uses: actions/setup-python@v2
48+
with:
49+
python-version: ${{ matrix.python-version }}
50+
- name: Install dependencies
51+
run: | # sleep to make sure Oracle server is fully loaded
52+
sleep 60
53+
python -m pip install --upgrade pip
54+
python -m pip install flake8 pytest pytest-asyncio
55+
pip install -r requirements.txt
56+
- name: Lint with flake8
57+
run: |
58+
# stop the build if there are Python syntax errors or undefined names
59+
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
60+
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
61+
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
62+
- name: Test with pytest
63+
run: |
64+
sleep 30
65+
pytest

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ Easy to use , buy may not the best practice for efficiency concern.
1818
pip install cx_Oracle_async
1919

2020
## Usage
21-
- Nearly all the same with aiomysql (with very limited functions of cource)
21+
- Nearly all the same with aiomysql (with very limited functions of cource).
22+
- If you're connecting to database which is on a different machine with python process , you need to install oracle client module in order to use this library. Check [cx-Oracle's installation guide](https://cx-oracle.readthedocs.io/en/latest/user_guide/installation.html).
2223
- No automaticly date format transition built-in.
2324

2425
## Performance
@@ -34,6 +35,7 @@ single line insertion | N/A (todo) | N/A | N/A
3435
*You can find performance test codes [here](https://github.com/GoodManWEN/cx_Oracle_async/blob/main/misc).*
3536

3637
## Examples
38+
Before running examples , make sure you've already installed a [oracle client](https://github.com/GoodManWEN/cx_Oracle_async#usage) on your machine.
3739
```Python3
3840
# all_usages.py
3941
import asyncio

cx_Oracle_async/utils.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,16 +137,19 @@ async def create_pool(
137137
maxLifetimeSession=0,
138138
sessionCallback=None,
139139
maxSessionsPerShard=0,
140-
host='localhost',
141-
port='1521',
142-
service_name='orcl',
140+
host=None,
141+
port=None,
142+
service_name=None,
143143
sid=None,
144144
loop=None
145145
):
146146
if loop == None:
147147
loop = asyncio.get_running_loop()
148148
if dsn == None:
149-
dsn = makedsn(host = host, port = port, sid = sid , service_name = service_name)
149+
if service_name != None:
150+
dsn = makedsn(host = host, port = port, sid = sid , service_name = service_name)
151+
else:
152+
dsn = makedsn(host = host, port = port, sid = sid)
150153
pool = cxor.SessionPool(
151154
user=user,
152155
password=password,

tests/test_behavior.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import os , sys
2+
sys.path.append(os.getcwd())
3+
import pytest
4+
import asyncio
5+
from cx_Oracle_async import *
6+
7+
@pytest.mark.asyncio
8+
async def test_new_table():
9+
dsn = makedsn(
10+
host = 'localhost',
11+
port = '1521',
12+
sid = 'xe'
13+
)
14+
oracle_pool = await create_pool(
15+
user = 'system',
16+
password = 'oracle',
17+
dsn = dsn
18+
)
19+
20+
async with oracle_pool.acquire() as connection:
21+
async with connection.cursor() as cursor:
22+
# check if dept exesits
23+
await cursor.execute("SELECT COUNT(*) FROM USER_TABLES WHERE TABLE_NAME = UPPER(:a)" , ('DEPT' , ))
24+
ret = await cursor.fetchone()
25+
assert ret
26+
if ret[0] > 0:
27+
await cursor.execute("DTOP TABLE DEPT")
28+
29+
sql = f"""
30+
CREATE TABLE DEPT
31+
(DEPTNO NUMBER(2) CONSTRAINT PK_DEPT PRIMARY KEY,
32+
DNAME VARCHAR2(14),
33+
LOC VARCHAR2(13)
34+
)
35+
"""
36+
await cursor.execute(sql)
37+
38+
# Single Insertion
39+
sql = "INSERT INTO DEPT(DEPTNO , DNAME , LOC) VALUES (:a , :b , :c)"
40+
await cursor.execute(sql , (10 ,'ACCOUNTING','NEW YORK'))
41+
await connection.commit()
42+
43+
# Multiple Insertion
44+
data = [
45+
(30,'SALES','CHICAGO'),
46+
(40,'OPERATIONS','BOSTON'),
47+
]
48+
await cursor.executemany(sql , data)
49+
await connection.commit()
50+
51+
# Check
52+
await cursor.execute("SELECT DNAME , LOC FROM DEPT WHERE DEPTNO BETWEEN :a AND :b" , (10 , 30))
53+
ret = await cursor.fetchall()
54+
assert len(ret) == 2
55+
assert ret[0][0] == 'ACCOUNTING'
56+
assert ret[1][1] == 'CHICAGO'
57+
58+
await oracle_pool.close()

tests/test_connection.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import os , sys
2+
sys.path.append(os.getcwd())
3+
import pytest
4+
import asyncio
5+
from cx_Oracle_async import *
6+
7+
@pytest.mark.asyncio
8+
async def test_different_connect_ways():
9+
dsn = makedsn(
10+
host = 'localhost',
11+
port = '1521',
12+
sid = 'xe'
13+
)
14+
oracle_pool = await create_pool(
15+
user = 'system',
16+
password = 'oracle',
17+
dsn = dsn
18+
)
19+
ret = await oracle_pool.close()
20+
assert ret == None
21+
22+
oracle_pool = await create_pool(
23+
host = 'localhost',
24+
port = '1521',
25+
user = 'system',
26+
password = 'oracle',
27+
sid = 'xe',
28+
min = 2 ,
29+
max = 4
30+
)
31+
32+
async with oracle_pool.acquire() as connection:
33+
async with connection.cursor() as cursor:
34+
pass
35+
36+
ret = await oracle_pool.close()
37+
assert ret == None
38+

0 commit comments

Comments
 (0)