Skip to content

Commit 8d7efbc

Browse files
committed
Publish test result to pipeline, Fix some Django 3.2 errors
1 parent c04b420 commit 8d7efbc

File tree

10 files changed

+60
-14
lines changed

10 files changed

+60
-14
lines changed

azure-pipelines.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,13 @@ jobs:
7777
codeCoverageTool: 'Cobertura'
7878
summaryFileLocation: 'C:\Windows\ServiceProfiles\NetworkService\coverage.xml'
7979

80+
- task: PublishTestResults@2
81+
displayName: Publish test results via jUnit
82+
inputs:
83+
testResultsFormat: 'JUnit'
84+
testResultsFiles: 'C:\Windows\ServiceProfiles\NetworkService\result.xml'
85+
testRunTitle: 'junit-$(Agent.OS)-$(Agent.OSArchitecture)-$(tox.env)'
86+
8087
- job: Linux
8188
pool:
8289
vmImage: ubuntu-18.04
@@ -144,3 +151,10 @@ jobs:
144151
inputs:
145152
codeCoverageTool: 'Cobertura'
146153
summaryFileLocation: '/home/vsts/coverage.xml'
154+
155+
- task: PublishTestResults@2
156+
displayName: Publish test results via jUnit
157+
inputs:
158+
testResultsFormat: 'JUnit'
159+
testResultsFiles: '/home/vsts/result.xml'
160+
testRunTitle: 'junit-$(Agent.OS)-$(Agent.OSArchitecture)-$(tox.env)'

mssql/base.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ class DatabaseWrapper(BaseDatabaseWrapper):
9393
'OneToOneField': 'int',
9494
'PositiveIntegerField': 'int',
9595
'PositiveSmallIntegerField': 'smallint',
96+
'PositiveBigIntegerField' : 'bigint',
9697
'SlugField': 'nvarchar(%(max_length)s)',
9798
'SmallAutoField': 'smallint',
9899
'SmallIntegerField': 'smallint',
@@ -109,6 +110,7 @@ class DatabaseWrapper(BaseDatabaseWrapper):
109110
'JSONField': '(ISJSON ("%(column)s") = 1)',
110111
'PositiveIntegerField': '[%(column)s] >= 0',
111112
'PositiveSmallIntegerField': '[%(column)s] >= 0',
113+
'PositiveBigIntegerField': '[%(column)s] >= 0',
112114
}
113115
operators = {
114116
# Since '=' is used not only for string comparision there is no way

mssql/features.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class DatabaseFeatures(BaseDatabaseFeatures):
1515
can_use_chunked_reads = False
1616
for_update_after_from = True
1717
greatest_least_ignores_nulls = True
18+
has_json_object_function = False
1819
has_json_operators = False
1920
has_native_json_field = False
2021
has_native_uuid_field = False
@@ -29,6 +30,7 @@ class DatabaseFeatures(BaseDatabaseFeatures):
2930
requires_sqlparse_for_splitting = False
3031
supports_boolean_expr_in_select_clause = False
3132
supports_deferrable_unique_constraints = False
33+
supports_expression_indexes = False
3234
supports_ignore_conflicts = False
3335
supports_index_on_text_field = False
3436
supports_json_field_contains = False

mssql/functions.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
KeyTransform, KeyTransformIn, KeyTransformExact,
1818
HasKeyLookup, compile_json_path)
1919

20+
if VERSION >= (3, 2):
21+
from django.db.models.functions.math import Random
22+
2023
DJANGO3 = VERSION[0] >= 3
2124

2225

@@ -59,6 +62,8 @@ def sqlserver_nth_value(self, compiler, connection, **extra_content):
5962
def sqlserver_round(self, compiler, connection, **extra_context):
6063
return self.as_sql(compiler, connection, template='%(function)s(%(expressions)s, 0)', **extra_context)
6164

65+
def sqlserver_random(self, compiler, connection, **extra_context):
66+
return self.as_sql(compiler, connection, function='RAND', **extra_context)
6267

6368
def sqlserver_window(self, compiler, connection, template=None):
6469
# MSSQL window functions require an OVER clause with ORDER BY
@@ -195,6 +200,9 @@ def json_HasKeyLookup(self, compiler, connection):
195200
Round.as_microsoft = sqlserver_round
196201
Window.as_microsoft = sqlserver_window
197202

203+
if VERSION >= (3, 2):
204+
Random.as_microsoft = sqlserver_random
205+
198206
if DJANGO3:
199207
Lookup.as_microsoft = sqlserver_lookup
200208
else:

mssql/introspection.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import pyodbc as Database
55

