Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions python/sqlcommenter-python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Add the provided Django middleware to your Django project's settings. All querie

```python
MIDDLEWARE = [
'sqlcommenter.django.middleware.SqlCommenter',
'google.cloud.sqlcommenter.django.middleware.SqlCommenter',
...
]
```
Expand All @@ -41,7 +41,7 @@ which when viewed say on Postgresql logs, produces
If you want the opencensus attributes included, you must set the
``SQLCOMMENTER_WITH_OPENCENSUS`` setting to ``True`` and include
``'opencensus.ext.django.middleware.OpencensusMiddleware'`` before
``'sqlcommenter.django.middleware.SqlCommenter',`` in your ``MIDDLEWARE``
``'google.cloud.sqlcommenter.django.middleware.SqlCommenter',`` in your ``MIDDLEWARE``
setting.

### SQLAlchemy
Expand All @@ -50,7 +50,7 @@ Attach the provided event listener to the `before_cursor_execute` event of the d

```python
import sqlalchemy
from sqlcommenter.sqlalchemy.executor import BeforeExecuteFactory
from google.cloud.sqlcommenter.sqlalchemy.executor import BeforeExecuteFactory

engine = sqlalchemy.create_engine(...)
listener = BeforeExecuteFactory(with_db_driver=True, with_db_framework=True, with_opencensus=True)
Expand All @@ -72,7 +72,7 @@ Use the provided cursor factory to generate database cursors. All queries execut

```python
import psycopg2
from sqlcommenter.psycopg2.extension import CommenterCursorFactory
from google.cloud.sqlcommenter.psycopg2.extension import CommenterCursorFactory

