1 |
# Copyright (c) 2002, 2003 by Intevation GmbH |
# Copyright (c) 2002, 2003, 2004 by Intevation GmbH |
2 |
# Authors: |
# Authors: |
3 |
# Bernhard Herzog <[email protected]> |
# Bernhard Herzog <[email protected]> |
4 |
# |
# |
65 |
class SaveSessionTest(unittest.TestCase, support.FileTestMixin, |
class SaveSessionTest(unittest.TestCase, support.FileTestMixin, |
66 |
xmlsupport.ValidationTest): |
xmlsupport.ValidationTest): |
67 |
|
|
68 |
dtd = "http://thuban.intevation.org/dtds/thuban-1.0-dev.dtd" |
dtd = "http://thuban.intevation.org/dtds/thuban-1.1-dev.dtd" |
69 |
thubanids = [((dtd, n), (None, "id")) for n in |
thubanids = [((dtd, n), (None, "id")) for n in |
70 |
["fileshapesource", "filetable", "jointable", |
["fileshapesource", "filetable", "jointable", |
71 |
"derivedshapesource", "dbshapesource", "dbconnection"]] |
"derivedshapesource", "dbshapesource", "dbconnection"]] |
111 |
file.close() |
file.close() |
112 |
self.compare_xml(written_contents, |
self.compare_xml(written_contents, |
113 |
'<?xml version="1.0" encoding="UTF-8"?>\n' |
'<?xml version="1.0" encoding="UTF-8"?>\n' |
114 |
'<!DOCTYPE session SYSTEM "thuban-1.0.dtd">\n' |
'<!DOCTYPE session SYSTEM "thuban-1.1.dtd">\n' |
115 |
'<session title="empty session" ' |
'<session title="empty session" ' |
116 |
'xmlns="http://thuban.intevation.org/dtds/thuban-1.0-dev.dtd">' |
'xmlns="http://thuban.intevation.org/dtds/thuban-1.1-dev.dtd">' |
117 |
'\n</session>\n') |
'\n</session>\n') |
118 |
|
|
119 |
self.validate_data(written_contents) |
self.validate_data(written_contents) |
141 |
written_contents = file.read() |
written_contents = file.read() |
142 |
file.close() |
file.close() |
143 |
expected_template = '''<?xml version="1.0" encoding="UTF-8"?> |
expected_template = '''<?xml version="1.0" encoding="UTF-8"?> |
144 |
<!DOCTYPE session SYSTEM "thuban-1.0.dtd"> |
<!DOCTYPE session SYSTEM "thuban-1.1.dtd"> |
145 |
<session title="single map&layer" |
<session title="single map&layer" |
146 |
xmlns="http://thuban.intevation.org/dtds/thuban-1.0-dev.dtd"> |
xmlns="http://thuban.intevation.org/dtds/thuban-1.1-dev.dtd"> |
147 |
<fileshapesource id="D1" |
<fileshapesource id="D1" |
148 |
filename="../../Data/iceland/political.shp" |
filename="../../Data/iceland/political.shp" |
149 |
filetype="shapefile"/> |
filetype="shapefile"/> |
203 |
written_contents = file.read() |
written_contents = file.read() |
204 |
file.close() |
file.close() |
205 |
expected_contents = '''<?xml version="1.0" encoding="UTF-8"?> |
expected_contents = '''<?xml version="1.0" encoding="UTF-8"?> |
206 |
<!DOCTYPE session SYSTEM "thuban-1.0.dtd"> |
<!DOCTYPE session SYSTEM "thuban-1.1.dtd"> |
207 |
<session title="single map&layer" |
<session title="single map&layer" |
208 |
xmlns="http://thuban.intevation.org/dtds/thuban-1.0-dev.dtd"> |
xmlns="http://thuban.intevation.org/dtds/thuban-1.1-dev.dtd"> |
209 |
<fileshapesource id="D1" |
<fileshapesource id="D1" |
210 |
filename="../../Data/iceland/political.shp" |
filename="../../Data/iceland/political.shp" |
211 |
filetype="shapefile"/> |
filetype="shapefile"/> |
234 |
self.validate_data(written_contents) |
self.validate_data(written_contents) |
235 |
|
|
236 |
def testRasterLayer(self): |
def testRasterLayer(self): |
|
# deliberately put an apersand in the title :) |
|
|
session = Session("single map&layer") |
|
|
map = Map("Test Map") |
|
|
session.AddMap(map) |
|
|
# use shapefile from the example data |
|
|
imgfile = os.path.join(os.path.dirname(__file__), |
|
|
os.pardir, "Data", "iceland", "island.tif") |
|
|
layer = RasterLayer("My RasterLayer", imgfile) |
|
|
map.AddLayer(layer) |
|
237 |
|
|
238 |
filename = self.temp_file_name("%s.thuban" % self.id()) |
MASK_NONE = RasterLayer.MASK_NONE |
239 |
save_session(session, filename) |
MASK_BIT = RasterLayer.MASK_BIT |
240 |
session.Destroy() |
MASK_ALPHA = RasterLayer.MASK_ALPHA |
241 |
|
|
242 |
|
for opacity, masktype, opname, maskname in \ |
243 |
|
[(1, MASK_BIT, '', ''), |
244 |
|
(.2, MASK_BIT, 'opacity="0.2"', ''), |
245 |
|
(1, MASK_ALPHA, '', 'masktype="alpha"'), |
246 |
|
(.5, MASK_ALPHA, 'opacity="0.5"', 'masktype="alpha"'), |
247 |
|
(1, MASK_NONE, '', 'masktype="none"'), |
248 |
|
(0, MASK_NONE, 'opacity="0"', 'masktype="none"') ]: |
249 |
|
|
|
file = open(filename) |
|
|
written_contents = file.read() |
|
|
file.close() |
|
|
expected_contents = '''<?xml version="1.0" encoding="UTF-8"?> |
|
|
<!DOCTYPE session SYSTEM "thuban-1.0.dtd"> |
|
|
<session title="single map&layer" |
|
|
xmlns="http://thuban.intevation.org/dtds/thuban-1.0-dev.dtd"> |
|
|
<map title="Test Map"> |
|
|
<rasterlayer title="My RasterLayer" |
|
|
filename="../../Data/iceland/island.tif" |
|
|
visible="true"> |
|
|
</rasterlayer> |
|
|
</map> |
|
|
</session>''' |
|
|
#print written_contents |
|
|
#print "********************************************" |
|
|
#print expected_contents |
|
|
self.compare_xml(written_contents, expected_contents) |
|
250 |
|
|
251 |
self.validate_data(written_contents) |
# deliberately put an apersand in the title :) |
252 |
|
session = Session("single map&layer") |
253 |
|
map = Map("Test Map") |
254 |
|
session.AddMap(map) |
255 |
|
# use shapefile from the example data |
256 |
|
imgfile = os.path.join(os.path.dirname(__file__), |
257 |
|
os.pardir, "Data", "iceland", "island.tif") |
258 |
|
layer = RasterLayer("My RasterLayer", imgfile) |
259 |
|
|
260 |
|
layer.SetOpacity(opacity) |
261 |
|
layer.SetMaskType(masktype) |
262 |
|
|
263 |
|
map.AddLayer(layer) |
264 |
|
|
265 |
|
filename = self.temp_file_name("%s.thuban" % self.id()) |
266 |
|
save_session(session, filename) |
267 |
|
session.Destroy() |
268 |
|
|
269 |
|
file = open(filename) |
270 |
|
written_contents = file.read() |
271 |
|
file.close() |
272 |
|
expected_contents = '''<?xml version="1.0" encoding="UTF-8"?> |
273 |
|
<!DOCTYPE session SYSTEM "thuban-1.1.dtd"> |
274 |
|
<session title="single map&layer" |
275 |
|
xmlns="http://thuban.intevation.org/dtds/thuban-1.1-dev.dtd"> |
276 |
|
<map title="Test Map"> |
277 |
|
<rasterlayer title="My RasterLayer" |
278 |
|
filename="../../Data/iceland/island.tif" |
279 |
|
visible="true" %s %s> |
280 |
|
</rasterlayer> |
281 |
|
</map> |
282 |
|
</session>''' % (opname, maskname) |
283 |
|
#print written_contents |
284 |
|
#print "********************************************" |
285 |
|
#print expected_contents |
286 |
|
self.compare_xml(written_contents, expected_contents) |
287 |
|
|
288 |
|
self.validate_data(written_contents) |
289 |
|
|
290 |
def testClassifiedLayer(self): |
def testClassifiedLayer(self): |
291 |
"""Save a session with a single map with classifications""" |
"""Save a session with a single map with classifications""" |
337 |
written_contents = file.read() |
written_contents = file.read() |
338 |
file.close() |
file.close() |
339 |
expected_contents = '''<?xml version="1.0" encoding="UTF-8"?> |
expected_contents = '''<?xml version="1.0" encoding="UTF-8"?> |
340 |
<!DOCTYPE session SYSTEM "thuban-1.0.dtd"> |
<!DOCTYPE session SYSTEM "thuban-1.1.dtd"> |
341 |
<session title="Map with Classifications" |
<session title="Map with Classifications" |
342 |
xmlns="http://thuban.intevation.org/dtds/thuban-1.0-dev.dtd"> |
xmlns="http://thuban.intevation.org/dtds/thuban-1.1-dev.dtd"> |
343 |
<fileshapesource id="D1" |
<fileshapesource id="D1" |
344 |
filename="../../Data/iceland/political.shp" |
filename="../../Data/iceland/political.shp" |
345 |
filetype="shapefile"/> |
filetype="shapefile"/> |
408 |
written_contents = file.read() |
written_contents = file.read() |
409 |
file.close() |
file.close() |
410 |
expected_contents = '''<?xml version="1.0" encoding="UTF-8"?> |
expected_contents = '''<?xml version="1.0" encoding="UTF-8"?> |
411 |
<!DOCTYPE session SYSTEM "thuban-1.0.dtd"> |
<!DOCTYPE session SYSTEM "thuban-1.1.dtd"> |
412 |
<session title="a DBF Table session" |
<session title="a DBF Table session" |
413 |
xmlns="http://thuban.intevation.org/dtds/thuban-1.0-dev.dtd"> |
xmlns="http://thuban.intevation.org/dtds/thuban-1.1-dev.dtd"> |
414 |
<filetable id="D1" filename="../../Data/iceland/political.dbf" |
<filetable id="D1" filename="../../Data/iceland/political.dbf" |
415 |
filetype="DBF" title="political"/> |
filetype="DBF" title="political"/> |
416 |
</session>''' |
</session>''' |
466 |
written_contents = file.read() |
written_contents = file.read() |
467 |
file.close() |
file.close() |
468 |
expected_contents = '''<?xml version="1.0" encoding="UTF-8"?> |
expected_contents = '''<?xml version="1.0" encoding="UTF-8"?> |
469 |
<!DOCTYPE session SYSTEM "thuban-1.0.dtd"> |
<!DOCTYPE session SYSTEM "thuban-1.1.dtd"> |
470 |
<session title="A Joined Table session" |
<session title="A Joined Table session" |
471 |
xmlns="http://thuban.intevation.org/dtds/thuban-1.0-dev.dtd"> |
xmlns="http://thuban.intevation.org/dtds/thuban-1.1-dev.dtd"> |
472 |
<fileshapesource filename="../../Data/iceland/roads-line.shp" |
<fileshapesource filename="../../Data/iceland/roads-line.shp" |
473 |
filetype="shapefile" id="D142197204"/> |
filetype="shapefile" id="D142197204"/> |
474 |
<filetable filename="save_joinedtable.dbf" |
<filetable filename="save_joinedtable.dbf" |
507 |
class NonConnectionStore(PostGISShapeStore): |
class NonConnectionStore(PostGISShapeStore): |
508 |
"""Shapestore that doesn't try to access the server""" |
"""Shapestore that doesn't try to access the server""" |
509 |
def _fetch_table_information(self): |
def _fetch_table_information(self): |
510 |
pass |
# pretend that we've found a geometry column |
511 |
|
self.geometry_column = "the_geom" |
512 |
|
def IDColumn(self): |
513 |
|
"""Return an object with a name attribute with value 'gid'""" |
514 |
|
class dummycol: |
515 |
|
name = "gid" |
516 |
|
return dummycol |
517 |
|
|
518 |
session = Session("A PostGIS Session") |
session = Session("A PostGIS Session") |
519 |
try: |
try: |
536 |
written = file.read() |
written = file.read() |
537 |
file.close() |
file.close() |
538 |
expected = '''<?xml version="1.0" encoding="UTF-8"?> |
expected = '''<?xml version="1.0" encoding="UTF-8"?> |
539 |
<!DOCTYPE session SYSTEM "thuban-1.0.dtd"> |
<!DOCTYPE session SYSTEM "thuban-1.1.dtd"> |
540 |
<session title="A PostGIS Session" |
<session title="A PostGIS Session" |
541 |
xmlns="http://thuban.intevation.org/dtds/thuban-1.0-dev.dtd"> |
xmlns="http://thuban.intevation.org/dtds/thuban-1.1-dev.dtd"> |
542 |
<dbconnection id="DB" |
<dbconnection id="DB" |
543 |
dbtype="postgis" dbname="plugh" |
dbtype="postgis" dbname="plugh" |
544 |
host="xyzzy" port="42" |
host="xyzzy" port="42" |
545 |
user="grue"/> |
user="grue"/> |
546 |
<dbshapesource id="roads" dbconn="DB" tablename="roads"/> |
<dbshapesource id="roads" dbconn="DB" tablename="roads" |
547 |
|
id_column="gid" geometry_column="the_geom"/> |
548 |
<map title="Test Map"> |
<map title="Test Map"> |
549 |
<layer title="Roads to Nowhere" |
<layer title="Roads to Nowhere" |
550 |
shapestore="roads" visible="true" |
shapestore="roads" visible="true" |