Skip to content
Open
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
6 changes: 3 additions & 3 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,20 +62,20 @@ def lint_setup_py(session):

def default(session):
# Install all test dependencies, then install this package in-place.
session.install("mock", "pytest", "pytest-cov")
session.install("mock", "pytest", "pytest-cov", "django")
session.install("-e", ".")

# Run py.test against the unit tests.
session.run(
"py.test",
"--quiet",
# "--cov=django_spanner",
"--cov=django_spanner",
"--cov=google.cloud",
"--cov=tests.unit",
"--cov-append",
"--cov-config=.coveragerc",
"--cov-report=",
"--cov-fail-under=90",
"--cov-fail-under=70",
os.path.join("tests", "unit"),
*session.posargs
)
Expand Down
135 changes: 0 additions & 135 deletions tests/spanner_dbapi/test_connect.py

This file was deleted.

79 changes: 0 additions & 79 deletions tests/spanner_dbapi/test_connection.py

This file was deleted.

92 changes: 92 additions & 0 deletions tests/unit/django_spanner/test_compiler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# Copyright 2020 Google LLC
#
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file or at
# https://developers.google.com/open-source/licenses/bsd

"""Django-Spanner SQLCompiler class unit tests."""

import unittest
from unittest import mock


class TestSQLCompiler(unittest.TestCase):
def test_get_combinator_sql(self):
from django.core.exceptions import EmptyResultSet
from django.db.utils import DatabaseError
from django_spanner.compiler import SQLCompiler

def _empty_result_set():
from django.core.exceptions import EmptyResultSet

raise EmptyResultSet

query = mock.MagicMock()
query.values_select = False
connection = mock.MagicMock()
using = 'using'

compiler = SQLCompiler(query, connection, using)
self.assertIsInstance(compiler, SQLCompiler)

mock_cquery = mock.MagicMock()
mock_cquery.get_compiler = mock_compiler = mock.MagicMock()
part_sql = 'part_sql'
part_args = 'part_args'
mock_compiler.return_value.as_sql.return_value = (part_sql, part_args)
mock_cquery.is_empty = lambda: False

compiler.query = mock_query = mock.MagicMock()
mock_query.combined_queries = [mock_cquery]

combinator = 'union'
all_ = True

res, params = compiler.get_combinator_sql(combinator, all_)
self.assertEqual(res, ['({})'.format(part_sql)])
self.assertEqual(params, [c for c in part_args])

compiler.connection.features.supports_slicing_ordering_in_compound = False
q = compiler.query.combined_queries[0]
q.low_mark = q.high_mark = True
with self.assertRaises(DatabaseError):
compiler.get_combinator_sql(combinator, all_)
q.low_mark = q.high_mark = False
mock_compiler.return_value.get_order_by.return_value = True
with self.assertRaises(DatabaseError):
compiler.get_combinator_sql(combinator, all_)

compiler.connection.features.supports_slicing_ordering_in_compound = True
mock_compiler.return_value.query.values_select = False
compiler.query.values_select = [0]
mock_compiler.return_value.query.set_values = mock_set_values = mock.MagicMock()
compiler.get_combinator_sql(combinator, all_)
mock_set_values.assert_called_once_with((0,))

compiler.query.combined_queries = []
with self.assertRaises(EmptyResultSet):
compiler.get_combinator_sql(combinator, all_)

compiler.connection.features.supports_slicing_ordering_in_compound = False
compiler.query.combined_queries = [mock_cquery, mock_cquery]
mock_cquery.return_value.get_compiler.return_value = [0, 0]
mock_compiler.return_value.get_order_by.return_value = False
res, params = compiler.get_combinator_sql(combinator, all_)
self.assertEqual(res[0].split()[0], '({})'.format(part_sql))
self.assertEqual(params[:9], [c for c in part_args])

compiler.connection.features.supports_parentheses_in_compound = False
res, params = compiler.get_combinator_sql(combinator, all_)
self.assertEqual(res[0].split()[0], 'SELECT')
self.assertEqual(params[:9], [c for c in part_args])

mock_compiler.return_value.query.combinator = False
res, params = compiler.get_combinator_sql(combinator, all_)
self.assertEqual(res[0].split()[0], part_sql)
self.assertEqual(params[:9], [c for c in part_args])

mock_compiler.return_value.as_sql = _empty_result_set
with self.assertRaises(EmptyResultSet):
compiler.get_combinator_sql(combinator, all_)
with self.assertRaises(EmptyResultSet):
compiler.get_combinator_sql(None, all_)
3 changes: 2 additions & 1 deletion version.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
# license that can be found in the LICENSE file or at
# https://developers.google.com/open-source/licenses/bsd

__version__ = "2.2.0a1"
# __version__ = "2.2.0a1"
__version__ = "3.1.0a1"
Copy link
Collaborator Author

@mf2199 mf2199 Oct 27, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is needed to prevent version requirement exception:

 django.core.exceptions.ImproperlyConfigured: You must use the latest version of django-spanner 3.1.x with Django 3.1.y (found django-spanner 2.2.0a1).