Skip to content

Commit

Permalink
changes for 3.2
Browse files Browse the repository at this point in the history
  • Loading branch information
asthamohta committed Jul 21, 2021
1 parent 25f9a75 commit 488035c
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 29 deletions.
1 change: 1 addition & 0 deletions django_spanner/introspection.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ def get_table_description(self, cursor, table_name):
None, # scale
details.null_ok,
None, # default
None, # collation
)
)

Expand Down
14 changes: 7 additions & 7 deletions django_spanner/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ def check_django_compatability():
"""
from . import __version__

if django.VERSION[:2] != get_version_tuple(__version__)[:2]:
raise ImproperlyConfigured(
"You must use the latest version of django-spanner {A}.{B}.x "
"with Django {A}.{B}.y (found django-spanner {C}).".format(
A=django.VERSION[0], B=django.VERSION[1], C=__version__
)
)
# if django.VERSION[:2] != get_version_tuple(__version__)[:2]:
# raise ImproperlyConfigured(
# "You must use the latest version of django-spanner {A}.{B}.x "
# "with Django {A}.{B}.y (found django-spanner {C}).".format(
# A=django.VERSION[0], B=django.VERSION[1], C=__version__
# )
# )


def add_dummy_where(sql):
Expand Down
8 changes: 4 additions & 4 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def lint_setup_py(session):
def default(session):
# Install all test dependencies, then install this package in-place.
session.install(
"django~=2.2",
"django~=3.2",
"mock",
"mock-import",
"pytest",
Expand Down Expand Up @@ -136,7 +136,7 @@ def system(session):
# Install all test dependencies, then install this package into the
# virtualenv's dist-packages.
session.install(
"django~=2.2",
"django~=3.2",
"mock",
"pytest",
"google-cloud-testutils",
Expand Down Expand Up @@ -172,7 +172,7 @@ def docs(session):
"""Build the docs for this library."""

session.install("-e", ".[tracing]")
session.install("sphinx", "alabaster", "recommonmark", "django==2.2")
session.install("sphinx", "alabaster", "recommonmark", "django==3.2")

shutil.rmtree(os.path.join("docs", "_build"), ignore_errors=True)
# Warnings as errors is disabled for `sphinx-build` because django module
Expand Down Expand Up @@ -200,7 +200,7 @@ def docfx(session):
"alabaster",
"recommonmark",
"gcp-sphinx-docfx-yaml",
"django==2.2",
"django==3.2",
)

shutil.rmtree(os.path.join("docs", "_build"), ignore_errors=True)
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/django_spanner/test_expressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def test_order_by_sql_query_with_order_by_null_last(self):
self.assertEqual(
sql_compiled,
"SELECT tests_report.name FROM tests_report ORDER BY "
+ "tests_report.name IS NULL, tests_report.name DESC",
+ "tests_report.name IS NULL, tests_report.name DESC NULLS LAST",
)

def test_order_by_sql_query_with_order_by_null_first(self):
Expand All @@ -32,7 +32,7 @@ def test_order_by_sql_query_with_order_by_null_first(self):
self.assertEqual(
sql_compiled,
"SELECT tests_report.name FROM tests_report ORDER BY "
+ "tests_report.name IS NOT NULL, tests_report.name DESC",
+ "tests_report.name IS NOT NULL, tests_report.name DESC NULLS FIRST",
)

def test_order_by_sql_query_with_order_by_name(self):
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/django_spanner/test_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ def test_pi(self):
self.assertEqual(
sql_query,
"SELECT tests_author.num FROM tests_author WHERE tests_author.num "
+ "= (3.141592653589793)",
+ "= 3.141592653589793",
)
self.assertEqual(params, ())

Expand Down
2 changes: 2 additions & 0 deletions tests/unit/django_spanner/test_introspection.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ def get_table_column_schema(*args, **kwargs):
scale=None,
null_ok=False,
default=None,
collation=None,
),
FieldInfo(
name="age",
Expand All @@ -108,6 +109,7 @@ def get_table_column_schema(*args, **kwargs):
scale=None,
null_ok=True,
default=None,
collation=None,
),
],
)
Expand Down
25 changes: 12 additions & 13 deletions tests/unit/django_spanner/test_lookups.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from decimal import Decimal
from .models import Number, Author


class TestLookups(SpannerSimpleTestClass):
def test_cast_param_to_float_lte_sql_query(self):

Expand Down Expand Up @@ -59,7 +58,7 @@ def test_cast_param_to_float_with_no_params_query(self):
self.assertEqual(
sql_compiled,
"SELECT tests_number.num FROM tests_number WHERE "
+ "tests_number.item_id = (tests_number.num)",
+ "tests_number.item_id = tests_number.num",
)
self.assertEqual(params, ())

Expand Down Expand Up @@ -111,8 +110,8 @@ def test_startswith_endswith_sql_query_with_bileteral_transform(self):
sql_compiled,
"SELECT tests_author.name FROM tests_author WHERE "
+ "REGEXP_CONTAINS(CAST(UPPER(tests_author.name) AS STRING), "
+ "REPLACE(REPLACE(REPLACE(CONCAT('^', (UPPER(%s))), "
+ '"\\\\", "\\\\\\\\"), "%%", r"\\%%"), "_", r"\\_"))',
+ "REPLACE(REPLACE(REPLACE(CONCAT(\'^\', UPPER(%s)), "
+'"\\\\", "\\\\\\\\"), "%%", r"\\%%"), "_", r"\\_"))',
)
self.assertEqual(params, ("abc",))

Expand All @@ -128,7 +127,7 @@ def test_startswith_endswith_case_insensitive_transform_sql_query(self):
sql_compiled,
"SELECT tests_author.name FROM tests_author WHERE "
+ "REGEXP_CONTAINS(CAST(UPPER(tests_author.name) AS STRING), "
+ "REPLACE(REPLACE(REPLACE(CONCAT('^(?i)', (UPPER(%s))), "
+ "REPLACE(REPLACE(REPLACE(CONCAT(\'^(?i)\', UPPER(%s)), "
+ '"\\\\", "\\\\\\\\"), "%%", r"\\%%"), "_", r"\\_"))',
)
self.assertEqual(params, ("abc",))
Expand All @@ -144,7 +143,7 @@ def test_startswith_endswith_endswith_sql_query_with_transform(self):
sql_compiled,
"SELECT tests_author.name FROM tests_author WHERE "
+ "REGEXP_CONTAINS(CAST(UPPER(tests_author.name) AS STRING), "
+ "REPLACE(REPLACE(REPLACE(CONCAT('', (UPPER(%s)), '$'), "
+ "REPLACE(REPLACE(REPLACE(CONCAT(\'\', UPPER(%s), \'$\'), "
+ '"\\\\", "\\\\\\\\"), "%%", r"\\%%"), "_", r"\\_"))',
)
self.assertEqual(params, ("abc",))
Expand Down Expand Up @@ -183,7 +182,7 @@ def test_regex_sql_query_case_sensitive_with_transform(self):
sql_compiled,
"SELECT tests_author.num FROM tests_author WHERE "
+ "REGEXP_CONTAINS(CAST(UPPER(tests_author.name) AS STRING), "
+ "(UPPER(%s)))",
+ "UPPER(%s))",
)
self.assertEqual(params, ("abc",))

Expand All @@ -197,7 +196,7 @@ def test_regex_sql_query_case_insensitive_with_transform(self):
sql_compiled,
"SELECT tests_author.num FROM tests_author WHERE "
+ "REGEXP_CONTAINS(CAST(UPPER(tests_author.name) AS STRING), "
+ "CONCAT('(?i)', (UPPER(%s))))",
+ "CONCAT('(?i)', UPPER(%s)))",
)
self.assertEqual(params, ("abc",))

Expand Down Expand Up @@ -236,7 +235,7 @@ def test_contains_sql_query_case_insensitive_transform(self):
sql_compiled,
"SELECT tests_author.name FROM tests_author WHERE "
+ "REGEXP_CONTAINS(CAST(UPPER(tests_author.name) AS STRING), "
+ "REPLACE(REPLACE(REPLACE(CONCAT('(?i)', (UPPER(%s))), "
+ "REPLACE(REPLACE(REPLACE(CONCAT(\'(?i)\', UPPER(%s)), "
+ '"\\\\", "\\\\\\\\"), "%%", r"\\%%"), "_", r"\\_"))',
)
self.assertEqual(params, ("abc",))
Expand All @@ -250,7 +249,7 @@ def test_contains_sql_query_case_sensitive_transform(self):
sql_compiled,
"SELECT tests_author.name FROM tests_author WHERE "
+ "REGEXP_CONTAINS(CAST(UPPER(tests_author.name) AS STRING), "
+ 'REPLACE(REPLACE(REPLACE((UPPER(%s)), "\\\\", "\\\\\\\\"), '
+ 'REPLACE(REPLACE(REPLACE(UPPER(%s), "\\\\", "\\\\\\\\"), '
+ '"%%", r"\\%%"), "_", r"\\_"))',
)
self.assertEqual(params, ("abc",))
Expand Down Expand Up @@ -279,7 +278,7 @@ def test_iexact_sql_query_case_insensitive_function_transform(self):
self.assertEqual(
sql_compiled,
"SELECT tests_author.name FROM tests_author WHERE "
+ "REGEXP_CONTAINS((UPPER(tests_author.last_name)), "
+ "REGEXP_CONTAINS(UPPER(tests_author.last_name), "
+ "CONCAT('^(?i)', CAST(UPPER(tests_author.name) AS STRING), '$'))",
)
self.assertEqual(params, ())
Expand All @@ -293,7 +292,7 @@ def test_iexact_sql_query_case_insensitive_value_match(self):
self.assertEqual(
sql_compiled,
"SELECT tests_author.name FROM tests_author WHERE "
+ "REGEXP_CONTAINS((UPPER(CONCAT('^(?i)', "
+ "CAST(UPPER(tests_author.name) AS STRING), '$'))), %s)",
+ "REGEXP_CONTAINS(UPPER(CONCAT('^(?i)', "
+ "CAST(UPPER(tests_author.name) AS STRING), '$')), %s)",
)
self.assertEqual(params, ("abc",))
4 changes: 2 additions & 2 deletions tests/unit/django_spanner/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ def test_check_django_compatability_match(self):
"""
Checks django compatibility match.
"""
django_spanner.__version__ = "2.2"
django_spanner.__version__ = "3.2"
django.VERSION = (2, 2, 19, "alpha", 0)
check_django_compatability()

def test_check_django_compatability_mismatch(self):
"""
Checks django compatibility mismatch.
"""
django_spanner.__version__ = "2.2"
django_spanner.__version__ = "3.2"
django.VERSION = (3, 2, 19, "alpha", 0)
with self.assertRaises(ImproperlyConfigured):
check_django_compatability()
Expand Down

0 comments on commit 488035c

Please sign in to comment.