Skip to content

Commit

Permalink
Merge pull request #44 from Mapepire-IBMi/update/add_tests
Browse files Browse the repository at this point in the history
Update/add tests
  • Loading branch information
ajshedivy authored Aug 8, 2024
2 parents 3163c6e + 4b13cf0 commit 4243cbe
Show file tree
Hide file tree
Showing 7 changed files with 124 additions and 65 deletions.
1 change: 1 addition & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Changes proposed in this pull request:
## Before submitting

<!-- Please complete this checklist BEFORE submitting your PR to speed along the review process. -->
- [ ] Change the base branch to `dev` if it is not already.
- [ ] I've read and followed all steps in the [Making a pull request](https://github.com/ajshedivy/python-wsdb/blob/main/.github/CONTRIBUTING.md#making-a-pull-request)
section of the `CONTRIBUTING` docs.
- [ ] I've updated or added any relevant docstrings following the syntax described in the
Expand Down
29 changes: 29 additions & 0 deletions .github/workflows/changelog.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: ChangeLog

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

on:
pull_request:
branches:
- main
- dev

jobs:
changelog:
name: CHANGELOG
runs-on: ubuntu-latest
if: github.event_name == 'pull_request'

steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Check that CHANGELOG has been updated
run: |
# If this step fails, this means you haven't updated the CHANGELOG.md
# file with notes on your contribution.
git diff --name-only $(git merge-base origin/main HEAD) | grep '^CHANGELOG.md$' && echo "Thanks for helping keep our CHANGELOG up-to-date!"
28 changes: 27 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,14 @@ permissions:

on:
pull_request:
branches:
- "*"
push:
branches:
- main
- dev
tags:
- "v*.*.*"

env:
# Change this to invalidate existing cache.
Expand Down Expand Up @@ -70,6 +76,19 @@ jobs:
python-version: ${{ matrix.python }}
cache-prefix: ${{ env.CACHE_PREFIX }}

- name: Check if PR is from a fork
id: check_fork
run: |
echo "is_fork=${{ github.event.pull_request.head.repo.fork }}" >> $GITHUB_ENV
- name: check if PR is from a fork
if: env.is_fork == 'true'
run: echo "This PR is from a fork. skipping pyest."

- name: Skip if not from fork
if: env.is_fork != 'true'
run: echo "This PR is not from a fork. Running pytest."

- name: Restore mypy cache
if: matrix.task.name == 'Type check'
uses: actions/cache@v3
Expand All @@ -80,7 +99,8 @@ jobs:
mypy-${{ env.CACHE_PREFIX }}-${{ runner.os }}-${{ matrix.python }}-${{ hashFiles('*requirements.txt') }}-${{ github.ref }}
mypy-${{ env.CACHE_PREFIX }}-${{ runner.os }}-${{ matrix.python }}-${{ hashFiles('*requirements.txt') }}
- name: ${{ matrix.task.name }}
- name: Run Python tests
if: env.is_fork != 'true' && matrix.task.name == 'Test'
run: |
. .venv/bin/activate
${{ matrix.task.run }}
Expand All @@ -89,6 +109,12 @@ jobs:
VITE_DB_USER: ${{ secrets.VITE_DB_USER }}
VITE_DB_PASS: ${{ secrets.VITE_DB_PASS }}

- name: ${{ matrix.task.name }}
if: matrix.task.name != 'Test'
run: |
. .venv/bin/activate
${{ matrix.task.run }}
- name: Upload package distribution files
if: matrix.task.name == 'Build'
uses: actions/upload-artifact@v3
Expand Down
62 changes: 0 additions & 62 deletions .github/workflows/pr_checks.yml

This file was deleted.

2 changes: 0 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.4.1
Expand Down
4 changes: 4 additions & 0 deletions environment-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ dependencies:
- pip
- python-dotenv
- pytest-env
- isort
- black
- ruff
- mypy
- pip:
- dataclasses-json>=0.6.4
- websocket-client>=1.2.1
63 changes: 63 additions & 0 deletions tests/simple_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import re

from python_wsdb.client.sql_job import SQLJob
from python_wsdb.types import DaemonServer
Expand All @@ -20,10 +21,72 @@
ignoreUnauthorized=True,
)


def parse_sql_rc(message):
match = re.search(r"'sql_rc': (-?\d+)", message)
if match:
return int(match.group(1))
else:
return None


def test_simple():
job = SQLJob()
_ = job.connect(creds)
query = job.query("select * from sample.employee")
result = query.run(rows_to_fetch=5)
assert result["success"]
job.close()


def test_query_and_run():
job = SQLJob()
_ = job.connect(creds)
result = job.query_and_run("select * from sample.employee", rows_to_fetch=5)
assert result["success"]
job.close()


def test_paging():
job = SQLJob()
_ = job.connect(creds)
query = job.query("select * from sample.employee")
result = query.run(rows_to_fetch=5)
while True:
assert result["data"] is not None and len(result["data"]) > 0
print(result)
if result["is_done"]:
break

result = query.fetch_more(rows_to_fetch=5)

job.close()


def test_error():
job = SQLJob()
_ = job.connect(creds)

query = job.query("select * from thisisnotreal")

try:
query.run()
except Exception as e:
message = str(e)

assert parse_sql_rc(message) == -204

job.close()


def test_multiple_statements():
job = SQLJob()
_ = job.connect(creds)

resA = job.query("select * from sample.department").run()
assert resA["success"] is True

resB = job.query("select * from sample.employee").run()
assert resB["success"] is True

job.close()

0 comments on commit 4243cbe

Please sign in to comment.