1919from qgis .core import QgsVectorLayer , QgsFeatureRequest , NULL
2020
2121from qgis .PyQt .QtCore import QSettings , QDate , QTime , QDateTime , QVariant
22+ from qgis .PyQt .QtSql import QSqlDatabase , QSqlQuery
2223
23- from utilities import unitTestDataPath
24+ from utilities import unitTestDataPath , compareWkt
2425from qgis .testing import start_app , unittest
2526from providertestbase import ProviderTestCase
2627
@@ -46,10 +47,42 @@ def setUpClass(cls):
4647 assert (cls .poly_vl .isValid ())
4748 cls .poly_provider = cls .poly_vl .dataProvider ()
4849
50+ cls .conn = QSqlDatabase .addDatabase ('QOCISPATIAL' , "oracletest" )
51+ cls .conn .setDatabaseName ('10.0.0.2/orcl' )
52+ cls .conn .setUserName ('QGIS' )
53+ cls .conn .setPassword ('qgis' )
54+ assert cls .conn .open ()
55+
4956 @classmethod
5057 def tearDownClass (cls ):
5158 """Run after all tests"""
5259
60+ def execSQLCommand (self , sql , ignore_errors = False ):
61+ self .assertTrue (self .conn )
62+ query = QSqlQuery (self .conn )
63+ self .assertTrue (query .exec_ (sql ), sql + ': ' + query .lastError ().text ())
64+ query .finish ()
65+
66+ # disabled: WIP
67+ def disabled_getSource (self ):
68+ # create temporary table for edit tests
69+ self .execSQLCommand ('DROP TABLE "QGIS"."EDIT_DATA"' , ignore_errors = True )
70+ self .execSQLCommand ("""CREATE TABLE QGIS.EDIT_DATA ("pk" INTEGER PRIMARY KEY, "cnt" INTEGER, "name" VARCHAR2(100), "name2" VARCHAR2(100), "num_char" VARCHAR2(100), GEOM SDO_GEOMETRY)""" )
71+ self .execSQLCommand ("""INSERT INTO QGIS.EDIT_DATA ("pk", "cnt", "name", "name2", "num_char", GEOM)
72+ SELECT 5, -200, NULL, 'NuLl', '5', SDO_GEOMETRY( 2001,4326,SDO_POINT_TYPE(-71.123, 78.23, NULL), NULL, NULL) from dual
73+ UNION ALL SELECT 3, 300, 'Pear', 'PEaR', '3', NULL from dual
74+ UNION ALL SELECT 1, 100, 'Orange', 'oranGe', '1', SDO_GEOMETRY( 2001,4326,SDO_POINT_TYPE(-70.332, 66.33, NULL), NULL, NULL) from dual
75+ UNION ALL SELECT 2, 200, 'Apple', 'Apple', '2', SDO_GEOMETRY( 2001,4326,SDO_POINT_TYPE(-68.2, 70.8, NULL), NULL, NULL) from dual
76+ UNION ALL SELECT 4, 400, 'Honey', 'Honey', '4', SDO_GEOMETRY( 2001,4326,SDO_POINT_TYPE(-65.32, 78.3, NULL), NULL, NULL) from dual""" )
77+ vl = QgsVectorLayer (
78+ self .dbconn + ' sslmode=disable key=\' pk\' srid=4326 type=POINT table="QGIS"."EDIT_DATA" (GEOM) sql=' ,
79+ 'test' , 'oracle' )
80+ return vl
81+
82+ # disabled: WIP
83+ def disabled_getEditableLayer (self ):
84+ return self .getSource ()
85+
5386 def enableCompiler (self ):
5487 QSettings ().setValue (u'/qgis/compileExpressions' , True )
5588
@@ -103,5 +136,49 @@ def testDefaultValue(self):
103136 self .assertEqual (self .provider .defaultValue (1 ), NULL )
104137 self .assertEqual (self .provider .defaultValue (2 ), "'qgis'" )
105138
139+ def testPoints (self ):
140+ vl = QgsVectorLayer ('%s table="QGIS"."POINT_DATA" (GEOM) srid=4326 type=POINT sql=' %
141+ (self .dbconn ), "testpoints" , "oracle" )
142+ self .assertTrue (vl .isValid ())
143+
144+ features = [f for f in vl .getFeatures ()]
145+ self .assertEqual (features [0 ].geometry ().exportToWkt (), 'Point (1 2)' )
146+ self .assertEqual (features [1 ].geometry ().exportToWkt (), 'PointZ (1 2 3)' )
147+ self .assertEqual (features [2 ].geometry ().exportToWkt (), 'MultiPointZ ((1 2 3),(4 5 6))' )
148+ self .assertEqual (features [3 ].geometry ().exportToWkt (), 'MultiPoint ((1 2),(3 4))' )
149+
150+ def testCurves (self ):
151+ vl = QgsVectorLayer ('%s table="QGIS"."LINE_DATA" (GEOM) srid=4326 type=LINESTRING sql=' %
152+ (self .dbconn ), "testlines" , "oracle" )
153+ self .assertTrue (vl .isValid ())
154+
155+ features = {f ['pk' ]: f for f in vl .getFeatures ()}
156+ self .assertTrue (compareWkt (features [1 ].geometry ().exportToWkt (), 'LineString (1 2, 3 4, 5 6)' , 0.00001 ), features [1 ].geometry ().exportToWkt ())
157+ self .assertTrue (
158+ compareWkt (features [4 ].geometry ().exportToWkt (), 'LineStringZ (1 2 3, 4 5 6, 7 8 9)' , 0.00001 ), features [4 ].geometry ().exportToWkt ())
159+ self .assertTrue (
160+ compareWkt (features [5 ].geometry ().exportToWkt (), 'MultiLineString ((1 2, 3 4),(5 6, 7 8, 9 10))' , 0.00001 ), features [5 ].geometry ().exportToWkt ())
161+ self .assertTrue (
162+ compareWkt (features [6 ].geometry ().exportToWkt (), 'MultiLineStringZ ((1 2 11, 3 4 -11),(5 6 9, 7 8 1, 9 10 -3))' , 0.00001 ), features [6 ].geometry ().exportToWkt ())
163+
164+ def testSurfaces (self ):
165+ vl = QgsVectorLayer ('%s table="QGIS"."POLY_DATA" (GEOM) srid=4326 type=POLYGON sql=' %
166+ (self .dbconn ), "testpoly" , "oracle" )
167+ self .assertTrue (vl .isValid ())
168+
169+ features = {f ['pk' ]: f for f in vl .getFeatures ()}
170+ self .assertTrue (compareWkt (features [1 ].geometry ().exportToWkt (), 'Polygon ((1 2, 11 2, 11 22, 1 22, 1 2))' , 0.00001 ), features [1 ].geometry ().exportToWkt ())
171+ self .assertTrue (compareWkt (features [2 ].geometry ().exportToWkt (), 'PolygonZ ((1 2 3, 11 2 13, 11 22 15, 1 22 7, 1 2 3))' , 0.00001 ), features [2 ].geometry ().exportToWkt ())
172+ self .assertTrue (
173+ compareWkt (features [3 ].geometry ().exportToWkt (), 'Polygon ((1 2, 11 2, 11 22, 1 22, 1 2),(5 6, 8 9, 8 6, 5 6),(3 4, 5 6, 3 6, 3 4))' , 0.00001 ), features [3 ].geometry ().exportToWkt ())
174+ self .assertTrue (
175+ compareWkt (features [4 ].geometry ().exportToWkt (), 'PolygonZ ((1 2 3, 11 2 13, 11 22 15, 1 22 7, 1 2 3),(5 6 1, 8 9 -1, 8 6 2, 5 6 1))' , 0.00001 ), features [4 ].geometry ().exportToWkt ())
176+ self .assertTrue (
177+ compareWkt (features [5 ].geometry ().exportToWkt (), 'Polygon ((1 2, 11 2, 11 22, 1 22, 1 2))' , 0.00001 ), features [5 ].geometry ().exportToWkt ())
178+ self .assertTrue (
179+ compareWkt (features [7 ].geometry ().exportToWkt (), 'MultiPolygon (((1 2, 11 2, 11 22, 1 22, 1 2)),((1 2, 11 2, 11 22, 1 22, 1 2),(5 6, 8 9, 8 6, 5 6),(3 4, 5 6, 3 6, 3 4)))' , 0.00001 ), features [7 ].geometry ().exportToWkt ())
180+ self .assertTrue (
181+ compareWkt (features [8 ].geometry ().exportToWkt (), 'MultiPolygonZ (((1 2 3, 11 2 13, 11 22 15, 1 22 7, 1 2 3)),((1 2 3, 11 2 13, 11 22 15, 1 22 7, 1 2 3),(5 6 1, 8 9 -1, 8 6 2, 5 6 1)))' , 0.00001 ), features [8 ].geometry ().exportToWkt ())
182+
106183if __name__ == '__main__' :
107184 unittest .main ()
0 commit comments