6+
from django import VERSION
67
from django.db.backends.base.introspection import (
78
BaseDatabaseIntrospection, FieldInfo, TableInfo,
89
)
@@ -97,7 +98,11 @@ def get_table_description(self, cursor, table_name, identity_check=True):
9798
"""
9899

99100
# map pyodbc's cursor.columns to db-api cursor description
100-
columns = [[c[3], c[4], None, c[6], c[6], c[8], c[10], c[12]] for c in cursor.columns(table=table_name)]
101+
if VERSION >= (3, 2):
102+
columns = [[c[3], c[4], None, c[6], c[6], c[8], c[10], c[12], ''] for c in cursor.columns(table=table_name)]
103+
else:
104+
columns = [[c[3], c[4], None, c[6], c[6], c[8], c[10], c[12]] for c in cursor.columns(table=table_name)]
105+
101106
items = []
102107
for column in columns:
103108
if identity_check and self._is_auto_field(cursor, table_name, column[0]):

mssql/operations.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ def date_interval_sql(self, timedelta):
143143
sql = 'DATEADD(microsecond, %d%%s, CAST(%s AS datetime2))' % (timedelta.microseconds, sql)
144144
return sql
145145

146-
def date_trunc_sql(self, lookup_type, field_name):
146+
def date_trunc_sql(self, lookup_type, field_name, tzname=''):
147147
CONVERT_YEAR = 'CONVERT(varchar, DATEPART(year, %s))' % field_name
148148
CONVERT_QUARTER = 'CONVERT(varchar, 1+((DATEPART(quarter, %s)-1)*3))' % field_name
149149
CONVERT_MONTH = 'CONVERT(varchar, DATEPART(month, %s))' % field_name
@@ -465,7 +465,7 @@ def adapt_datetimefield_value(self, value):
465465
value = value.astimezone(self.connection.timezone).replace(tzinfo=None)
466466
return value
467467

468-
def time_trunc_sql(self, lookup_type, field_name):
468+
def time_trunc_sql(self, lookup_type, field_name, tzname=''):
469469
# if self.connection.sql_server_version >= 2012:
470470
# fields = {
471471
# 'hour': 'DATEPART(hour, %s)' % field_name,

test.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ DJANGO_VERSION="$(python -m django --version)"
1010
cd django
1111
git fetch --depth=1 origin +refs/tags/*:refs/tags/*
1212
git checkout $DJANGO_VERSION
13-
pip install -r tests/requirements/py3.txt coverage
13+
pip install -r tests/requirements/py3.txt
1414

1515
coverage run tests/runtests.py --settings=testapp.settings --noinput \
1616
aggregation \
@@ -110,4 +110,6 @@ coverage run tests/runtests.py --settings=testapp.settings --noinput \
110110
update_only_fields
111111

112112
python -m coverage xml --include '*mssql*' --omit '*virtualenvs*'
113-
mv coverage.xml ~/
113+
114+
# For Azure Pipelines
115+
cp -f coverage.xml result.xml ~/

testapp/runners.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
from django.test.runner import DiscoverRunner
22
from django.conf import settings
33

4+
from unittest import skip
5+
import xmlrunner
6+
47
EXCLUDED_TESTS = getattr(settings, 'EXCLUDED_TESTS', [])
58
REGEX_TESTS = getattr(settings, 'REGEX_TESTS', [])
69

@@ -12,11 +15,22 @@ def build_suite(self, *args, **kwargs):
1215
suite = super().build_suite(*args, **kwargs)
1316
tests = []
1417
for case in suite:
18+
test_name = case._testMethodName
1519
if ENABLE_REGEX_TESTS:
16-
if not case.id() in EXCLUDED_TESTS:
17-
tests.append(case)
20+
if case.id() in EXCLUDED_TESTS:
21+
setattr(case, test_name, skip("Not supported")(getattr(case, test_name)))
1822
else:
19-
if not case.id() in EXCLUDED_TESTS + REGEX_TESTS:
20-
tests.append(case)
23+
if case.id() in EXCLUDED_TESTS + REGEX_TESTS:
24+
setattr(case, test_name, skip("Not supported")(getattr(case, test_name)))
25+
tests.append(case)
2126
suite._tests = tests
2227
return suite
28+
29+
def run_suite(self, suite):
30+
kwargs = dict(
31+
verbosity=1, descriptions=False,
32+
failfast=self.failfast)
33+
34+
with open('./result.xml', 'wb') as xml:
35+
return xmlrunner.XMLTestRunner(
36+
output=xml, **kwargs).run(suite)

testapp/settings.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -179,10 +179,6 @@
179179
'expressions.tests.ExpressionOperatorTests.test_lefthand_bitwise_xor_null',
180180
'inspectdb.tests.InspectDBTestCase.test_number_field_types',
181181
'inspectdb.tests.InspectDBTestCase.test_json_field',
182-
'model_fields.test_integerfield.PositiveBigIntegerFieldTests.test_backend_range_save',
183-
'model_fields.test_integerfield.PositiveBigIntegerFieldTests.test_coercing',
184-
'model_fields.test_integerfield.PositiveBigIntegerFieldTests.test_documented_range',
185-
'model_fields.test_integerfield.PositiveBigIntegerFieldTests.test_types',
186182
'ordering.tests.OrderingTests.test_default_ordering_by_f_expression',
187183
'ordering.tests.OrderingTests.test_order_by_nulls_first',
188184
'ordering.tests.OrderingTests.test_order_by_nulls_last',
@@ -203,8 +199,8 @@
203199
'model_fields.test_jsonfield.TestQuerying.test_none_key',
204200
'model_fields.test_jsonfield.TestQuerying.test_none_key_and_exact_lookup',
205201
'model_fields.test_jsonfield.TestQuerying.test_key_escape',
206-
207202
'model_fields.test_jsonfield.TestQuerying.test_ordering_by_transform',
203+
'expressions_window.tests.WindowFunctionTests.test_key_transform',
208204
]
209205

210206
REGEX_TESTS = ['lookup.tests.LookupTests.test_regex',

tox.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ commands =
1616
bash test.sh
1717

1818
deps =
19+
coverage
20+
unittest-xml-reporting
21+
1922
django22: django==2.2.*
2023
django30: django>=3.0,<3.1
2124
django31: django>=3.1,<3.2

0 commit comments

Comments
 (0)