def test_get_multiple(self, mock_request): mock_request.method = 'GET' mock_request.args = MultiDict({ 'f': 'value', 'net': 'CH', 'sta': 'DAVOX,BALST', 'start': '2017-01-01', 'end': '2017-01-07' }) reference_sncls = [ utils.SNCL(network='CH', station='DAVOX', location='*', channel='*', starttime=datetime.datetime(2017, 1, 1), endtime=datetime.datetime(2017, 1, 7)), utils.SNCL(network='CH', station='BALST', location='*', channel='*', starttime=datetime.datetime(2017, 1, 1), endtime=datetime.datetime(2017, 1, 7)) ] test_args = parser.parse(self.TestSchema(), mock_request, locations=('query', )) self.assertEqual(dict(test_args), {'f': 'value'}) sncls = utils.fdsnws_parser.parse( schema.ManySNCLSchema(context={'request': mock_request}), mock_request, locations=('query', ))['sncls'] self.assertEqual(sncls, reference_sncls)
def test_post_multiple(self, mock_request): mock_request.method = 'POST' mock_request.stream = io.StringIO( "f=value\nNL HGN ?? * 2013-10-10 2013-10-11\n" "GR BFO * * 2017-01-01 2017-01-31") reference_sncls = [ utils.SNCL(network='NL', station='HGN', location='??', channel='*', starttime=datetime.datetime(2013, 10, 10), endtime=datetime.datetime(2013, 10, 11)), utils.SNCL(network='GR', station='BFO', location='*', channel='*', starttime=datetime.datetime(2017, 1, 1), endtime=datetime.datetime(2017, 1, 31)) ] test_args = utils.fdsnws_parser.parse(self.TestSchema(), mock_request, locations=('form', )) self.assertEqual(dict(test_args), {'f': 'value'}) sncls = utils.fdsnws_parser.parse( schema.ManySNCLSchema(context={'request': mock_request}), mock_request, locations=('form', ))['sncls'] self.assertEqual(sncls, reference_sncls)
def test_many_sncls(self, mock_request): # request.method == 'POST' mock_request.method = 'POST' s = schema.ManySNCLSchema(context={'request': mock_request}) reference_result = [ utils.SNCL(network='CH', station='DAVOX', starttime=datetime.datetime(2017, 1, 1), endtime=datetime.datetime(2017, 1, 31)), utils.SNCL(network='GR', station='BFO', channel='BH?', starttime=datetime.datetime(2017, 1, 1), endtime=datetime.datetime(2017, 1, 31)) ] test_dataset = { 'sncls': [{ '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).data['sncls'] self.assertEqual(result, reference_result)
def test_sncl_post_start_end_future(self, mock_request): # request.method == 'POST' mock_request.method = 'POST' s = schema.SNCLSchema(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 = utils.SNCL(network='CH', station='DAVOX', location='*', channel='*', 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)
def test_get_missing(self, mock_request): mock_request.method = 'GET' mock_request.args = MultiDict({'f': 'value'}) reference_sncls = [ utils.SNCL(network='*', station='*', location='*', channel='*') ] test_args = parser.parse(self.TestSchema(), mock_request, locations=('query', )) self.assertEqual(dict(test_args), {'f': 'value'}) sncls = utils.fdsnws_parser.parse( schema.ManySNCLSchema(context={'request': mock_request}), mock_request, locations=('query', ))['sncls'] self.assertEqual(sncls, reference_sncls)
def test_sncl_post(self, mock_request): # request.method == 'POST' mock_request.method = 'POST' s = schema.SNCLSchema(context={'request': mock_request}) # valid values - single SNCL line reference_result = utils.SNCL(network='CH', station='DAVOX', location='*', channel='*', 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)