예제 #1
0
    def test_importXML5(self):
        db = _mysql.connect(host="z",
                            user="******",
                            passwd="U865dZpL0E",
                            db="cs327e_wigu")
        truncateAllTables(db)

        inputString = StringIO("""<root>
                                      <citations>
                                          <citationPair>
                                              <citationId>CIT_101</citationId>
                                              <citation>http://www.ncdc.noaa.gov/extremeevents/specialreports/Hurricane-Katrina.pdf</citation>
                                          </citationPair>
                                      </citations>
                                  </root>""")
        importXML(inputString)

        db.query("SELECT * FROM Citations")
        result = db.store_result()
        rows = result.fetch_row(maxrows=0, how=1)
        self.assert_(
            rows[0] == {
                "citationId":
                "1",
                "citation":
                "http://www.ncdc.noaa.gov/extremeevents/specialreports/Hurricane-Katrina.pdf"
            })
    def test_importXML3(self):
        db = _mysql.connect(host="z", user="******", passwd="U865dZpL0E", db="cs327e_wigu")
        truncateAllTables(db)

        inputString = StringIO("""<root>
                                      <people>
                                          <person>
                                              <personId>PER_001</personId>
                                              <name>George Clooney</name>
                                              <kind>Actor / Actress</kind>
                                              <streetAddress>8817 Lookout Mountain Ave</streetAddress>
                                              <city>Los Angeles</city>
                                              <stateOrProvince>California</stateOrProvince>
                                              <postalCode>90046-1819</postalCode>
                                              <country>USA</country>
                                            </person>
                                      </people>
                                  </root>""")
        importXML(inputString)

        db.query("SELECT * FROM People")
        result = db.store_result()
        rows = result.fetch_row(maxrows=0, how=1)
        self.assert_(rows[0] == {"personId" : "1",
                                 "name" : "George Clooney",
                                 "kind" : "Actor / Actress",
                                 "streetAddress" : "8817 Lookout Mountain Ave",
                                 "city" : "Los Angeles",
                                 "stateOrProvince" : "California",
                                 "postalCode" : "90046-1819",
                                 "country" : "USA"})
예제 #3
0
    def test_importXML4(self):
        db = _mysql.connect(host="z",
                            user="******",
                            passwd="U865dZpL0E",
                            db="cs327e_wigu")
        truncateAllTables(db)

        inputString = StringIO("""<root>
                                      <urls>
                                          <url>
                                              <urlId>URL_101</urlId>
                                              <type>Image</type>
                                              <urlAddress>http://web.mit.edu/12.000/www/m2010/images/katrina-08-28-2005.jpg</urlAddress>
                                          </url>
                                      </urls>
                                  </root>""")
        importXML(inputString)

        db.query("SELECT * FROM Urls")
        result = db.store_result()
        rows = result.fetch_row(maxrows=0, how=1)
        self.assert_(
            rows[0] == {
                "urlId":
                "1",
                "type":
                "Image",
                "urlAddress":
                "http://web.mit.edu/12.000/www/m2010/images/katrina-08-28-2005.jpg"
            })
예제 #4
0
    def test_importXML2(self):
        db = _mysql.connect(host="z",
                            user="******",
                            passwd="U865dZpL0E",
                            db="cs327e_wigu")
        truncateAllTables(db)

        inputString = StringIO("""<root>
                                      <orgs>
                                          <org>
                                              <orgId>ORG_001</orgId>
                                              <name>FEMA</name>
                                              <kind>Government Agency</kind>
                                              <streetAddress>500 C Street SW</streetAddress>
                                              <city>Washington, D.C.</city>
                                              <postalCode>20472</postalCode>
                                              <country>USA</country>
                                              <foundingMission>Support and protect citizens including during disaster or recovery</foundingMission>
                                              <dateFounded>1979-04-01</dateFounded>
                                              <majorEvents>First establishment of a federal emergency management in U.S. by Congressional Act of 1803</majorEvents>
                                          </org>
                                      </orgs>
                                  </root>""")
        importXML(inputString)

        db.query("SELECT * FROM Orgs")
        result = db.store_result()
        rows = result.fetch_row(maxrows=0, how=1)
        self.assert_(
            rows[0] == {
                "orgId":
                "1",
                "name":
                "FEMA",
                "kind":
                "Government Agency",
                "streetAddress":
                "500 C Street SW",
                "city":
                "Washington, D.C.",
                "stateOrProvince":
                None,
                "postalCode":
                "20472",
                "country":
                "USA",
                "foundingMission":
                "Support and protect citizens including during disaster or recovery",
                "dateFounded":
                "1979-04-01",
                "dateAbolished":
                None,
                "majorEvents":
                "First establishment of a federal emergency management in U.S. by Congressional Act of 1803"
            })
