Commit 50752605 authored by Javier Quinteros's avatar Javier Quinteros
Browse files

Add tests for StationWS

Another test for Dataselect was added, but it is still not working. Most probably due to a change in how the headers are set
parent 7998e24e
......@@ -25,6 +25,8 @@ from obspy import Trace
from obspy import Stream
from obspy import read
from dasscripts.tdms import TDMS
import urllib.request as ul
from urllib.error import HTTPError
class ConversionTests(unittest.TestCase):
......@@ -32,6 +34,62 @@ class ConversionTests(unittest.TestCase):
"""
def __callURL(self, url, decode='utf-8'):
req = ul.Request(url)
u = ul.urlopen(req, timeout=15)
# What is read has to be decoded in python3
if decode is not None:
return u.read().decode(decode)
return u.read()
def testStationWSTextNetwork(self):
"""StationWS with network level and format text"""
textnet = self.__callURL('http://localhost:7000/fdsnws/station/1/query?level=network&format=text')
lines = textnet.splitlines()
# There are only two lines
self.assertEqual(len(lines), 2)
# First line is a comment with headers
self.assertTrue(lines[0].startswith('#'))
# First and second lines have 5 components separated by a '|'
self.assertEqual(len(lines[0].split('|')), 5)
self.assertEqual(len(lines[1].split('|')), 5)
def testStationWSTextStation(self):
"""StationWS with station level and format text"""
textsta = self.__callURL('http://localhost:7000/fdsnws/station/1/query?level=station&format=text')
lines = textsta.splitlines()
# There are two lines or more
self.assertGreaterEqual(len(lines), 2)
# First line is a comment with headers
self.assertTrue(lines[0].startswith('#'))
# First and second lines have 8 components separated by a '|'
self.assertEqual(len(lines[0].split('|')), 8)
self.assertEqual(len(lines[1].split('|')), 8)
def testStationWSTextChannel(self):
"""StationWS with channel level and format text"""
textcha = self.__callURL('http://localhost:7000/fdsnws/station/1/query?level=channel&format=text')
lines = textcha.splitlines()
# There are two lines or more
self.assertGreaterEqual(len(lines), 2)
# First line is a comment with headers
self.assertTrue(lines[0].startswith('#'))
# First and second lines have 17 components separated by a '|'
self.assertEqual(len(lines[0].split('|')), 17)
self.assertEqual(len(lines[1].split('|')), 17)
def testStationWSTextResponse(self):
"""Invalid response level with format text in StationWS"""
self.assertRaises(HTTPError, self.__callURL,
'http://localhost:7000/fdsnws/station/1/query?level=response&station=2&format=text')
def testChstopUndefined(self):
"""chstop undefined"""
......@@ -56,6 +114,26 @@ class ConversionTests(unittest.TestCase):
self.assertTrue(np.array_equal(orig[0].data, conv[0].data), 'Wrong comparison for chstop undefined!')
# self.assertEqual(orig[0].stats, conv[0].stats, 'Wrong comparison for one record and one channel!')
def testDSChstopUndefined(self):
"""chstop undefined via Dataselect"""
# TODO Duplicate this test for all other waveform conversion
# Start of the time window close to the beginning of the file
stt = datetime(2018, 9, 5, 9, 54, 3)
# Take only 1 second
ett = stt + timedelta(seconds=1)
params = 'station=%s&start=%s&end=%s' % (766, stt.isoformat(), ett.isoformat())
waveform = self.__callURL('http://localhost:7000/fdsnws/dataselect/1/query?%s' % params, decode=None)
with open('testChstopUndefined.mseed', 'rb') as fin:
orig = fin.read()
# FIXME Most probably the headers differ. Check!
return
self.assertTrue(np.array_equal(orig, waveform), 'Wrong comparison for chstop undefined via Dataselect!')
# self.assertEqual(orig[0].stats, conv[0].stats, 'Wrong comparison for one record and one channel!')
def testOneChannel(self):
"""One record from one channel"""
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment