def test_many_sncls(self, mock_request): # request.method == 'POST' mock_request.method = 'POST' s = schema.ManyStreamEpochSchema(context={'request': mock_request}) reference_result = [ sncl.StreamEpoch(stream=sncl.Stream(network='CH', station='DAVOX'), starttime=datetime.datetime(2017, 1, 1), endtime=datetime.datetime(2017, 1, 31)), sncl.StreamEpoch(stream=sncl.Stream(network='GR', station='BFO', channel='BH?'), starttime=datetime.datetime(2017, 1, 1), endtime=datetime.datetime(2017, 1, 31)) ] test_dataset = { 'stream_epochs': [{ 'net': 'CH', 'sta': 'DAVOX', 'start': '2017-01-01', 'end': '2017-01-31' }, { 'net': 'GR', 'sta': 'BFO', 'cha': 'BH?', 'start': '2017-01-01', 'end': '2017-01-31' }] } result = s.load(test_dataset)['stream_epochs'] self.assertEqual(result, reference_result)
def test_slice_with_endtime(self): stream_epoch = sncl.StreamEpoch(stream=self.stream, starttime=datetime.datetime( 2018, 1, 1), endtime=datetime.datetime(2018, 1, 8)) reference_result = [ sncl.StreamEpoch(stream=self.stream, starttime=datetime.datetime(2018, 1, 1), endtime=datetime.datetime(2018, 1, 4, 12)), sncl.StreamEpoch(stream=self.stream, starttime=datetime.datetime(2018, 1, 4, 12), endtime=datetime.datetime(2018, 1, 8)) ] self.assertEqual(sorted(stream_epoch.slice(num=2)), reference_result)
def test_get_missing(self, mock_request): mock_request.method = 'GET' mock_request.args = MultiDict({'f': 'value'}) reference_sncls = [sncl.StreamEpoch(stream=sncl.Stream())] test_args = parser.parse(self.TestSchema(), mock_request, locations=('query', )) self.assertEqual(dict(test_args), {'f': 'value'}) sncls = fdsnws.fdsnws_parser.parse( schema.ManyStreamEpochSchema(context={'request': mock_request}), mock_request, locations=('query', ))['stream_epochs'] self.assertEqual(sncls, reference_sncls)
def test_sncl_post(self, mock_request): # request.method == 'POST' mock_request.method = 'POST' s = schema.StreamEpochSchema(context={'request': mock_request}) # valid values - single SNCL line reference_result = sncl.StreamEpoch( stream=sncl.Stream(network='CH', station='DAVOX'), starttime=datetime.datetime(2017, 1, 1), endtime=datetime.datetime(2017, 1, 2)) test_dataset = { 'net': 'CH', 'sta': 'DAVOX', 'loc': '*', 'cha': '*', 'start': '2017-01-01', 'end': '2017-01-02'} result = self._load(s, test_dataset) self.assertEqual(result, reference_result)
def test_sncl_post_start_end_future(self, mock_request): # request.method == 'POST' mock_request.method = 'POST' s = schema.StreamEpochSchema(context={'request': mock_request}) # both starttime and endtime in future (not caught) today = datetime.datetime.now() tomorrow = today + datetime.timedelta(1) tomorrow_str = tomorrow.isoformat() dat = today + datetime.timedelta(2) dat_str = dat.isoformat() reference_result = sncl.StreamEpoch( stream=sncl.Stream(network='CH', station='DAVOX'), starttime=tomorrow, endtime=dat) test_dataset = {'net': 'CH', 'sta': 'DAVOX', 'loc': '*', 'cha': '*', 'start': tomorrow_str, 'end': dat_str} result = self._load(s, test_dataset) self.assertEqual(result, reference_result)