Skip to content
Permalink
Browse files

Add provider test for mssql

  • Loading branch information
nyalldawson committed Dec 10, 2015
1 parent c9645e4 commit 8602a91a1d18ca030d809d46d025ee79bd1ea0b0
@@ -1,4 +1,5 @@
SET (ENABLE_PGTEST FALSE CACHE BOOL "Enable PostgreSQL provider tests")
SET (ENABLE_MSSQLTEST FALSE CACHE BOOL "Enable MsSQL provider tests")

INCLUDE(UsePythonTest)
# Run one of the two server tests at the beginning so they don't run in
@@ -83,6 +84,10 @@ IF (ENABLE_PGTEST)
ADD_PYTHON_TEST(PyQgsRelationEditWidget test_qgsrelationeditwidget.py)
ENDIF (ENABLE_PGTEST)

IF (ENABLE_MSSQLTEST)
ADD_PYTHON_TEST(PyQgsMssqlProvider test_provider_mssql.py)
ENDIF (ENABLE_MSSQLTEST)

IF (WITH_APIDOC)
ADD_PYTHON_TEST(PyQgsDocCoverage test_qgsdoccoverage.py)
#SIP coverage test relies on API doc parsing to identify members which should be in bindings
@@ -0,0 +1,57 @@
# -*- coding: utf-8 -*-
"""QGIS Unit tests for the MS SQL provider.
.. note:: This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
"""
__author__ = 'Nyall Dawson'
__date__ = '2015-12-07'
__copyright__ = 'Copyright 2015, The QGIS Project'
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'

import qgis
import os
import sys
from qgis.core import NULL

from qgis.core import QgsVectorLayer, QgsFeatureRequest, QgsFeature, QgsProviderRegistry
from PyQt4.QtCore import QSettings
from utilities import (unitTestDataPath,
getQgisTestApp,
unittest,
TestCase
)
from providertestbase import ProviderTestCase

QGISAPP, CANVAS, IFACE, PARENT = getQgisTestApp()
TEST_DATA_DIR = unitTestDataPath()


class TestPyQgsMssqlProvider(TestCase, ProviderTestCase):

@classmethod
def setUpClass(cls):
"""Run before all tests"""
cls.dbconn = u"dbname='gis' host=localhost\sqlexpress"
if 'QGIS_MSSQLTEST_DB' in os.environ:
cls.dbconn = os.environ['QGIS_MSSQLTEST_DB']
# Create test layer
cls.vl = QgsVectorLayer(cls.dbconn + ' sslmode=disable key=\'pk\' srid=4326 type=POINT table="qgis_test"."someData" (geom) sql=', 'test', 'mssql')
assert(cls.vl.isValid())
cls.provider = cls.vl.dataProvider()

@classmethod
def tearDownClass(cls):
"""Run after all tests"""

def enableCompiler(self):
QSettings().setValue(u'/qgis/compileExpressions', True)

def disableCompiler(self):
QSettings().setValue(u'/qgis/compileExpressions', False)

if __name__ == '__main__':
unittest.main()
@@ -0,0 +1,17 @@
CREATE SCHEMA qgis_test

CREATE TABLE qgis_test.[someData] (
pk integer PRIMARY KEY,
cnt integer,
name nvarchar(max) DEFAULT 'qgis',
name2 nvarchar(max) DEFAULT 'qgis',
geom geometry
)

INSERT INTO qgis_test.[someData] (pk, cnt, name, name2, geom) VALUES
(5, -200, NULL, 'NuLl', geometry::STGeomFromText( 'Point(-71.123 78.23)', 4326 )),
(3, 300, 'Pear', 'PEaR', NULL),
(1, 100, 'Orange', 'oranGe', geometry::STGeomFromText( 'Point(-70.332 66.33)', 4326 )),
(2, 200, 'Apple', 'Apple', geometry::STGeomFromText( 'Point(-68.2 70.8)', 4326 )),
(4, 400, 'Honey', 'Honey', geometry::STGeomFromText( 'Point(-65.32 78.3)', 4326 ))
;

0 comments on commit 8602a91

Please sign in to comment.
You can’t perform that action at this time.