Skip to content

Commit caccc13

Browse files
authored
Merge pull request #138 from Thiyagu55/python-test-workflows
Python test workflows
2 parents b6d3d75 + 3a29cb9 commit caccc13

File tree

8 files changed

+85
-10
lines changed

8 files changed

+85
-10
lines changed

.github/workflows/integration-tests.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ on:
1010
paths-ignore:
1111
- php/sqlcommenter-php/packages/sqlcommenter-laravel/**
1212
- php/sqlcommenter-php/samples/sqlcommenter-laravel/**
13+
1314
jobs:
1415
integrationtests:
1516
runs-on: ubuntu-latest
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: Python Packages Test
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
paths:
8+
- python/sqlcommenter-python/**
9+
pull_request:
10+
paths:
11+
- python/sqlcommenter-python/**
12+
13+
jobs:
14+
unittests:
15+
env:
16+
# We use these variables to convert between tox and GHA version literals
17+
py36: 3.6
18+
py37: 3.7
19+
py38: 3.8
20+
py39: 3.9
21+
RUN_MATRIX_COMBINATION: ${{ matrix.python-version }}-${{ matrix.package }}-${{ matrix.os }}
22+
runs-on: ${{ matrix.os }}
23+
strategy:
24+
fail-fast: false # ensures the entire test matrix is run, even if one permutation fails
25+
matrix:
26+
python-version: [ py36, py37, py38, py39 ]
27+
os: [ ubuntu-20.04 ]
28+
steps:
29+
- name: Checkout Contrib Repo @ SHA - ${{ github.sha }}
30+
uses: actions/checkout@v2
31+
- name: Set up Python ${{ env[matrix.python-version] }}
32+
uses: actions/setup-python@v2
33+
with:
34+
python-version: ${{ env[matrix.python-version] }}
35+
- name: Install tox
36+
run: pip install -U tox-factor
37+
- name: run tox
38+
run: tox -e '${{ matrix.python-version }}-{django21,django22,django30,django31,django32,psycopg2,flask,generic,sqlalchemy}'
39+
working-directory: ./python/sqlcommenter-python
40+
41+
lint:
42+
strategy:
43+
fail-fast: false
44+
matrix:
45+
tox-environment: [ "lint" ]
46+
name: ${{ matrix.tox-environment }}
47+
runs-on: ubuntu-20.04
48+
steps:
49+
- name: Checkout Contrib Repo @ SHA - ${{ github.sha }}
50+
uses: actions/checkout@v2
51+
- name: Set up Python 3.9
52+
uses: actions/setup-python@v2
53+
with:
54+
python-version: 3.9
55+
- name: Install tox
56+
run: pip install -U tox
57+
- name: run tox
58+
run: tox -e flake8
59+
working-directory: ./python/sqlcommenter-python
60+

.github/workflows/unit-tests.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,26 @@
11
name: Unit Tests
2+
23
on:
34
push:
45
branches:
56
- master
67
paths-ignore:
78
- php/sqlcommenter-php/packages/sqlcommenter-laravel/**
89
- php/sqlcommenter-php/samples/sqlcommenter-laravel/**
10+
- python/sqlcommenter-python/**
911
pull_request:
1012
paths-ignore:
1113
- php/sqlcommenter-php/packages/sqlcommenter-laravel/**
1214
- php/sqlcommenter-php/samples/sqlcommenter-laravel/**
15+
- python/sqlcommenter-python/**
16+
1317
jobs:
1418
unittests:
1519
runs-on: ubuntu-latest
1620
steps:
1721
- run: 'echo "No build required" '
22+
23+
lint:
24+
runs-on: ubuntu-latest
25+
steps:
26+
- run: 'echo "No build required" '

python/sqlcommenter-python/google/cloud/sqlcommenter/django/middleware.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
import django
2121
from django.db import connections
22-
2322
from django.db.backends.utils import CursorDebugWrapper
2423
from google.cloud.sqlcommenter import add_sql_comment
2524
from google.cloud.sqlcommenter.opencensus import get_opencensus_values

python/sqlcommenter-python/tests/django/tests.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@
1717
import django
1818
from django.db import connection, connections
1919
from django.http import HttpRequest
20-
from django.test import TestCase, override_settings, modify_settings
20+
from django.test import TestCase, modify_settings, override_settings
2121
from django.urls import resolve, reverse
22-
from google.cloud.sqlcommenter.django.middleware import SqlCommenter, QueryWrapper
22+
from google.cloud.sqlcommenter.django.middleware import (
23+
QueryWrapper, SqlCommenter,
24+
)
2325

2426
from ..compat import mock
2527
from ..opencensus_mock import mock_opencensus_tracer
@@ -30,6 +32,8 @@
3032
# Adding the middleware twice in modify_settings
3133
# doesn't work. The middleware is only used once
3234
# if used in modify_settings
35+
36+
3337
class TestMiddleware:
3438
def __init__(self, get_response):
3539
self.get_response = get_response
@@ -38,10 +42,12 @@ def __call__(self, request):
3842
with connection.execute_wrapper(QueryWrapper(request)):
3943
return self.get_response(request)
4044

45+
4146
# Query log only active if DEBUG=True.
4247
@override_settings(DEBUG=True)
4348
class Tests(TestCase):
4449
databases = '__all__'
50+
4551
@staticmethod
4652
def get_request(path):
4753
request = HttpRequest()

python/sqlcommenter-python/tests/fastapi/app.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22

33
from fastapi import FastAPI, status
44
from fastapi.responses import JSONResponse
5+
from google.cloud.sqlcommenter.fastapi import (
6+
SQLCommenterMiddleware, get_fastapi_info,
7+
)
58
from starlette.exceptions import HTTPException as StarletteHTTPException
69

7-
from google.cloud.sqlcommenter.fastapi import SQLCommenterMiddleware, get_fastapi_info
8-
910
app = FastAPI(title="SQLCommenter")
1011

1112
app.add_middleware(SQLCommenterMiddleware)

python/sqlcommenter-python/tests/fastapi/tests.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,8 @@
1818

1919
import fastapi
2020
import pytest
21-
from starlette.testclient import TestClient
22-
2321
from google.cloud.sqlcommenter.fastapi import get_fastapi_info
22+
from starlette.testclient import TestClient
2423

2524
from .app import app
2625

python/sqlcommenter-python/tests/generic/test_add_sql_comment.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ def test_end_comment_escaping(self):
2727
self.assertEqual("Select 1 /*a='%%2A/abc'*/", add_sql_comment("Select 1", a='*/abc'))
2828

2929
def test_bytes(self):
30-
self.assertIn("Select 1 /*a='%%2A/abc'*/", add_sql_comment("Select 1",a=b'*/abc'))
30+
self.assertIn("Select 1 /*a='%%2A/abc'*/", add_sql_comment("Select 1", a=b'*/abc'))
3131

3232
def test_url_quoting(self):
33-
self.assertIn("Select 1 /*foo='bar%%2Cbaz'*/", add_sql_comment("Select 1",foo='bar,baz'))
33+
self.assertIn("Select 1 /*foo='bar%%2Cbaz'*/", add_sql_comment("Select 1", foo='bar,baz'))
3434

3535
def test_sql_with_semicolon(self):
36-
self.assertIn("Select 1 /*foo='bar%%2Cbaz'*/;", add_sql_comment("Select 1;",foo='bar,baz'))
36+
self.assertIn("Select 1 /*foo='bar%%2Cbaz'*/;", add_sql_comment("Select 1;", foo='bar,baz'))

0 commit comments

Comments
 (0)