예제 #5
0
    def test_importXML1(self):
        db = _mysql.connect(host="z",
                            user="******",
                            passwd="U865dZpL0E",
                            db="cs327e_wigu")
        truncateAllTables(db)

        inputString = StringIO("""<root>
                                      <crises>
                                          <crisis>
                                              <crisisId>CRI_001</crisisId>
                                              <name>Katrina</name>
                                              <kind>Natural Disaster</kind>
                                              <city>New Orleans</city>
                                              <stateOrProvince>Louisiana</stateOrProvince>
                                              <country>United States</country>
                                              <dateAndTime>2005-08-26T09:00:00</dateAndTime>
                                              <fatalities>1300</fatalities>
                                              <damageInUSD>10000000000</damageInUSD>
                                          </crisis>
                                      </crises>
                                  </root>""")
        importXML(inputString)

        db.query("SELECT * FROM Crises")
        result = db.store_result()
        rows = result.fetch_row(maxrows=0, how=1)
        self.assert_(
            rows[0] == {
                "crisisId": "1",
                "name": "Katrina",
                "kind": "Natural Disaster",
                "streetAddress": None,
                "city": "New Orleans",
                "stateOrProvince": "Louisiana",
                "postalCode": None,
                "country": "United States",
                "dateAndTime": "2005-08-26 09:00:00",
                "fatalities": "1300",
                "injuries": None,
                "populationIll": None,
                "populationDisplaced": None,
                "environmentalImpact": None,
                "politicalChanges": None,
                "culturalChanges": None,
                "jobsLost": None,
                "damageInUSD": "10000000000",
                "reparationCost": None,
                "regulatoryChanges": None
            })
    def test_importXML1(self):
        db = _mysql.connect(host="z", user="******", passwd="U865dZpL0E", db="cs327e_wigu")
        truncateAllTables(db)

        inputString = StringIO("""<root>
                                      <crises>
                                          <crisis>
                                              <crisisId>CRI_001</crisisId>
                                              <name>Katrina</name>
                                              <kind>Natural Disaster</kind>
                                              <city>New Orleans</city>
                                              <stateOrProvince>Louisiana</stateOrProvince>
                                              <country>United States</country>
                                              <dateAndTime>2005-08-26T09:00:00</dateAndTime>
                                              <fatalities>1300</fatalities>
                                              <damageInUSD>10000000000</damageInUSD>
                                          </crisis>
                                      </crises>
                                  </root>""")
        importXML(inputString)

        db.query("SELECT * FROM Crises")
        result = db.store_result()
        rows = result.fetch_row(maxrows=0, how=1)
        self.assert_(rows[0] == {"crisisId" : "1",
                                 "name" : "Katrina",
                                 "kind" : "Natural Disaster",
                                 "streetAddress" : None,
                                 "city" : "New Orleans",
                                 "stateOrProvince" : "Louisiana",
                                 "postalCode" : None,
                                 "country" : "United States",
                                 "dateAndTime" : "2005-08-26 09:00:00",
                                 "fatalities" : "1300",
                                 "injuries" : None,
                                 "populationIll" : None,
                                 "populationDisplaced" : None,
                                 "environmentalImpact" : None,
                                 "politicalChanges" : None,
                                 "culturalChanges" : None,
                                 "jobsLost" : None,
                                 "damageInUSD" : "10000000000",
                                 "reparationCost" : None,
                                 "regulatoryChanges" : None})
    def test_importXML5(self):
        db = _mysql.connect(host="z", user="******", passwd="U865dZpL0E", db="cs327e_wigu")
        truncateAllTables(db)

        inputString = StringIO("""<root>
                                      <citations>
                                          <citationPair>
                                              <citationId>CIT_101</citationId>
                                              <citation>http://www.ncdc.noaa.gov/extremeevents/specialreports/Hurricane-Katrina.pdf</citation>
                                          </citationPair>
                                      </citations>
                                  </root>""")
        importXML(inputString)

        db.query("SELECT * FROM Citations")
        result = db.store_result()
        rows = result.fetch_row(maxrows=0, how=1)
        self.assert_(rows[0] == {"citationId" : "1",
                                 "citation" : "http://www.ncdc.noaa.gov/extremeevents/specialreports/Hurricane-Katrina.pdf"})
    def test_importXML4(self):
        db = _mysql.connect(host="z", user="******", passwd="U865dZpL0E", db="cs327e_wigu")
        truncateAllTables(db)

        inputString = StringIO("""<root>
                                      <urls>
                                          <url>
                                              <urlId>URL_101</urlId>
                                              <type>Image</type>
                                              <urlAddress>http://web.mit.edu/12.000/www/m2010/images/katrina-08-28-2005.jpg</urlAddress>
                                          </url>
                                      </urls>
                                  </root>""")
        importXML(inputString)

        db.query("SELECT * FROM Urls")
        result = db.store_result()
        rows = result.fetch_row(maxrows=0, how=1)
        self.assert_(rows[0] == {"urlId" : "1",
                                 "type" : "Image",
                                 "urlAddress" : "http://web.mit.edu/12.000/www/m2010/images/katrina-08-28-2005.jpg"})
    def test_importXML2(self):
        db = _mysql.connect(host="z", user="******", passwd="U865dZpL0E", db="cs327e_wigu")
        truncateAllTables(db)

        inputString = StringIO("""<root>
                                      <orgs>
                                          <org>
                                              <orgId>ORG_001</orgId>
                                              <name>FEMA</name>
                                              <kind>Government Agency</kind>
                                              <streetAddress>500 C Street SW</streetAddress>
                                              <city>Washington, D.C.</city>
                                              <postalCode>20472</postalCode>
                                              <country>USA</country>
                                              <foundingMission>Support and protect citizens including during disaster or recovery</foundingMission>
                                              <dateFounded>1979-04-01</dateFounded>
                                              <majorEvents>First establishment of a federal emergency management in U.S. by Congressional Act of 1803</majorEvents>
                                          </org>
                                      </orgs>
                                  </root>""")
        importXML(inputString)

        db.query("SELECT * FROM Orgs")
        result = db.store_result()
        rows = result.fetch_row(maxrows=0, how=1)
        self.assert_(rows[0] == {"orgId" : "1",
                                 "name" : "FEMA",
                                 "kind" : "Government Agency",
                                 "streetAddress" : "500 C Street SW",
                                 "city" : "Washington, D.C.",
                                 "stateOrProvince" : None,
                                 "postalCode" : "20472",
                                 "country" : "USA",
                                 "foundingMission" : "Support and protect citizens including during disaster or recovery",
                                 "dateFounded" : "1979-04-01",
                                 "dateAbolished" : None,
                                 "majorEvents" : "First establishment of a federal emergency management in U.S. by Congressional Act of 1803"})
