def test_url_building(self): """ Tests the build_url() functions. """ # Application WADL self.assertEqual( build_url("http://service.iris.edu", "dataselect", 1, "application.wadl"), "http://service.iris.edu/fdsnws/dataselect/1/application.wadl") self.assertEqual( build_url("http://service.iris.edu", "event", 1, "application.wadl"), "http://service.iris.edu/fdsnws/event/1/application.wadl") self.assertEqual( build_url("http://service.iris.edu", "station", 1, "application.wadl"), "http://service.iris.edu/fdsnws/station/1/application.wadl") # Test one parameter. self.assertEqual( build_url("http://service.iris.edu", "dataselect", 1, "query", {"network": "BW"}), "http://service.iris.edu/fdsnws/dataselect/1/query?network=BW") self.assertEqual( build_url("http://service.iris.edu", "dataselect", 1, "queryauth", {"network": "BW"}), "http://service.iris.edu/fdsnws/dataselect/1/queryauth?network=BW") # Test two parameters. Note random order, two possible results. self.assertTrue( build_url("http://service.iris.edu", "dataselect", 1, "query", { "net": "A", "sta": "BC" }) in ("http://service.iris.edu/fdsnws/dataselect/1/query?net=A&sta=BC", "http://service.iris.edu/fdsnws/dataselect/1/query?sta=BC&net=A")) # A wrong service raises a ValueError self.assertRaises(ValueError, build_url, "http://service.iris.edu", "obspy", 1, "query")
def test_url_building(self): """ Tests the build_url() functions. """ # Application WADL self.assertEqual( build_url("http://service.iris.edu", "dataselect", 1, "application.wadl"), "http://service.iris.edu/fdsnws/dataselect/1/application.wadl") self.assertEqual( build_url("http://service.iris.edu", "event", 1, "application.wadl"), "http://service.iris.edu/fdsnws/event/1/application.wadl") self.assertEqual( build_url("http://service.iris.edu", "station", 1, "application.wadl"), "http://service.iris.edu/fdsnws/station/1/application.wadl") # Test one parameter. self.assertEqual( build_url("http://service.iris.edu", "dataselect", 1, "query", {"network": "BW"}), "http://service.iris.edu/fdsnws/dataselect/1/query?network=BW") self.assertEqual( build_url("http://service.iris.edu", "dataselect", 1, "queryauth", {"network": "BW"}), "http://service.iris.edu/fdsnws/dataselect/1/queryauth?network=BW") # Test two parameters. Note random order, two possible results. self.assertTrue( build_url("http://service.iris.edu", "dataselect", 1, "query", {"net": "A", "sta": "BC"}) in ("http://service.iris.edu/fdsnws/dataselect/1/query?net=A&sta=BC", "http://service.iris.edu/fdsnws/dataselect/1/query?sta=BC&net=A")) # A wrong service raises a ValueError self.assertRaises(ValueError, build_url, "http://service.iris.edu", "obspy", 1, "query")
def test_location_parameters(self): """ Tests how the variety of location values are handled. Why location? Mostly because it is one tricky parameter. It is not uncommon to assume that a non-existent location is "--", but in reality "--" is "<space><space>". This substitution exists because mostly because various applications have trouble digesting spaces (spaces in the URL, for example). The confusion begins when location is treated as empty instead, which would imply "I want all locations" instead of "I only want locations of <space><space>" """ # requests with no specified location should be treated as a wildcard self.assertFalse("--" in build_url( "http://service.iris.edu", "station", 1, "query", { "network": "IU", "station": "ANMO", "starttime": "2013-01-01" })) # location of " " is the same as "--" self.assertEqual( build_url("http://service.iris.edu", "station", 1, "query", {"location": " "}), "http://service.iris.edu/fdsnws/station/1/query?location=--") # wildcard locations are valid. Will be encoded. self.assertEqual( build_url("http://service.iris.edu", "station", 1, "query", {"location": "*"}), "http://service.iris.edu/fdsnws/station/1/query?location=%2A") self.assertEqual( build_url("http://service.iris.edu", "station", 1, "query", {"location": "A?"}), "http://service.iris.edu/fdsnws/station/1/query?location=A%3F") # lists are valid, including <space><space> lists. Again encoded # result. self.assertEqual( build_url("http://service.iris.edu", "station", 1, "query", {"location": " ,1?,?0"}), "http://service.iris.edu/fdsnws/station/1/query?" "location=--%2C1%3F%2C%3F0") self.assertEqual( build_url("http://service.iris.edu", "station", 1, "query", {"location": "1?,--,?0"}), "http://service.iris.edu/fdsnws/station/1/query?" "location=1%3F%2C--%2C%3F0") # Test all three special cases with empty parameters into lists. self.assertEqual( build_url("http://service.iris.edu", "station", 1, "query", {"location": " ,AA,BB"}), "http://service.iris.edu/fdsnws/station/1/query?" "location=--%2CAA%2CBB") self.assertEqual( build_url("http://service.iris.edu", "station", 1, "query", {"location": "AA, ,BB"}), "http://service.iris.edu/fdsnws/station/1/query?" "location=AA%2C--%2CBB") self.assertEqual( build_url("http://service.iris.edu", "station", 1, "query", {"location": "AA,BB, "}), "http://service.iris.edu/fdsnws/station/1/query?" "location=AA%2CBB%2C--")
def test_location_parameters(self): """ Tests how the variety of location values are handled. Why location? Mostly because it is one tricky parameter. It is not uncommon to assume that a non-existent location is "--", but in reality "--" is "<space><space>". This substitution exists because mostly because various applications have trouble digesting spaces (spaces in the URL, for example). The confusion begins when location is treated as empty instead, which would imply "I want all locations" instead of "I only want locations of <space><space>" """ # requests with no specified location should be treated as a wildcard self.assertFalse( "--" in build_url("http://service.iris.edu", "station", 1, "query", {"network": "IU", "station": "ANMO", "starttime": "2013-01-01"})) # location of " " is the same as "--" self.assertEqual( build_url("http://service.iris.edu", "station", 1, "query", {"location": " "}), "http://service.iris.edu/fdsnws/station/1/query?location=--") # wildcard locations are valid. Will be encoded. self.assertEqual( build_url("http://service.iris.edu", "station", 1, "query", {"location": "*"}), "http://service.iris.edu/fdsnws/station/1/query?location=%2A") self.assertEqual( build_url("http://service.iris.edu", "station", 1, "query", {"location": "A?"}), "http://service.iris.edu/fdsnws/station/1/query?location=A%3F") # lists are valid, including <space><space> lists. Again encoded # result. self.assertEqual( build_url("http://service.iris.edu", "station", 1, "query", {"location": " ,1?,?0"}), "http://service.iris.edu/fdsnws/station/1/query?" "location=--%2C1%3F%2C%3F0") self.assertEqual( build_url("http://service.iris.edu", "station", 1, "query", {"location": "1?,--,?0"}), "http://service.iris.edu/fdsnws/station/1/query?" "location=1%3F%2C--%2C%3F0") # Test all three special cases with empty parameters into lists. self.assertEqual( build_url("http://service.iris.edu", "station", 1, "query", {"location": " ,AA,BB"}), "http://service.iris.edu/fdsnws/station/1/query?" "location=--%2CAA%2CBB") self.assertEqual( build_url("http://service.iris.edu", "station", 1, "query", {"location": "AA, ,BB"}), "http://service.iris.edu/fdsnws/station/1/query?" "location=AA%2C--%2CBB") self.assertEqual( build_url("http://service.iris.edu", "station", 1, "query", {"location": "AA,BB, "}), "http://service.iris.edu/fdsnws/station/1/query?" "location=AA%2CBB%2C--")
def test_location_parameters(self): """ Tests how the variety of location values are handled. Why location? Mostly because it is one tricky parameter. It is not uncommon to assume that a non-existent location is "--", but in reality "--" is "<space><space>". This substitution exists because mostly because various applications have trouble digesting spaces (spaces in the URL, for example). The confusion begins when location is treated as empty instead, which would imply "I want all locations" instead of "I only want locations of <space><space>" """ # requests with no specified location should be treated as a wildcard self.assertFalse( "--" in build_url("http://service.iris.edu", "station", 1, "query", {"network": "IU", "station": "ANMO", "starttime": "2013-01-01"})) # location of " " is the same as "--" self.assertEqual( build_url("http://service.iris.edu", "station", 1, "query", {"location": " "}), "http://service.iris.edu/fdsnws/station/1/query?location=--") # wildcard locations are valid. Will be encoded. self.assertEqual( build_url("http://service.iris.edu", "station", 1, "query", {"location": "*"}), "http://service.iris.edu/fdsnws/station/1/query?location=%2A") self.assertEqual( build_url("http://service.iris.edu", "station", 1, "query", {"location": "A?"}), "http://service.iris.edu/fdsnws/station/1/query?location=A%3F") # lists are valid, including <space><space> lists. Again encoded # result. self.assertEqual( build_url("http://service.iris.edu", "station", 1, "query", {"location": " ,1?,?0"}), "http://service.iris.edu/fdsnws/station/1/query?" "location=--%2C1%3F%2C%3F0") self.assertEqual( build_url("http://service.iris.edu", "station", 1, "query", {"location": "1?,--,?0"}), "http://service.iris.edu/fdsnws/station/1/query?" "location=1%3F%2C--%2C%3F0") # Test all three special cases with empty parameters into lists. self.assertEqual( build_url("http://service.iris.edu", "station", 1, "query", {"location": " ,AA,BB"}), "http://service.iris.edu/fdsnws/station/1/query?" "location=--%2CAA%2CBB") self.assertEqual( build_url("http://service.iris.edu", "station", 1, "query", {"location": "AA, ,BB"}), "http://service.iris.edu/fdsnws/station/1/query?" "location=AA%2C--%2CBB") self.assertEqual( build_url("http://service.iris.edu", "station", 1, "query", {"location": "AA,BB, "}), "http://service.iris.edu/fdsnws/station/1/query?" "location=AA%2CBB%2C--") # The location parameter is also passed through the # _create_url_from_parameters() method and thus has to survive it! # This guards against a regression where all empty location codes # where removed by this function! for service in ["station", "dataselect"]: for loc in ["", " ", " ", "--", b"", b" ", b" ", b"--", u"", u" ", u" ", u"--"]: self.assertIn( "location=--", self.client._create_url_from_parameters( service, [], {"location": loc, "starttime": 0, "endtime": 1})) # Also check the full call with a mock test. for loc in ["", " ", " ", "--", b"", b" ", b" ", b"--", u"", u" ", u" ", u"--"]: with mock.patch("obspy.clients.fdsn.Client._download") as p: try: self.client.get_stations(0, 0, location=loc) except: pass self.assertEqual(p.call_count, 1) self.assertIn("location=--", p.call_args[0][0]) with mock.patch("obspy.clients.fdsn.Client._download") as p: try: self.client.get_waveforms(1, 2, loc, 4, 0, 0) except: pass self.assertEqual(p.call_count, 1) self.assertIn("location=--", p.call_args[0][0])
def test_location_parameters(self): """ Tests how the variety of location values are handled. Why location? Mostly because it is one tricky parameter. It is not uncommon to assume that a non-existent location is "--", but in reality "--" is "<space><space>". This substitution exists because mostly because various applications have trouble digesting spaces (spaces in the URL, for example). The confusion begins when location is treated as empty instead, which would imply "I want all locations" instead of "I only want locations of <space><space>" """ # requests with no specified location should be treated as a wildcard self.assertFalse("--" in build_url( "http://service.iris.edu", "station", 1, "query", { "network": "IU", "station": "ANMO", "starttime": "2013-01-01" })) # location of " " is the same as "--" self.assertEqual( build_url("http://service.iris.edu", "station", 1, "query", {"location": " "}), "http://service.iris.edu/fdsnws/station/1/query?location=--") # wildcard locations are valid. Will be encoded. self.assertEqual( build_url("http://service.iris.edu", "station", 1, "query", {"location": "*"}), "http://service.iris.edu/fdsnws/station/1/query?location=%2A") self.assertEqual( build_url("http://service.iris.edu", "station", 1, "query", {"location": "A?"}), "http://service.iris.edu/fdsnws/station/1/query?location=A%3F") # lists are valid, including <space><space> lists. Again encoded # result. self.assertEqual( build_url("http://service.iris.edu", "station", 1, "query", {"location": " ,1?,?0"}), "http://service.iris.edu/fdsnws/station/1/query?" "location=--%2C1%3F%2C%3F0") self.assertEqual( build_url("http://service.iris.edu", "station", 1, "query", {"location": "1?,--,?0"}), "http://service.iris.edu/fdsnws/station/1/query?" "location=1%3F%2C--%2C%3F0") # Test all three special cases with empty parameters into lists. self.assertEqual( build_url("http://service.iris.edu", "station", 1, "query", {"location": " ,AA,BB"}), "http://service.iris.edu/fdsnws/station/1/query?" "location=--%2CAA%2CBB") self.assertEqual( build_url("http://service.iris.edu", "station", 1, "query", {"location": "AA, ,BB"}), "http://service.iris.edu/fdsnws/station/1/query?" "location=AA%2C--%2CBB") self.assertEqual( build_url("http://service.iris.edu", "station", 1, "query", {"location": "AA,BB, "}), "http://service.iris.edu/fdsnws/station/1/query?" "location=AA%2CBB%2C--") # The location parameter is also passed through the # _create_url_from_parameters() method and thus has to survive it! # This guards against a regression where all empty location codes # where removed by this function! for service in ["station", "dataselect"]: for loc in [ "", " ", " ", "--", b"", b" ", b" ", b"--", u"", u" ", u" ", u"--" ]: self.assertIn( "location=--", self.client._create_url_from_parameters( service, [], { "location": loc, "starttime": 0, "endtime": 1 })) # Also check the full call with a mock test. for loc in [ "", " ", " ", "--", b"", b" ", b" ", b"--", u"", u" ", u" ", u"--" ]: with mock.patch("obspy.clients.fdsn.Client._download") as p: try: self.client.get_stations(0, 0, location=loc) except: pass self.assertEqual(p.call_count, 1) self.assertIn("location=--", p.call_args[0][0]) with mock.patch("obspy.clients.fdsn.Client._download") as p: try: self.client.get_waveforms(1, 2, loc, 4, 0, 0) except: pass self.assertEqual(p.call_count, 1) self.assertIn("location=--", p.call_args[0][0])