def test_forecast_date_order(self): base_url = self.endpoint # A user has forecast data payload = [encode_datetime(self.payload_prediction( valid_from=delta(hours=4), valid_to=delta(hours=6) ))] # The user submits the data to the endpoint self.assertSubmitPayload(base_url, payload) # A user has previous forecast data payload_2 = [encode_datetime(self.payload_prediction( True, valid_from=delta(hours=2), valid_to=delta(hours=4) ))] # The user submits the data to the endpoint self.assertSubmitPayload(base_url, payload_2) # The user queries for the latest record base_url = self.live_server_url + self.endpoint now_url = "{0}/now".format(base_url) data = self.assertRecordJSONExists(now_url) # record-0 matches the second payload self.assertPayloadMatchesData(data[0], payload_2[0]) # record-1 matches the first payload self.assertPayloadMatchesData(data[1], payload[0])
def test_observation_date_order(self): url = self.live_server_url + self.endpoint # A user has observation data payload = [ encode_datetime(self.payload_observation(datetime=delta(hours=-4))) ] # The user submits the data to the endpoint self.assertSubmitPayload(url, payload) payload_2 = [ encode_datetime(self.payload_observation(OBSERVATION_B, datetime=delta(hours=-2))) ] # The user submits the data to the endpoint self.assertSubmitPayload(url, payload_2) # The user queries for the recent record base_url = self.live_server_url + self.endpoint recent_url = "{0}/recent".format(base_url) data = self.assertRecordJSONExists(recent_url) # The first data matches the second payload self.assertPayloadMatchesData(data[0], payload_2[0]) # The second data matches the first payload self.assertPayloadMatchesData(data[1], payload[0])
def test_observation_date_order(self): url = self.endpoint # A user has observation data payload = [ encode_datetime(self.payload_observation(datetime=delta(hours=-4))) ] # The user submits the data to the endpoint self.assertSubmitPayload(url, payload) payload_2 = [ encode_datetime( self.payload_observation(OBSERVATION_B, datetime=delta(hours=-2))) ] # The user submits the data to the endpoint self.assertSubmitPayload(url, payload_2) # The user queries for the recent record base_url = self.live_server_url + self.endpoint recent_url = "{0}/recent".format(base_url) data = self.assertRecordJSONExists(recent_url) # The first data matches the second payload self.assertPayloadMatchesData(data[0], payload_2[0]) # The second data matches the first payload self.assertPayloadMatchesData(data[1], payload[0])
def test_forecast_date_order(self): base_url = self.endpoint # A user has forecast data payload = [ encode_datetime( self.payload_prediction(valid_from=delta(hours=4), valid_to=delta(hours=6))) ] # The user submits the data to the endpoint self.assertSubmitPayload(base_url, payload) # A user has previous forecast data payload_2 = [ encode_datetime( self.payload_prediction(True, valid_from=delta(hours=2), valid_to=delta(hours=4))) ] # The user submits the data to the endpoint self.assertSubmitPayload(base_url, payload_2) # The user queries for the latest record base_url = self.live_server_url + self.endpoint now_url = "{0}/now".format(base_url) data = self.assertRecordJSONExists(now_url) # record-0 matches the second payload self.assertPayloadMatchesData(data[0], payload_2[0]) # record-1 matches the first payload self.assertPayloadMatchesData(data[1], payload[0])
def test_prediction_latest(self): base_url = self.endpoint # A user has forecast data payload = [ encode_datetime( self.payload_prediction(valid_from=delta(hours=2), valid_to=delta(hours=4))) ] # The user submits the data to the endpoint self.assertSubmitPayload(base_url, payload) # A user has forecast data payload_2 = [ encode_datetime( self.payload_prediction(True, valid_from=delta(hours=4), valid_to=delta(hours=6))) ] # The user submits the data to the endpoint self.assertSubmitPayload(base_url, payload_2) # The user queries the latest endpoint latest_url = "{0}{1}/latest".format(self.live_server_url, base_url) data = self.assertRecordJSONExists(latest_url) # A single record is returned self.assertEqual(1, len(data)) # The user data matches the original payload self.assertPayloadMatchesData(data[0], payload[0])
def test_multiple_day_range_forecasts(self): base_url = self.endpoint # A user has forecast data payload = [ encode_datetime( self.payload_prediction(valid_from=delta(hours=2), valid_to=delta(hours=4))), encode_datetime( self.payload_prediction(True, valid_from=delta(days=1, hours=2), valid_to=delta(days=1, hours=4))) ] # The user submits the data to the endpoint self.assertSubmitPayload(base_url, payload) # The user queries for a range record base_url = self.live_server_url + self.endpoint range_url = "{0}?start={1}&end={2}" \ .format(base_url, format_datetime(delta()), format_datetime(delta(days=2))) data = self.assertRecordJSONExists(range_url) self.assertEqual(2, len(data))
def test_observation_latest(self): base_url = self.endpoint # A user has observation data payload = [ encode_datetime(self.payload_observation(datetime=delta(hours=-4))) ] # The user submits the data to the endpoint self.assertSubmitPayload(base_url, payload) payload_2 = [ encode_datetime( self.payload_observation(OBSERVATION_B, datetime=delta(hours=-6))) ] # The user submits the data to the endpoint self.assertSubmitPayload(base_url, payload_2) # The user queries the latest endpoint latest_url = "{0}/latest".format(self.live_server_url + base_url) data = self.assertRecordJSONExists(latest_url) # A single record is returned self.assertEqual(1, len(data)) # The user data matches the original payload self.assertPayloadMatchesData(data[0], payload[0])
def test_prediction_latest(self): base_url = self.endpoint # A user has forecast data payload = [ encode_datetime(self.payload_prediction(valid_from=delta(hours=2), valid_to=delta(hours=4))) ] # The user submits the data to the endpoint self.assertSubmitPayload(base_url, payload) # A user has forecast data payload_2 = [ encode_datetime(self.payload_prediction(True, valid_from=delta(hours=4), valid_to=delta(hours=6))) ] # The user submits the data to the endpoint self.assertSubmitPayload(base_url, payload_2) # The user queries the latest endpoint latest_url = "{0}{1}/latest".format(self.live_server_url, base_url) data = self.assertRecordJSONExists(latest_url) # A single record is returned self.assertEqual(1, len(data)) # The user data matches the original payload self.assertPayloadMatchesData(data[0], payload[0])
def test_observation_latest(self): base_url = self.live_server_url + self.endpoint # A user has observation data payload = [ encode_datetime(self.payload_observation(datetime=delta(hours=-4))) ] # The user submits the data to the endpoint self.assertSubmitPayload(base_url, payload) payload_2 = [ encode_datetime(self.payload_observation(OBSERVATION_B, datetime=delta(hours=-6))) ] # The user submits the data to the endpoint self.assertSubmitPayload(base_url, payload_2) # The user queries the latest endpoint latest_url = "{0}/latest".format(base_url) data = self.assertRecordJSONExists(latest_url) # A single record is returned self.assertEqual(1, len(data)) # The user data matches the original payload self.assertPayloadMatchesData(data[0], payload[0])
def test_multiple_day_range_forecasts(self): base_url = self.endpoint # A user has forecast data payload = [ encode_datetime(self.payload_prediction( valid_from=delta(hours=2), valid_to=delta(hours=4) )), encode_datetime(self.payload_prediction( True, valid_from=delta(days=1, hours=2), valid_to=delta(days=1, hours=4) )) ] # The user submits the data to the endpoint self.assertSubmitPayload(base_url, payload) # The user queries for a range record base_url = self.live_server_url + self.endpoint range_url = "{0}?start={1}&end={2}" \ .format(base_url, format_datetime(delta()), format_datetime(delta(days=2))) data = self.assertRecordJSONExists(range_url) self.assertEqual(2, len(data))
def test_can_save_observation(self): # A user has observation data payload = [encode_datetime(self.payload_observation_now())] # The user submits the data to the endpoint self.assertSubmitPayload(self.endpoint, payload) # The user queries for the recent record base_url = self.live_server_url + self.endpoint recent_url = "{0}/recent".format(base_url) data = self.assertRecordJSONExists(recent_url) # The user data matches the original payload self.assertPayloadMatchesData(data[0], payload[0]) # The user queries for a range record range_url = '{0}?start={1}&end={2}' \ .format(base_url, format_datetime(delta(hours=-1)), format_datetime(delta())) data = self.assertRecordJSONExists(range_url) # The user data matches the original payload self.assertPayloadMatchesData(data[0], payload[0]) # The user can has individual endpoints to query endpoints = [ key for key in payload[0].keys() if key not in ['datetime', 'supplier'] ] # The user queries each endpoint for endpoint in endpoints: url = "{0}/{1}/recent".format(base_url, endpoint.replace('_', '-')) # The user receives a JSON response from the endpoint data = self.assertRecordJSONExists(url) # The JSON response contains the observation data self.assertIn(endpoint, data[0]) self.assertEqual(payload[0][endpoint], data[0][endpoint]) url = "{0}/{1}/latest".format(base_url, endpoint.replace('_', '-')) # The user receives a JSON response from the endpoint latest data = self.assertRecordJSONExists(url) # The JSON response contains the datetime # The JSON response contains the observation data self.assertIn(endpoint, data[0]) self.assertEqual(payload[0][endpoint], data[0][endpoint]) self.assertIn('datetime', data[0]) self.assertEquals(payload[0]['datetime'], data[0]['datetime']) self.assertEqual(payload[0]['datetime'], data[0]['datetime']) # The user queries the latest endpoint latest_url = "{0}/latest".format(base_url) data = self.assertRecordJSONExists(latest_url) # The user data matches the original payload self.assertPayloadMatchesData(data[0], payload[0])
def test_can_save_observation(self): # A user has observation data payload = [encode_datetime(self.payload_observation_now())] # The user submits the data to the endpoint self.assertSubmitPayload(self.live_server_url + self.endpoint, payload) # The user queries for the recent record base_url = self.live_server_url + self.endpoint recent_url = "{0}/recent".format(base_url) data = self.assertRecordJSONExists(recent_url) # The user data matches the original payload self.assertPayloadMatchesData(data[0], payload[0]) # The user queries for a range record range_url = '{0}?start={1}&end={2}' \ .format(base_url, format_datetime(delta(hours=-1)), format_datetime(delta())) data = self.assertRecordJSONExists(range_url) # The user data matches the original payload self.assertPayloadMatchesData(data[0], payload[0]) # The user can has individual endpoints to query endpoints = [key for key in payload[0].keys() if key not in ['datetime', 'supplier']] # The user queries each endpoint for endpoint in endpoints: url = "{0}/{1}/recent".format(base_url, endpoint.replace('_', '-')) # The user receives a JSON response from the endpoint data = self.assertRecordJSONExists(url) # The JSON response contains the observation data self.assertIn(endpoint, data[0]) self.assertEqual(payload[0][endpoint], data[0][endpoint]) url = "{0}/{1}/latest".format(base_url, endpoint.replace('_', '-')) # The user receives a JSON response from the endpoint latest data = self.assertRecordJSONExists(url) # The JSON response contains the datetime # The JSON response contains the observation data self.assertIn(endpoint, data[0]) self.assertEqual(payload[0][endpoint], data[0][endpoint]) self.assertIn('datetime', data[0]) self.assertEquals(payload[0]['datetime'], data[0]['datetime']) self.assertEqual(payload[0]['datetime'], data[0]['datetime']) # The user queries the latest endpoint latest_url = "{0}/latest".format(base_url) data = self.assertRecordJSONExists(latest_url) # The user data matches the original payload self.assertPayloadMatchesData(data[0], payload[0])
def test_fields_are_optional(self): # A user has partial observation data payload = [ encode_datetime(self.payload_observation_now(OBSERVATION_C)) ] # The user submits the data to the endpoint self.assertSubmitPayload(self.endpoint, payload) # The user queries for the recent record base_url = self.live_server_url + self.endpoint recent_url = "{0}/recent".format(base_url) self.assertRecordJSONExists(recent_url) '''
def test_fields_are_optional(self): # A user has partial observation data payload = [encode_datetime( self.payload_observation_now(OBSERVATION_C))] # The user submits the data to the endpoint self.assertSubmitPayload(self.live_server_url + self.endpoint, payload) # The user queries for the recent record base_url = self.live_server_url + self.endpoint recent_url = "{0}/recent".format(base_url) self.assertRecordJSONExists(recent_url) '''
def test_will_update_observation(self): # A user has observation data payload = [encode_datetime(self.payload_observation_now())] # The user submits the data to the endpoint self.assertSubmitPayload(self.endpoint, payload) # The user submits modified data to the endpoint payload[0]['wind_gust'] = 5 self.assertSubmitPayload(self.endpoint, payload, status_code=200) # The user queries for the recent record base_url = self.live_server_url + self.endpoint recent_url = "{0}/recent".format(base_url) data = self.assertRecordJSONExists(recent_url) # A single record exists self.assertEqual(1, len(data)) # The user data matches the original payload self.assertPayloadMatchesData(data[0], payload[0])
def test_will_update_observation(self): # A user has observation data payload = [encode_datetime(self.payload_observation_now())] # The user submits the data to the endpoint self.assertSubmitPayload(self.live_server_url + self.endpoint, payload) # The user submits modified data to the endpoint payload[0]['wind_gust'] = 5 self.assertSubmitPayload(self.live_server_url + self.endpoint, payload, 200) # The user queries for the recent record base_url = self.live_server_url + self.endpoint recent_url = "{0}/recent".format(base_url) data = self.assertRecordJSONExists(recent_url) # A single record exists self.assertEqual(1, len(data)) # The user data matches the original payload self.assertPayloadMatchesData(data[0], payload[0])
def test_will_update_forecast(self): # A user has forecast data payload = [encode_datetime(self.payload_prediction_now())] base_url = self.endpoint # The user submits the data to the endpoint self.assertSubmitPayload(base_url, payload) # The user submits the data to the endpoint again payload[0]['pressure'] = 12 self.assertSubmitPayload(base_url, payload, status_code=200) # The user queries for the latest record base_url = self.live_server_url + self.endpoint now_url = "{0}/now".format(base_url) data = self.assertRecordJSONExists(now_url) # A single record exists self.assertEqual(1, len(data)) # The user data matches the second payload for index, _ in enumerate(data): self.assertPayloadMatchesData(data[index], payload[index])