Skip to content
Snippets Groups Projects
Commit eebc2d9b authored by Jörn Künsemöller's avatar Jörn Künsemöller
Browse files

TMSS-435: add tests for sunrise etc.

parent 8282fea9
No related branches found
No related tags found
1 merge request!269Resolve TMSS-435
......@@ -26,6 +26,7 @@ import logging
import requests
import dateutil.parser
import astropy.coordinates
import json
logger = logging.getLogger(__name__)
logging.basicConfig(format='%(asctime)s %(levelname)s %(message)s', level=logging.INFO)
......@@ -127,6 +128,43 @@ class UtilREST(unittest.TestCase):
lon_str2 = r2.content.decode('utf8')
self.assertNotEqual(lon_str1, lon_str2)
def test_util_sun_rise_and_set_returns_json_structure_with_defaults(self):
r = requests.get(BASE_URL + '/util/sun_rise_and_set', auth=AUTH)
self.assertEqual(r.status_code, 200)
r_dict = json.loads(r.content.decode('utf-8'))
# assert defaults to core and today
self.assertIn('CS002', r_dict.keys())
sunrise_start = dateutil.parser.parse(r_dict['CS002']['sunrise'][0]['start'])
self.assertEqual(datetime.date.today(), sunrise_start.date())
def test_util_sun_rise_and_set_considers_stations(self):
stations = ['CS005', 'RS305', 'DE609']
r = requests.get(BASE_URL + '/util/sun_rise_and_set?stations=%s' % ','.join(stations), auth=AUTH)
self.assertEqual(r.status_code, 200)
r_dict = json.loads(r.content.decode('utf-8'))
# assert station is included in response and timestamps differ
sunset_start_last = None
for station in stations:
self.assertIn(station, r_dict.keys())
sunset_start = dateutil.parser.parse(r_dict[station]['sunset'][0]['start'])
if sunset_start_last:
self.assertNotEqual(sunset_start, sunset_start_last)
sunset_start_last = sunset_start
def test_util_sun_rise_and_set_considers_timestamps(self):
timestamps = ['2020-01-01', '2020-02-22T16-00-00', '2020-3-11', '2020-01-01']
r = requests.get(BASE_URL + '/util/sun_rise_and_set?timestamps=%s' % ','.join(timestamps), auth=AUTH)
self.assertEqual(r.status_code, 200)
r_dict = json.loads(r.content.decode('utf-8'))
# assert all requested timestamps are included in response (sunrise on same day)
for i in range(len(timestamps)):
expected_date = dateutil.parser.parse(timestamps[i]).date()
response_date = dateutil.parser.parse(r_dict['CS002']['sunrise'][i]['start']).date()
self.assertEqual(expected_date, response_date)
if __name__ == "__main__":
os.environ['TZ'] = 'UTC'
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment