def test_notifications_hook(self): sensor_value = SensorValue( sensor_id=1, value=56, timestamp=datetime.now().replace(tzinfo=utc)) sensor_value.save() threshold = Threshold(sensor_id=1) threshold.save() response = self.client.get('/api/notifications/') self.assertEqual(response.status_code, 200) data = json.loads(response.content) self.assertEqual(data['total'], 0) self.assertEqual(len(data['notifications']), 0) notification = Notification(threshold=threshold, sensor_value=sensor_value, target=50) notification.save() response = self.client.get('/api/notifications/') self.assertEqual(response.status_code, 200) data = json.loads(response.content) self.assertEqual(data['total'], 1) self.assertEqual(len(data['notifications']), 1) self.assertEqual(data['notifications'][0]['threshold']['id'], threshold.id)
def getNotification(self,title=None,date=None,insertOnBd=False): payload = {'format': 'json','title':title,'date':date} r = requests.get(self.baseUrlAPI+ 'notification/', params=payload) print r.status_code aux = r.json()['objects'] if len(aux) == 0 : stderr.write('Notification with title: \"'+title + '\" and date: \"' + str(date) + '\" doesn\'t exist in SIOrg+Pub') return None print aux data = aux[0] a = Notification(title=data['title'],description=data['description'],date=data['date']) if insertOnBd : a.save() return a
def getNotification(self, title=None, date=None, insertOnBd=False): payload = {'format': 'json', 'title': title, 'date': date} r = requests.get(self.baseUrlAPI + 'notification/', params=payload) print r.status_code aux = r.json()['objects'] if len(aux) == 0: stderr.write('Notification with title: \"' + title + '\" and date: \"' + str(date) + '\" doesn\'t exist in SIOrg+Pub') return None print aux data = aux[0] a = Notification(title=data['title'], description=data['description'], date=data['date']) if insertOnBd: a.save() return a
def test_notifications_hook(self): sensor_value = SensorValue(sensor_id=1, value=56, timestamp=datetime.now().replace(tzinfo=utc)) sensor_value.save() threshold = Threshold(sensor_id=1) threshold.save() response = self.client.get('/api/notifications/') self.assertEqual(response.status_code, 200) data = json.loads(response.content) self.assertEqual(data['total'], 0) self.assertEqual(len(data['notifications']), 0) notification = Notification(threshold=threshold, sensor_value=sensor_value, target=50) notification.save() response = self.client.get('/api/notifications/') self.assertEqual(response.status_code, 200) data = json.loads(response.content) self.assertEqual(data['total'], 1) self.assertEqual(len(data['notifications']), 1) self.assertEqual( data['notifications'][0]['threshold']['id'], threshold.id)
import setup_environment import datetime from server.models import UserWeatherInfo, WeatherInfo, Notification # Loop over all entries in the UserWeatherInfo table user_weather_infos = UserWeatherInfo.objects.all() for user_weather_info in user_weather_infos: user_id = user_weather_info.user_id location = user_weather_info.location # Obtain weather info for this location. weather_info = WeatherInfo.objects.get(location=location, date=datetime.date.today()) notification = 'The weather prediction is %s with a max temperature of %f' % (weather_info.forecast_condition, weather_info.forecast_temperature) tomorrow = datetime.date.today() + datetime.timedelta(days=1) morning_time = datetime.time(8, 00) tomorrow_time = datetime.datetime.combine(tomorrow, morning_time) notif = Notification(user_id=user_id, notification=notification, schedule_time=tomorrow_time, done=False) notif.save()