| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
import unittest |
|---|
| 23 |
import traceback |
|---|
| 24 |
import string |
|---|
| 25 |
import os.path |
|---|
| 26 |
from ConfigParser import * |
|---|
| 27 |
import re |
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 |
from FDO import * |
|---|
| 31 |
from SdfConnectionFactory import * |
|---|
| 32 |
from SdfFileFactory import * |
|---|
| 33 |
|
|---|
| 34 |
|
|---|
| 35 |
G_INI_FILENAME="./Input/UnitTestConfig.ini" |
|---|
| 36 |
|
|---|
| 37 |
|
|---|
| 38 |
class ApplySchemaTest(unittest.TestCase): |
|---|
| 39 |
""" |
|---|
| 40 |
Unit test for FDO Command classes. |
|---|
| 41 |
|
|---|
| 42 |
This class has the following dependencies: |
|---|
| 43 |
1. A config file called input/UnitTestConfig.ini must exist |
|---|
| 44 |
2. input/UnitTestConfig.ini must contain the following entries: |
|---|
| 45 |
|
|---|
| 46 |
[Connection] |
|---|
| 47 |
ConnectString=<A FDO connection string> |
|---|
| 48 |
ProviderName=<An FDO provider name. Can also be a regular expression> |
|---|
| 49 |
|
|---|
| 50 |
""" |
|---|
| 51 |
_oConfig = ConfigParser() |
|---|
| 52 |
_oConnection = None |
|---|
| 53 |
|
|---|
| 54 |
def setUp(self): |
|---|
| 55 |
""" |
|---|
| 56 |
Initialize resources required by the test. |
|---|
| 57 |
Creates, initializes and open a FdoIConnection |
|---|
| 58 |
|
|---|
| 59 |
Arguments: |
|---|
| 60 |
None |
|---|
| 61 |
|
|---|
| 62 |
Returns: |
|---|
| 63 |
none |
|---|
| 64 |
""" |
|---|
| 65 |
|
|---|
| 66 |
|
|---|
| 67 |
SdfFileFactory.createFromIni(G_INI_FILENAME, True) |
|---|
| 68 |
|
|---|
| 69 |
|
|---|
| 70 |
self._oConfig.read([G_INI_FILENAME]) |
|---|
| 71 |
self._oConnection = SdfConnectionFactory.create() |
|---|
| 72 |
|
|---|
| 73 |
|
|---|
| 74 |
sConnectString = self._oConfig.get("Connection", "ConnectString") |
|---|
| 75 |
self._oConnection.SetConnectionString(sConnectString) |
|---|
| 76 |
self._oConnection.Open() |
|---|
| 77 |
|
|---|
| 78 |
|
|---|
| 79 |
def testApplySchema(self): |
|---|
| 80 |
"""Test the Apply Schema command against an SDF datasource""" |
|---|
| 81 |
self.assertEquals(self._oConnection.GetConnectionState(), FdoConnectionState_Open) |
|---|
| 82 |
|
|---|
| 83 |
|
|---|
| 84 |
oApplySchemaCmd = self._oConnection.CreateCommand(FdoCommandType_ApplySchema) |
|---|
| 85 |
oApplySchemaCmd = FdoICommandToFdoIApplySchema(oApplySchemaCmd) |
|---|
| 86 |
oApplySchemaCmd.SetFeatureSchema(self._createFeatureSchema("TestSchema")) |
|---|
| 87 |
oApplySchemaCmd.Execute() |
|---|
| 88 |
oApplySchemaCmd.Release() |
|---|
| 89 |
|
|---|
| 90 |
|
|---|
| 91 |
oDescribeSchemaCmd = self._oConnection.CreateCommand(FdoCommandType_DescribeSchema) |
|---|
| 92 |
oDescribeSchemaCmd = FdoICommandToFdoIDescribeSchema(oDescribeSchemaCmd) |
|---|
| 93 |
self.assertEquals(oDescribeSchemaCmd.__class__.__name__, "FdoIDescribeSchema") |
|---|
| 94 |
oSchemaCol = oDescribeSchemaCmd.Execute() |
|---|
| 95 |
oDescribeSchemaCmd.Release() |
|---|
| 96 |
self.assertEquals(oSchemaCol.GetCount(), 1) |
|---|
| 97 |
|
|---|
| 98 |
|
|---|
| 99 |
oSchema = oSchemaCol.GetItem(0) |
|---|
| 100 |
self.assert_(oSchema.GetName(), 'TestSchema') |
|---|
| 101 |
|
|---|
| 102 |
|
|---|
| 103 |
oClasses = oSchema.GetClasses() |
|---|
| 104 |
self.assertEquals(oClasses.GetCount(), 2) |
|---|
| 105 |
|
|---|
| 106 |
|
|---|
| 107 |
oClass = oClasses.FindItem("SewerPipe") |
|---|
| 108 |
self.assert_(oClass.GetName(), 'SewerPipe') |
|---|
| 109 |
self.assert_(oClass.GetQualifiedName(), 'TestSchema:SewerPipe') |
|---|
| 110 |
|
|---|
| 111 |
|
|---|
| 112 |
oProperties = oClass.GetProperties() |
|---|
| 113 |
self.assertEquals(oProperties.GetCount(), 4) |
|---|
| 114 |
|
|---|
| 115 |
|
|---|
| 116 |
oProperties.Release() |
|---|
| 117 |
oClass.Release() |
|---|
| 118 |
oClasses.Release() |
|---|
| 119 |
oSchema.Release() |
|---|
| 120 |
oSchemaCol.Release() |
|---|
| 121 |
|
|---|
| 122 |
|
|---|
| 123 |
def _createFeatureSchema(self, sSchemaName): |
|---|
| 124 |
"""Creates a FDO Feature schema instance""" |
|---|
| 125 |
oNewSchema = FdoFeatureSchema.Create(sSchemaName, sSchemaName) |
|---|
| 126 |
oClasses = oNewSchema.GetClasses() |
|---|
| 127 |
|
|---|
| 128 |
|
|---|
| 129 |
|
|---|
| 130 |
oClasses.Add(self._createFeatureClass("SewerPipe")) |
|---|
| 131 |
oClasses.Add(self._createFeatureClass("WaterPipe")) |
|---|
| 132 |
oClasses.Release() |
|---|
| 133 |
|
|---|
| 134 |
return oNewSchema |
|---|
| 135 |
|
|---|
| 136 |
|
|---|
| 137 |
def _createFeatureClass(self, sClassName): |
|---|
| 138 |
""" |
|---|
| 139 |
Creates an FDO Feature class definition |
|---|
| 140 |
|
|---|
| 141 |
Note: if you add more properties here, you must update testApplySchema() |
|---|
| 142 |
""" |
|---|
| 143 |
|
|---|
| 144 |
|
|---|
| 145 |
oNewClass = FdoFeatureClass.Create(sClassName, sClassName) |
|---|
| 146 |
oProperties = oNewClass.GetProperties() |
|---|
| 147 |
oIdentityProperties = oNewClass.GetIdentityProperties() |
|---|
| 148 |
|
|---|
| 149 |
|
|---|
| 150 |
oIdProperty = self._createDataProperty("FeatureId", FdoDataType_Int32) |
|---|
| 151 |
oProperties.Add(oIdProperty) |
|---|
| 152 |
oIdentityProperties.Add(oIdProperty) |
|---|
| 153 |
oIdentityProperties.Release() |
|---|
| 154 |
|
|---|
| 155 |
|
|---|
| 156 |
oProperties.Add(self._createDataProperty("Length", FdoDataType_Double)) |
|---|
| 157 |
oProperties.Add(self._createDataProperty("Diameter", FdoDataType_Double)) |
|---|
| 158 |
oProperties.Add(self._createDataProperty("Owner", FdoDataType_String)) |
|---|
| 159 |
|
|---|
| 160 |
oProperties.Release() |
|---|
| 161 |
return oNewClass |
|---|
| 162 |
|
|---|
| 163 |
|
|---|
| 164 |
def _createDataProperty(self, sPropertyName, enumDataType): |
|---|
| 165 |
""" |
|---|
| 166 |
Creates a simple data property. Default characteristics, such as length |
|---|
| 167 |
and scale are assigned. |
|---|
| 168 |
|
|---|
| 169 |
Arguments: |
|---|
| 170 |
sPropertyName (mandatory input) |
|---|
| 171 |
Name of the new property to create |
|---|
| 172 |
|
|---|
| 173 |
enumDataType (mandatory input) |
|---|
| 174 |
A FdoDataType value |
|---|
| 175 |
|
|---|
| 176 |
Returns: |
|---|
| 177 |
A FdoDataPropertyDefinition instance |
|---|
| 178 |
|
|---|
| 179 |
""" |
|---|
| 180 |
oNewProperty = FdoDataPropertyDefinition.Create(sPropertyName, sPropertyName) |
|---|
| 181 |
oNewProperty.SetDataType(enumDataType) |
|---|
| 182 |
oNewProperty.SetNullable(True) |
|---|
| 183 |
|
|---|
| 184 |
if enumDataType == FdoDataType_String: |
|---|
| 185 |
oNewProperty.SetLength(32) |
|---|
| 186 |
|
|---|
| 187 |
if enumDataType == FdoDataType_Decimal: |
|---|
| 188 |
oNewProperty.SetPrecision(16) |
|---|
| 189 |
oNewProperty.SetScale(4) |
|---|
| 190 |
|
|---|
| 191 |
return oNewProperty |
|---|
| 192 |
|
|---|
| 193 |
|
|---|
| 194 |
def tearDown(self): |
|---|
| 195 |
""" |
|---|
| 196 |
Releases any resources created or connected during the test |
|---|
| 197 |
|
|---|
| 198 |
Arguments: |
|---|
| 199 |
None |
|---|
| 200 |
|
|---|
| 201 |
Returns: |
|---|
| 202 |
none |
|---|
| 203 |
""" |
|---|
| 204 |
|
|---|
| 205 |
if not self._oConnection is None: |
|---|
| 206 |
if self._oConnection.__class__.__name__ == 'FdoIConnection': |
|---|
| 207 |
self._oConnection.Close() |
|---|
| 208 |
self._oConnection.Release() |
|---|
| 209 |
print "\nTesting ApplySchemaTest..." |
|---|
| 210 |
|
|---|
| 211 |
|
|---|