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_sncl_get_invalid_cha(self, mock_request): # request.method == 'GET' mock_request.method = 'GET' s = schema.SNCLSchema(context={'request': mock_request}) test_dataset = {'net': 'CH', 'sta': 'DAVOX', 'cha': 'BH,'} with self.assertRaises(ma.ValidationError): test_dataset = self._load(s, test_dataset)
def test_sncl_get_start_future(self, mock_request): # request.method == 'GET' mock_request.method = 'GET' s = schema.SNCLSchema(context={'request': mock_request}) # define starttime in future future = datetime.datetime.now() + datetime.timedelta(1) future = future.isoformat() test_dataset = {'net': 'CH', 'sta': 'DAVOX', 'start': future} with self.assertRaises(ma.ValidationError): test_dataset = self._load(s, test_dataset)
def test_sncl_get_end_lt_start(self, mock_request): # request.method == 'GET' mock_request.method = 'GET' s = schema.SNCLSchema(context={'request': mock_request}) # define endtime <= starttime test_dataset = { 'net': 'CH', 'sta': 'DAVOX', 'end': '2017-01-01', 'start': '2017-02-01' } with self.assertRaises(ma.ValidationError): test_dataset = self._load(s, test_dataset)
def test_sncl_post_missing_time(self, mock_request): # request.method == 'POST mock_request.method = 'POST' s = schema.SNCLSchema(context={'request': mock_request}) # define a invalid SNCL test_dataset = { 'net': 'CH', 'sta': 'DAVOX', 'loc': '*', 'cha': '*', 'start': '2017-01-01' } with self.assertRaises(ma.ValidationError): result = self._load(s, test_dataset)
def test_sncl_get_end_future(self, mock_request): # request.method == 'GET' mock_request.method = 'GET' s = schema.SNCLSchema(context={'request': mock_request}) # define endtime in future now = datetime.datetime.utcnow() tomorrow = now + datetime.timedelta(1) tomorrow_str = tomorrow.isoformat() test_dataset = {'net': 'CH', 'sta': 'DAVOX', 'end': tomorrow_str} result = self._load(s, test_dataset) self.assertAlmostEqual(result.endtime, now, delta=datetime.timedelta(seconds=1))
def test_sncl_post_start_lt_end(self, mock_request): # request.method == 'POST' mock_request.method = 'POST' s = schema.SNCLSchema(context={'request': mock_request}) # invalid time definition test_dataset = { 'net': 'CH', 'sta': 'DAVOX', 'loc': '*', 'cha': '*', 'start': '2017-01-02', 'end': '2017-01-01' } with self.assertRaises(ma.ValidationError): self._load(s, test_dataset)
def test_sncl_get_valid_loc_space(self, mock_request): # request.method == 'GET' mock_request.method = 'GET' s = schema.SNCLSchema(context={'request': mock_request}) # define multiple channels reference_result = { 'network': '*', 'station': '*', 'location': ' ', 'channel': '*' } test_dataset = {'loc': ' '} test_dataset = self._load(s, test_dataset) result = self._dump(s, test_dataset) self.assertEqual(result, reference_result)
def test_sncl_get_start(self, mock_request): # request.method == 'GET' mock_request.method = 'GET' s = schema.SNCLSchema(context={'request': mock_request}) # only endtime definition reference_result = { 'network': 'CH', 'station': 'DAVOX', 'location': '*', 'channel': '*', 'endtime': '2017-01-01T00:00:00' } test_dataset = {'net': 'CH', 'sta': 'DAVOX', 'end': '2017-01-01'} test_dataset = self._load(s, test_dataset) result = self._dump(s, test_dataset) self.assertEqual(result, reference_result)
def test_sncl_get(self, mock_request): # request.method == 'GET' mock_request.method = 'GET' s = schema.SNCLSchema(context={'request': mock_request}) # no time definitions reference_result = { 'network': 'CH?*', 'station': 'DAVOX?*', 'location': '*?ABC', 'channel': 'AZ?*' } test_dataset = { 'net': 'CH?*', 'sta': 'DAVOX?*', 'loc': '*?ABC', 'cha': 'AZ?*' } test_dataset = self._load(s, test_dataset) result = self._dump(s, test_dataset) self.assertEqual(result, reference_result)
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)