/[thuban]/branches/WIP-pyshapelib-bramz/test/test_save.py
ViewVC logotype

Diff of /branches/WIP-pyshapelib-bramz/test/test_save.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1599 by bh, Mon Aug 18 12:45:28 2003 UTC revision 1638 by bh, Fri Aug 22 18:19:14 2003 UTC
# Line 17  import os Line 17  import os
17  import unittest  import unittest
18  from StringIO import StringIO  from StringIO import StringIO
19    
 import xml.sax  
 import xml.sax.handler  
 from xml.sax import make_parser, ErrorHandler, SAXNotRecognizedException  
   
20  import xmlsupport  import xmlsupport
21    import postgissupport
22    
23  import support  import support
24  support.initthuban()  support.initthuban()
# Line 43  from Thuban.Model.classification import Line 40  from Thuban.Model.classification import
40    
41  from Thuban.Model.range import Range  from Thuban.Model.range import Range
42    
43    from Thuban.Model.postgisdb import PostGISConnection, PostGISShapeStore
44    
45    
46  class XMLWriterTest(unittest.TestCase):  class XMLWriterTest(unittest.TestCase):
47    
# Line 69  class SaveSessionTest(unittest.TestCase, Line 68  class SaveSessionTest(unittest.TestCase,
68      dtd = "http://thuban.intevation.org/dtds/thuban-0.9-dev.dtd"      dtd = "http://thuban.intevation.org/dtds/thuban-0.9-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"]]                    "derivedshapesource", "dbshapesource", "dbconnection"]]
72      thubanidrefs = [((dtd, n), (None, m)) for n, m in      thubanidrefs = [((dtd, n), (None, m)) for n, m in
73                      [("layer", "shapestore"),                      [("layer", "shapestore"),
74                       ("jointable", "left"),                       ("jointable", "left"),
75                       ("jointable", "right"),                       ("jointable", "right"),
76                       ("derivedshapesource", "table"),                       ("derivedshapesource", "table"),
77                       ("derivedshapesource", "shapesource")]]                       ("derivedshapesource", "shapesource"),
78                         ("dbshapesource", "dbconn")]]
79      del n, m, dtd      del n, m, dtd
80    
81      def compare_xml(self, xml1, xml2):      def compare_xml(self, xml1, xml2):
# Line 466  class SaveSessionTest(unittest.TestCase, Line 466  class SaveSessionTest(unittest.TestCase,
466              session = None              session = None
467    
468    
469        def test_save_postgis(self):
470            """Test saving a session with a postgis connection"""
471    
472            class NonConnection(PostGISConnection):
473                """connection class that doesn't actually connect """
474                def connect(self):
475                    pass
476    
477            class NonConnectionStore(PostGISShapeStore):
478                """Shapestore that doesn't try to access the server"""
479                def _fetch_table_information(self):
480                    pass
481    
482            session = Session("A PostGIS Session")
483            try:
484                dbconn = NonConnection(dbname="plugh", host="xyzzy", port="42",
485                                       user="grue")
486                session.AddDBConnection(dbconn)
487                map = Map("Test Map")
488                session.AddMap(map)
489                store = NonConnectionStore(dbconn, "roads")
490                session.AddShapeStore(store)
491                layer = Layer("Roads to Nowhere", store)
492                map.AddLayer(layer)
493    
494                # Save the session
495                filename = self.temp_file_name(self.id() + ".thuban")
496                save_session(session, filename)
497    
498                # Read it back and compare
499                file = open(filename)
500                written = file.read()
501                file.close()
502                expected = '''<?xml version="1.0" encoding="UTF-8"?>
503                <!DOCTYPE session SYSTEM "thuban-0.9.dtd">
504                <session title="A PostGIS Session"
505                 xmlns="http://thuban.intevation.org/dtds/thuban-0.9-dev.dtd">
506                    <dbconnection id="DB"
507                                  dbtype="postgis" dbname="plugh"
508                                  host="xyzzy" port="42"
509                                  user="grue"/>
510                    <dbshapesource id="roads" dbconn="DB" tablename="roads"/>
511                    <map title="Test Map">
512                        <layer title="Roads to Nowhere"
513                               shapestore="roads" visible="true"
514                               stroke="#000000" stroke_width="1" fill="None"/>
515                    </map>
516                </session>'''
517                self.compare_xml(written, expected)
518                self.validate_data(written)
519            finally:
520                session.Destroy()
521    
522    
523  class MockDataStore:  class MockDataStore:
524    
525      """A very simple data store that only has dependencies"""      """A very simple data store that only has dependencies"""

Legend:
Removed from v.1599  
changed lines
  Added in v.1638

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26