From 488035c0989595c09f7215c5a03ec6fd42555bda Mon Sep 17 00:00:00 2001 From: asthamohta Date: Wed, 21 Jul 2021 15:09:47 +0530 Subject: [PATCH] changes for 3.2 --- django_spanner/introspection.py | 1 + django_spanner/utils.py | 14 +++++------ noxfile.py | 8 +++--- tests/unit/django_spanner/test_expressions.py | 4 +-- tests/unit/django_spanner/test_functions.py | 2 +- .../unit/django_spanner/test_introspection.py | 2 ++ tests/unit/django_spanner/test_lookups.py | 25 +++++++++---------- tests/unit/django_spanner/test_utils.py | 4 +-- 8 files changed, 31 insertions(+), 29 deletions(-) diff --git a/django_spanner/introspection.py b/django_spanner/introspection.py index b95ea3e629..f81a3ea953 100644 --- a/django_spanner/introspection.py +++ b/django_spanner/introspection.py @@ -96,6 +96,7 @@ def get_table_description(self, cursor, table_name): None, # scale details.null_ok, None, # default + None, # collation ) ) diff --git a/django_spanner/utils.py b/django_spanner/utils.py index 6fb40db812..de7a91cb05 100644 --- a/django_spanner/utils.py +++ b/django_spanner/utils.py @@ -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): diff --git a/noxfile.py b/noxfile.py index a5c05e7a02..bcfe118ca3 100644 --- a/noxfile.py +++ b/noxfile.py @@ -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", @@ -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", @@ -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 @@ -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) diff --git a/tests/unit/django_spanner/test_expressions.py b/tests/unit/django_spanner/test_expressions.py index 0efc99ce08..ae5b53f4f8 100644 --- a/tests/unit/django_spanner/test_expressions.py +++ b/tests/unit/django_spanner/test_expressions.py @@ -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): @@ -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): diff --git a/tests/unit/django_spanner/test_functions.py b/tests/unit/django_spanner/test_functions.py index 00b431b73b..b24a2290e9 100644 --- a/tests/unit/django_spanner/test_functions.py +++ b/tests/unit/django_spanner/test_functions.py @@ -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, ()) diff --git a/tests/unit/django_spanner/test_introspection.py b/tests/unit/django_spanner/test_introspection.py index c90288f3b3..03b5b67ca9 100644 --- a/tests/unit/django_spanner/test_introspection.py +++ b/tests/unit/django_spanner/test_introspection.py @@ -98,6 +98,7 @@ def get_table_column_schema(*args, **kwargs): scale=None, null_ok=False, default=None, + collation=None, ), FieldInfo( name="age", @@ -108,6 +109,7 @@ def get_table_column_schema(*args, **kwargs): scale=None, null_ok=True, default=None, + collation=None, ), ], ) diff --git a/tests/unit/django_spanner/test_lookups.py b/tests/unit/django_spanner/test_lookups.py index 53604691cc..797dfbaba8 100644 --- a/tests/unit/django_spanner/test_lookups.py +++ b/tests/unit/django_spanner/test_lookups.py @@ -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): @@ -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, ()) @@ -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",)) @@ -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",)) @@ -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",)) @@ -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",)) @@ -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",)) @@ -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",)) @@ -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",)) @@ -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, ()) @@ -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",)) diff --git a/tests/unit/django_spanner/test_utils.py b/tests/unit/django_spanner/test_utils.py index e4d50861d0..b8c353ab2d 100644 --- a/tests/unit/django_spanner/test_utils.py +++ b/tests/unit/django_spanner/test_utils.py @@ -20,7 +20,7 @@ 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() @@ -28,7 +28,7 @@ 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()