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.0rc1.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.0rc1.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.0rc1.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.0rc1.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"/> |
242 |
imgfile = os.path.join(os.path.dirname(__file__), |
imgfile = os.path.join(os.path.dirname(__file__), |
243 |
os.pardir, "Data", "iceland", "island.tif") |
os.pardir, "Data", "iceland", "island.tif") |
244 |
layer = RasterLayer("My RasterLayer", imgfile) |
layer = RasterLayer("My RasterLayer", imgfile) |
245 |
|
layer.SetUseMask(True) |
246 |
map.AddLayer(layer) |
map.AddLayer(layer) |
247 |
|
|
248 |
filename = self.temp_file_name("%s.thuban" % self.id()) |
filename = self.temp_file_name("%s.thuban" % self.id()) |
253 |
written_contents = file.read() |
written_contents = file.read() |
254 |
file.close() |
file.close() |
255 |
expected_contents = '''<?xml version="1.0" encoding="UTF-8"?> |
expected_contents = '''<?xml version="1.0" encoding="UTF-8"?> |
256 |
<!DOCTYPE session SYSTEM "thuban-1.0.dtd"> |
<!DOCTYPE session SYSTEM "thuban-1.1.dtd"> |
257 |
<session title="single map&layer" |
<session title="single map&layer" |
258 |
xmlns="http://thuban.intevation.org/dtds/thuban-1.0rc1.dtd"> |
xmlns="http://thuban.intevation.org/dtds/thuban-1.1-dev.dtd"> |
259 |
<map title="Test Map"> |
<map title="Test Map"> |
260 |
<rasterlayer title="My RasterLayer" |
<rasterlayer title="My RasterLayer" |
261 |
filename="../../Data/iceland/island.tif" |
filename="../../Data/iceland/island.tif" |
262 |
visible="true"> |
visible="true" use_mask="true"> |
263 |
</rasterlayer> |
</rasterlayer> |
264 |
</map> |
</map> |
265 |
</session>''' |
</session>''' |
320 |
written_contents = file.read() |
written_contents = file.read() |
321 |
file.close() |
file.close() |
322 |
expected_contents = '''<?xml version="1.0" encoding="UTF-8"?> |
expected_contents = '''<?xml version="1.0" encoding="UTF-8"?> |
323 |
<!DOCTYPE session SYSTEM "thuban-1.0.dtd"> |
<!DOCTYPE session SYSTEM "thuban-1.1.dtd"> |
324 |
<session title="Map with Classifications" |
<session title="Map with Classifications" |
325 |
xmlns="http://thuban.intevation.org/dtds/thuban-1.0rc1.dtd"> |
xmlns="http://thuban.intevation.org/dtds/thuban-1.1-dev.dtd"> |
326 |
<fileshapesource id="D1" |
<fileshapesource id="D1" |
327 |
filename="../../Data/iceland/political.shp" |
filename="../../Data/iceland/political.shp" |
328 |
filetype="shapefile"/> |
filetype="shapefile"/> |
391 |
written_contents = file.read() |
written_contents = file.read() |
392 |
file.close() |
file.close() |
393 |
expected_contents = '''<?xml version="1.0" encoding="UTF-8"?> |
expected_contents = '''<?xml version="1.0" encoding="UTF-8"?> |
394 |
<!DOCTYPE session SYSTEM "thuban-1.0.dtd"> |
<!DOCTYPE session SYSTEM "thuban-1.1.dtd"> |
395 |
<session title="a DBF Table session" |
<session title="a DBF Table session" |
396 |
xmlns="http://thuban.intevation.org/dtds/thuban-1.0rc1.dtd"> |
xmlns="http://thuban.intevation.org/dtds/thuban-1.1-dev.dtd"> |
397 |
<filetable id="D1" filename="../../Data/iceland/political.dbf" |
<filetable id="D1" filename="../../Data/iceland/political.dbf" |
398 |
filetype="DBF" title="political"/> |
filetype="DBF" title="political"/> |
399 |
</session>''' |
</session>''' |
449 |
written_contents = file.read() |
written_contents = file.read() |
450 |
file.close() |
file.close() |
451 |
expected_contents = '''<?xml version="1.0" encoding="UTF-8"?> |
expected_contents = '''<?xml version="1.0" encoding="UTF-8"?> |
452 |
<!DOCTYPE session SYSTEM "thuban-1.0.dtd"> |
<!DOCTYPE session SYSTEM "thuban-1.1.dtd"> |
453 |
<session title="A Joined Table session" |
<session title="A Joined Table session" |
454 |
xmlns="http://thuban.intevation.org/dtds/thuban-1.0rc1.dtd"> |
xmlns="http://thuban.intevation.org/dtds/thuban-1.1-dev.dtd"> |
455 |
<fileshapesource filename="../../Data/iceland/roads-line.shp" |
<fileshapesource filename="../../Data/iceland/roads-line.shp" |
456 |
filetype="shapefile" id="D142197204"/> |
filetype="shapefile" id="D142197204"/> |
457 |
<filetable filename="save_joinedtable.dbf" |
<filetable filename="save_joinedtable.dbf" |
490 |
class NonConnectionStore(PostGISShapeStore): |
class NonConnectionStore(PostGISShapeStore): |
491 |
"""Shapestore that doesn't try to access the server""" |
"""Shapestore that doesn't try to access the server""" |
492 |
def _fetch_table_information(self): |
def _fetch_table_information(self): |
493 |
pass |
# pretend that we've found a geometry column |
494 |
|
self.geometry_column = "the_geom" |
495 |
|
def IDColumn(self): |
496 |
|
"""Return an object with a name attribute with value 'gid'""" |
497 |
|
class dummycol: |
498 |
|
name = "gid" |
499 |
|
return dummycol |
500 |
|
|
501 |
session = Session("A PostGIS Session") |
session = Session("A PostGIS Session") |
502 |
try: |
try: |
519 |
written = file.read() |
written = file.read() |
520 |
file.close() |
file.close() |
521 |
expected = '''<?xml version="1.0" encoding="UTF-8"?> |
expected = '''<?xml version="1.0" encoding="UTF-8"?> |
522 |
<!DOCTYPE session SYSTEM "thuban-1.0.dtd"> |
<!DOCTYPE session SYSTEM "thuban-1.1.dtd"> |
523 |
<session title="A PostGIS Session" |
<session title="A PostGIS Session" |
524 |
xmlns="http://thuban.intevation.org/dtds/thuban-1.0rc1.dtd"> |
xmlns="http://thuban.intevation.org/dtds/thuban-1.1-dev.dtd"> |
525 |
<dbconnection id="DB" |
<dbconnection id="DB" |
526 |
dbtype="postgis" dbname="plugh" |
dbtype="postgis" dbname="plugh" |
527 |
host="xyzzy" port="42" |
host="xyzzy" port="42" |
528 |
user="grue"/> |
user="grue"/> |
529 |
<dbshapesource id="roads" dbconn="DB" tablename="roads"/> |
<dbshapesource id="roads" dbconn="DB" tablename="roads" |
530 |
|
id_column="gid" geometry_column="the_geom"/> |
531 |
<map title="Test Map"> |
<map title="Test Map"> |
532 |
<layer title="Roads to Nowhere" |
<layer title="Roads to Nowhere" |
533 |
shapestore="roads" visible="true" |
shapestore="roads" visible="true" |