Example #1
0
 def test_save_data_city(self):
     print('Validate what is saved to the database matches what is received by JSON')
     #Current count of location and temp set for that location
     if Location.objects.filter(city_name='Pittsburgh').exists():
         Pitt = Location.objects.filter(city_name='Pittsburgh')
         Temp = Temperature.objects.get(location=Pitt)
         Wind = WindSpeed.objects.get(location=Pitt)
         Orig_count = Temp.count()
         Orig_wind = Wind.count()
     else:
         Orig_count = 0
         Orig_wind = 0
         Orig_advec = 0
     
     #Save a new entry
     loc_loader = LocationLoader()
     loc_loader.save_data_city('Pittsburgh,pa')
     
     #Assert location and tempset have been entered
     Pitt = Location.objects.get(city_name='Pittsburgh')
     Temp_count = Pitt.temperature_set.all().count()
     Wind_count = Pitt.windspeed_set.all().count()
     self.assertTrue(Location.objects.filter(city_name='Pittsburgh').exists())
     self.assertTrue(Temp_count == Orig_count + 1)
     self.assertTrue(Wind_count == Orig_wind + 1)
Example #2
0
 def test_loop_all_hist(self):
     
     #Prep the DB for Pittsburgh
     loc_loader = LocationLoader()
     loc_loader.save_data_city('Pittsburgh,pa')
     
     #prep timeframe variables
     load  = LocationLoaderHist()
     pitt = Location.objects.get(city_name='Pittsburgh')
     startb = datetime.datetime.now() + datetime.timedelta(-30)
     
     end_unaware = datetime.datetime.now() + datetime.timedelta(-1)
     end = end_unaware.replace(tzinfo=pytz.UTC)
     
     #clear out conflicting data
     pitt.temperature_set.all().delete()
     pitt.windspeed_set.all().delete()
     
     load.loop_all_hist('Pittsburgh',startb)
     
     #validate
     wind_max_dict = pitt.windspeed_set.all().aggregate(Max('timestamp'))
     temp_max_dict = pitt.temperature_set.all().aggregate(Max('timestamp')) 
     
     wind_max = wind_max_dict['timestamp__max']
     temp_max = temp_max_dict['timestamp__max']
     
     
     self.assertTrue( (wind_max - end) <= datetime.timedelta(days = 1))
     self.assertTrue( (temp_max - end) <= datetime.timedelta(days = 1))
Example #3
0
 def test_get_open_weather_city_imperial(self):
     print('Validate successful call of IMPERIAL weather data by city')
     loc_loader = LocationLoader()
     data = loc_loader.get_open_weather_city_imperial('Los Angeles,ca')
     print('Data Received from API Call')
     print(data)
     self.assertEqual(data[u'name'], u'Los Angeles')
Example #4
0
 def test_save_data_city_hist(self):
     
     loc_loader = LocationLoader()
     loc_loader.save_data_city('Pittsburgh,pa')
     
     
     print('Validate what is saved to the database matches what is received by JSON')
     #Current count of location and temp set for that location
     if Location.objects.filter(city_name='Pittsburgh').exists():
         Pitt = Location.objects.filter(city_name='Pittsburgh')
         Temp = Temperature.objects.get(location=Pitt)
         Wind = WindSpeed.objects.get(location=Pitt)
         Orig_count = 0
         Orig_wind = 0
     else:
         Orig_count = 0
         Orig_wind = 0
     
     pitt = Location.objects.get(city_name='Pittsburgh')
     id = pitt.city_id
     start_date_test = datetime.datetime.now() + datetime.timedelta(-30)
     end_date_test = datetime.datetime.now()
     
     #Save a new entry
     loc_loader = LocationLoaderHist()
     loc_loader.save_data_city_hist(id, start_date_test, end_date_test)
     
     #Assert location and tempset have been entered
     Pitt = Location.objects.get(city_name='Pittsburgh')
     Temp_count = Pitt.temperature_set.all().count()
     Wind_count = Pitt.windspeed_set.all().count()
     self.assertTrue(Location.objects.filter(city_name='Pittsburgh').exists())
     print Temp_count
     print Wind_count
     self.assertTrue(Temp_count >= Orig_count + 30)
     self.assertTrue(Wind_count >= Orig_wind + 30)