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-0.9-dev.dtd" |
dtd = "http://thuban.intevation.org/dtds/thuban-0.9.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"]] |
78 |
("dbshapesource", "dbconn")]] |
("dbshapesource", "dbconn")]] |
79 |
del n, m, dtd |
del n, m, dtd |
80 |
|
|
81 |
|
def tearDown(self): |
82 |
|
"""Call self.session.Destroy |
83 |
|
|
84 |
|
Test cases that create session should bind it to self.session so |
85 |
|
that it gets destroyed properly |
86 |
|
""" |
87 |
|
if hasattr(self, "session"): |
88 |
|
self.session.Destroy() |
89 |
|
self.session = None |
90 |
|
|
91 |
def compare_xml(self, xml1, xml2): |
def compare_xml(self, xml1, xml2): |
92 |
list1 = xmlsupport.sax_eventlist(xml1, ids = self.thubanids, |
list1 = xmlsupport.sax_eventlist(xml1, ids = self.thubanids, |
93 |
idrefs = self.thubanidrefs) |
idrefs = self.thubanidrefs) |
113 |
'<?xml version="1.0" encoding="UTF-8"?>\n' |
'<?xml version="1.0" encoding="UTF-8"?>\n' |
114 |
'<!DOCTYPE session SYSTEM "thuban-0.9.dtd">\n' |
'<!DOCTYPE session SYSTEM "thuban-0.9.dtd">\n' |
115 |
'<session title="empty session" ' |
'<session title="empty session" ' |
116 |
'xmlns="http://thuban.intevation.org/dtds/thuban-0.9-dev.dtd">' |
'xmlns="http://thuban.intevation.org/dtds/thuban-0.9.dtd">' |
117 |
'\n</session>\n') |
'\n</session>\n') |
118 |
|
|
119 |
self.validate_data(written_contents) |
self.validate_data(written_contents) |
140 |
expected_template = '''<?xml version="1.0" encoding="UTF-8"?> |
expected_template = '''<?xml version="1.0" encoding="UTF-8"?> |
141 |
<!DOCTYPE session SYSTEM "thuban-0.9.dtd"> |
<!DOCTYPE session SYSTEM "thuban-0.9.dtd"> |
142 |
<session title="single map&layer" |
<session title="single map&layer" |
143 |
xmlns="http://thuban.intevation.org/dtds/thuban-0.9-dev.dtd"> |
xmlns="http://thuban.intevation.org/dtds/thuban-0.9.dtd"> |
144 |
<fileshapesource id="D1" filename="%s" filetype="shapefile"/> |
<fileshapesource id="D1" filename="%s" filetype="shapefile"/> |
145 |
<map title="Test Map"> |
<map title="Test Map"> |
146 |
<projection name="Unknown"> |
<projection name="Unknown"> |
178 |
def testLayerProjection(self): |
def testLayerProjection(self): |
179 |
"""Test saving layers with projections""" |
"""Test saving layers with projections""" |
180 |
# deliberately put an apersand in the title :) |
# deliberately put an apersand in the title :) |
181 |
session = Session("single map&layer") |
session = self.session = Session("single map&layer") |
182 |
proj = Projection(["zone=26", "proj=utm", "ellps=clrk66"]) |
proj = Projection(["zone=26", "proj=utm", "ellps=clrk66"]) |
183 |
map = Map("Test Map", projection = proj) |
map = Map("Test Map", projection = proj) |
184 |
session.AddMap(map) |
session.AddMap(map) |
192 |
|
|
193 |
filename = self.temp_file_name("save_layerproj.thuban") |
filename = self.temp_file_name("save_layerproj.thuban") |
194 |
save_session(session, filename) |
save_session(session, filename) |
|
session.Destroy() |
|
195 |
|
|
196 |
file = open(filename) |
file = open(filename) |
197 |
written_contents = file.read() |
written_contents = file.read() |
199 |
expected_contents = '''<?xml version="1.0" encoding="UTF-8"?> |
expected_contents = '''<?xml version="1.0" encoding="UTF-8"?> |
200 |
<!DOCTYPE session SYSTEM "thuban-0.9.dtd"> |
<!DOCTYPE session SYSTEM "thuban-0.9.dtd"> |
201 |
<session title="single map&layer" |
<session title="single map&layer" |
202 |
xmlns="http://thuban.intevation.org/dtds/thuban-0.9-dev.dtd"> |
xmlns="http://thuban.intevation.org/dtds/thuban-0.9.dtd"> |
203 |
<fileshapesource id="D1" filename="%s" filetype="shapefile"/> |
<fileshapesource id="D1" filename="%s" filetype="shapefile"/> |
204 |
<map title="Test Map"> |
<map title="Test Map"> |
205 |
<projection name="Unknown"> |
<projection name="Unknown"> |
245 |
expected_contents = '''<?xml version="1.0" encoding="UTF-8"?> |
expected_contents = '''<?xml version="1.0" encoding="UTF-8"?> |
246 |
<!DOCTYPE session SYSTEM "thuban-0.9.dtd"> |
<!DOCTYPE session SYSTEM "thuban-0.9.dtd"> |
247 |
<session title="single map&layer" |
<session title="single map&layer" |
248 |
xmlns="http://thuban.intevation.org/dtds/thuban-0.9-dev.dtd"> |
xmlns="http://thuban.intevation.org/dtds/thuban-0.9.dtd"> |
249 |
<map title="Test Map"> |
<map title="Test Map"> |
250 |
<rasterlayer title="My RasterLayer" filename="%s" |
<rasterlayer title="My RasterLayer" filename="%s" |
251 |
visible="true"> |
visible="true"> |
312 |
expected_template = '''<?xml version="1.0" encoding="UTF-8"?> |
expected_template = '''<?xml version="1.0" encoding="UTF-8"?> |
313 |
<!DOCTYPE session SYSTEM "thuban-0.9.dtd"> |
<!DOCTYPE session SYSTEM "thuban-0.9.dtd"> |
314 |
<session title="Map with Classifications" |
<session title="Map with Classifications" |
315 |
xmlns="http://thuban.intevation.org/dtds/thuban-0.9-dev.dtd"> |
xmlns="http://thuban.intevation.org/dtds/thuban-0.9.dtd"> |
316 |
<fileshapesource id="D1" filename="%s" filetype="shapefile"/> |
<fileshapesource id="D1" filename="%s" filetype="shapefile"/> |
317 |
<map title="Test Map"> |
<map title="Test Map"> |
318 |
<projection name="Unknown"> |
<projection name="Unknown"> |
370 |
|
|
371 |
def test_dbf_table(self): |
def test_dbf_table(self): |
372 |
"""Test saving a session with a dbf table link""" |
"""Test saving a session with a dbf table link""" |
373 |
session = Session("a DBF Table session") |
session = self.session = Session("a DBF Table session") |
374 |
# use shapefile from the example data |
# use shapefile from the example data |
375 |
dbffile = os.path.join(os.path.dirname(__file__), |
dbffile = os.path.join(os.path.dirname(__file__), |
376 |
os.pardir, "Data", "iceland", "political.dbf") |
os.pardir, "Data", "iceland", "political.dbf") |
385 |
expected_template = '''<?xml version="1.0" encoding="UTF-8"?> |
expected_template = '''<?xml version="1.0" encoding="UTF-8"?> |
386 |
<!DOCTYPE session SYSTEM "thuban-0.9.dtd"> |
<!DOCTYPE session SYSTEM "thuban-0.9.dtd"> |
387 |
<session title="a DBF Table session" |
<session title="a DBF Table session" |
388 |
xmlns="http://thuban.intevation.org/dtds/thuban-0.9-dev.dtd"> |
xmlns="http://thuban.intevation.org/dtds/thuban-0.9.dtd"> |
389 |
<filetable id="D1" filename="%s" filetype="DBF" title="political"/> |
<filetable id="D1" filename="%s" filetype="DBF" title="political"/> |
390 |
</session>''' |
</session>''' |
391 |
|
|
393 |
% os.path.join(os.pardir, os.pardir, "Data", |
% os.path.join(os.pardir, os.pardir, "Data", |
394 |
"iceland", "political.dbf")) |
"iceland", "political.dbf")) |
395 |
self.compare_xml(written_contents, expected_contents) |
self.compare_xml(written_contents, expected_contents) |
396 |
|
self.validate_data(written_contents) |
397 |
|
|
398 |
def test_joined_table(self): |
def test_joined_table(self): |
399 |
"""Test saving a session with joined table""" |
"""Test saving a session with joined table""" |
445 |
expected_template = '''<?xml version="1.0" encoding="UTF-8"?> |
expected_template = '''<?xml version="1.0" encoding="UTF-8"?> |
446 |
<!DOCTYPE session SYSTEM "thuban-0.9.dtd"> |
<!DOCTYPE session SYSTEM "thuban-0.9.dtd"> |
447 |
<session title="A Joined Table session" |
<session title="A Joined Table session" |
448 |
xmlns="http://thuban.intevation.org/dtds/thuban-0.9-dev.dtd"> |
xmlns="http://thuban.intevation.org/dtds/thuban-0.9.dtd"> |
449 |
<fileshapesource filename="%(shpfile)s" |
<fileshapesource filename="%(shpfile)s" |
450 |
filetype="shapefile" id="D142197204"/> |
filetype="shapefile" id="D142197204"/> |
451 |
<filetable filename="%(dbffile)s" |
<filetable filename="%(dbffile)s" |
471 |
"shpfile": relative_filename(self.temp_dir(), shpfile) |
"shpfile": relative_filename(self.temp_dir(), shpfile) |
472 |
} |
} |
473 |
self.compare_xml(written_contents, expected_contents) |
self.compare_xml(written_contents, expected_contents) |
474 |
|
self.validate_data(written_contents) |
475 |
finally: |
finally: |
476 |
session.Destroy() |
session.Destroy() |
477 |
session = None |
session = None |
513 |
expected = '''<?xml version="1.0" encoding="UTF-8"?> |
expected = '''<?xml version="1.0" encoding="UTF-8"?> |
514 |
<!DOCTYPE session SYSTEM "thuban-0.9.dtd"> |
<!DOCTYPE session SYSTEM "thuban-0.9.dtd"> |
515 |
<session title="A PostGIS Session" |
<session title="A PostGIS Session" |
516 |
xmlns="http://thuban.intevation.org/dtds/thuban-0.9-dev.dtd"> |
xmlns="http://thuban.intevation.org/dtds/thuban-0.9.dtd"> |
517 |
<dbconnection id="DB" |
<dbconnection id="DB" |
518 |
dbtype="postgis" dbname="plugh" |
dbtype="postgis" dbname="plugh" |
519 |
host="xyzzy" port="42" |
host="xyzzy" port="42" |