cursor_factory = CommenterCursorFactory(
with_db_driver=True, with_dbapi_level=True, with_dbapi_threadsafety=True,
Expand Down
15 changes: 15 additions & 0 deletions python/sqlcommenter-python/google/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/python
#
# Copyright 2020 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
15 changes: 15 additions & 0 deletions python/sqlcommenter-python/google/cloud/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/python
#
# Copyright 2020 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,3 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@
import django
from django.db import connection
from django.db.backends.utils import CursorDebugWrapper

from sqlcommenter import generate_sql_comment
from sqlcommenter.opencensus import get_opencensus_values
from google.cloud.sqlcommenter import generate_sql_comment
from google.cloud.sqlcommenter.opencensus import get_opencensus_values

django_version = django.get_version()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,3 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@

import psycopg2
import psycopg2.extensions

from sqlcommenter import generate_sql_comment
from sqlcommenter.flask import get_flask_info
from sqlcommenter.opencensus import get_opencensus_values
from google.cloud.sqlcommenter import generate_sql_comment
from google.cloud.sqlcommenter.flask import get_flask_info
from google.cloud.sqlcommenter.opencensus import get_opencensus_values


# This integration extends psycopg2.extensions.cursor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,3 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@
from __future__ import absolute_import

import sqlalchemy

from sqlcommenter import generate_sql_comment
from sqlcommenter.flask import get_flask_info
from sqlcommenter.opencensus import get_opencensus_values
from google.cloud.sqlcommenter import generate_sql_comment
from google.cloud.sqlcommenter.flask import get_flask_info
from google.cloud.sqlcommenter.opencensus import get_opencensus_values


def BeforeExecuteFactory(
Expand Down
2 changes: 1 addition & 1 deletion python/sqlcommenter-python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from setuptools import find_packages, setup

setup(
name='sqlcommenter',
name='google.cloud.sqlcommenter',
version='0.1',
author='Google Developers',
author_email='sqlcommenter@googlegroups.com',
Expand Down
1 change: 0 additions & 1 deletion python/sqlcommenter-python/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,3 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

1 change: 0 additions & 1 deletion python/sqlcommenter-python/tests/django/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,3 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

3 changes: 1 addition & 2 deletions python/sqlcommenter-python/tests/django/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
from django.http import HttpRequest
from django.test import TestCase, override_settings
from django.urls import resolve, reverse

from sqlcommenter.django.middleware import SqlCommenter
from google.cloud.sqlcommenter.django.middleware import SqlCommenter

from ..opencensus_mock import mock_opencensus_tracer
from . import views
Expand Down
1 change: 0 additions & 1 deletion python/sqlcommenter-python/tests/flask/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,3 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

3 changes: 1 addition & 2 deletions python/sqlcommenter-python/tests/flask/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
# limitations under the License.

from flask import Flask

from sqlcommenter.flask import get_flask_info
from google.cloud.sqlcommenter.flask import get_flask_info

app = Flask(__name__)

Expand Down
3 changes: 1 addition & 2 deletions python/sqlcommenter-python/tests/flask/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@

import flask
import pytest

from sqlcommenter.flask import get_flask_info
from google.cloud.sqlcommenter.flask import get_flask_info

from .app import app

Expand Down
1 change: 0 additions & 1 deletion python/sqlcommenter-python/tests/generic/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,3 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

from unittest import TestCase

from sqlcommenter import generate_sql_comment
from google.cloud.sqlcommenter import generate_sql_comment


class GenerateSqlCommentTests(TestCase):
Expand Down
5 changes: 2 additions & 3 deletions python/sqlcommenter-python/tests/generic/test_opencensus.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,15 @@
from unittest import TestCase

import six

from sqlcommenter.opencensus import get_opencensus_values
from google.cloud.sqlcommenter.opencensus import get_opencensus_values

from ..compat import mock
from ..opencensus_mock import mock_opencensus_tracer


class OpenCensusTests(TestCase):
def test_not_installed(self):
with mock.patch('sqlcommenter.opencensus.execution_context', new=None):
with mock.patch('google.cloud.sqlcommenter.opencensus.execution_context', new=None):
with six.assertRaisesRegex(self, ImportError, 'opencensus is not installed'):
get_opencensus_values()

Expand Down
1 change: 0 additions & 1 deletion python/sqlcommenter-python/tests/psycopg2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,3 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

13 changes: 6 additions & 7 deletions python/sqlcommenter-python/tests/psycopg2/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@

import psycopg2.extensions
from forbiddenfruit import curse

from sqlcommenter import url_quote
from sqlcommenter.psycopg2.extension import CommenterCursorFactory
from google.cloud.sqlcommenter import url_quote
from google.cloud.sqlcommenter.psycopg2.extension import CommenterCursorFactory

from ..compat import mock
from ..opencensus_mock import mock_opencensus_tracer
Expand Down Expand Up @@ -89,27 +88,27 @@ class FlaskTests(Psycopg2TestCase):
'route': '/',
}

@mock.patch('sqlcommenter.psycopg2.extension.get_flask_info', return_value=flask_info)
@mock.patch('google.cloud.sqlcommenter.psycopg2.extension.get_flask_info', return_value=flask_info)
def test_all_data(self, get_info):
self.assertSQL(
"SELECT 1; /*controller='c',framework='flask',route='/'*/",
)

@mock.patch('sqlcommenter.psycopg2.extension.get_flask_info', return_value=flask_info)
@mock.patch('google.cloud.sqlcommenter.psycopg2.extension.get_flask_info', return_value=flask_info)
def test_framework_disabled(self, get_info):
self.assertSQL(
"SELECT 1; /*controller='c',route='/'*/",
with_framework=False,
)

@mock.patch('sqlcommenter.psycopg2.extension.get_flask_info', return_value=flask_info)
@mock.patch('google.cloud.sqlcommenter.psycopg2.extension.get_flask_info', return_value=flask_info)
def test_controller_disabled(self, get_info):
self.assertSQL(
"SELECT 1; /*framework='flask',route='/'*/",
with_controller=False,
)

@mock.patch('sqlcommenter.psycopg2.extension.get_flask_info', return_value=flask_info)
@mock.patch('google.cloud.sqlcommenter.psycopg2.extension.get_flask_info', return_value=flask_info)
def test_route_disabled(self, get_info):
self.assertSQL(
"SELECT 1; /*controller='c',framework='flask'*/",
Expand Down
1 change: 0 additions & 1 deletion python/sqlcommenter-python/tests/sqlalchemy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,3 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

11 changes: 5 additions & 6 deletions python/sqlcommenter-python/tests/sqlalchemy/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
from unittest import TestCase

import sqlalchemy

from sqlcommenter.sqlalchemy.executor import BeforeExecuteFactory
from google.cloud.sqlcommenter.sqlalchemy.executor import BeforeExecuteFactory

from ..compat import mock
from ..opencensus_mock import mock_opencensus_tracer
Expand Down Expand Up @@ -78,27 +77,27 @@ class FlaskTests(SQLAlchemyTestCase):
'route': '/',
}

@mock.patch('sqlcommenter.sqlalchemy.executor.get_flask_info', return_value=flask_info)
@mock.patch('google.cloud.sqlcommenter.sqlalchemy.executor.get_flask_info', return_value=flask_info)
def test_all_data(self, get_info):
self.assertSQL(
"SELECT 1; /*controller='c',framework='flask',route='/'*/",
)

@mock.patch('sqlcommenter.sqlalchemy.executor.get_flask_info', return_value=flask_info)
@mock.patch('google.cloud.sqlcommenter.sqlalchemy.executor.get_flask_info', return_value=flask_info)
def test_framework_disabled(self, get_info):
self.assertSQL(
"SELECT 1; /*controller='c',route='/'*/",
with_framework=False,
)

@mock.patch('sqlcommenter.sqlalchemy.executor.get_flask_info', return_value=flask_info)
@mock.patch('google.cloud.sqlcommenter.sqlalchemy.executor.get_flask_info', return_value=flask_info)
def test_controller_disabled(self, get_info):
self.assertSQL(
"SELECT 1; /*framework='flask',route='/'*/",
with_controller=False,
)

@mock.patch('sqlcommenter.sqlalchemy.executor.get_flask_info', return_value=flask_info)
@mock.patch('google.cloud.sqlcommenter.sqlalchemy.executor.get_flask_info', return_value=flask_info)
def test_route_disabled(self, get_info):
self.assertSQL(
"SELECT 1; /*controller='c',framework='flask'*/",
Expand Down
18 changes: 1 addition & 17 deletions python/sqlcommenter-python/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.

#!/usr/bin/python
#
# Copyright 2019 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from unittest import TestCase

from sqlcommenter import generate_sql_comment
from google.cloud.sqlcommenter import generate_sql_comment

from .opencensus_mock import mock_opencensus_tracer

Expand Down