예제 #10
0
    def test_importXML3(self):
        db = _mysql.connect(host="z",
                            user="******",
                            passwd="U865dZpL0E",
                            db="cs327e_wigu")
        truncateAllTables(db)

        inputString = StringIO("""<root>
                                      <people>
                                          <person>
                                              <personId>PER_001</personId>
                                              <name>George Clooney</name>
                                              <kind>Actor / Actress</kind>
                                              <streetAddress>8817 Lookout Mountain Ave</streetAddress>
                                              <city>Los Angeles</city>
                                              <stateOrProvince>California</stateOrProvince>
                                              <postalCode>90046-1819</postalCode>
                                              <country>USA</country>
                                            </person>
                                      </people>
                                  </root>""")
        importXML(inputString)

        db.query("SELECT * FROM People")
        result = db.store_result()
        rows = result.fetch_row(maxrows=0, how=1)
        self.assert_(
            rows[0] == {
                "personId": "1",
                "name": "George Clooney",
                "kind": "Actor / Actress",
                "streetAddress": "8817 Lookout Mountain Ave",
                "city": "Los Angeles",
                "stateOrProvince": "California",
                "postalCode": "90046-1819",
                "country": "USA"
            })
	def test_importXML_3 (self):
		xml = io.StringIO (unicode('<?xml version="1.0" encoding="utf-8"?><root><crises><crisis>1</crisis></crises></root>'))
		out = importXML (xml) 
		self.assertTrue(type(out) is Element)