Esempio n. 1
0
 def test_to_entity(self):
     model = Location(name=Databox.location_name, lon=Databox.lon,
                      lat=Databox.lat, city_id=Databox.city_id,
                      country=Databox.country)
     expected = Databox.location
     result = model.to_entity()
     Asserter.assertLocationEntitiesEqual(self, expected, result)
Esempio n. 2
0
 def test_from_entity(self):
     expected = Location(name=Databox.location_name,
                               lon=Databox.lon, lat=Databox.lat,
                               city_id=Databox.city_id,
                               country=Databox.country)
     result = Location.from_entity(Databox.location)
     Asserter.assertLocationModelsEqual(self, expected, result)
Esempio n. 3
0
 def test_from_entity(self):
     location = Location.from_entity(Databox.location)
     expected = Forecast(interval=Databox.interval,
                         reception_time=Databox.reception_time,
                         location=location)
     result = Forecast.from_entity(Databox.forecast)
     self.assertEquals(expected.interval, result.interval)
     self.assertEquals(expected.reception_time, result.reception_time)
     Asserter.assertLocationModelsEqual(self, expected.location, result.location)
Esempio n. 4
0
 def test_from_entity(self):
     location = Location.from_entity(Databox.location)
     weather = Weather.from_entity(Databox.weather)
     expected = Observation(reception_time=Databox.reception_time,
                            location=location,
                            weather=weather)
     result = Observation.from_entity(Databox.observation)
     self.assertEquals(expected.reception_time, result.reception_time)
     Asserter.assertLocationModelsEqual(self, expected.location, result.location)
     Asserter.assertWeatherModelsEqual(self, expected.weather, result.weather)
Esempio n. 5
0
 def test_from_entity(self):
     expected = COIndex(
         reference_time=Databox.reference_time,
         location=Location.from_entity(Databox.location),
         interval=Databox.coindex_interval,
         reception_time=Databox.reception_time,
         co_samples=json.dumps(Databox.co_samples))
     result = COIndex.from_entity(Databox.coindex)
     self.assertEquals(expected.reference_time, result.reference_time)
     self.assertEquals(expected.interval, result.interval)
     self.assertEquals(expected.reception_time, result.reception_time)
     self.assertEquals(sorted(expected.co_samples), sorted(result.co_samples))
     Asserter.assertLocationModelsEqual(self, expected.location, result.location)
Esempio n. 6
0
 def test_from_entity(self):
     expected = Ozone(
         reference_time=Databox.reference_time,
         location=Location.from_entity(Databox.location),
         du_value=Databox.du_value,
         interval=Databox.ozone_interval,
         reception_time=Databox.reception_time)
     result = Ozone.from_entity(Databox.ozone)
     self.assertEquals(expected.reference_time, result.reference_time)
     self.assertEquals(expected.interval, result.interval)
     self.assertEquals(expected.reception_time, result.reception_time)
     self.assertEquals(expected.du_value, result.du_value)
     Asserter.assertLocationModelsEqual(self, expected.location, result.location)
Esempio n. 7
0
 def test_to_entity(self):
     location = Location.from_entity(Databox.location)
     weather = Weather.from_entity(Databox.weather)
     model = Observation(reception_time=Databox.reception_time,
                         location=location,
                         weather=weather)
     result = model.to_entity()
     expected = Databox.observation
     self.assertEquals(expected.get_reception_time(), result.get_reception_time())
     Asserter.assertLocationEntitiesEqual(self, expected.get_location(),
                                        result.get_location())
     Asserter.assertWeatherEntitiesEqual(self, expected.get_weather(),
                                       result.get_weather())
Esempio n. 8
0
 def test_from_entity(self):
     expected = UVIndex(
         reference_time=Databox.reference_time,
         location=Location.from_entity(Databox.location),
         value=Databox.uvindex_intensity,
         interval=Databox.uvindex_interval,
         reception_time=Databox.reception_time)
     result = UVIndex.from_entity(Databox.uvindex)
     self.assertEquals(expected.reference_time, result.reference_time)
     self.assertEquals(expected.value, result.value)
     self.assertEquals(expected.interval, result.interval)
     self.assertEquals(expected.reception_time, result.reception_time)
     Asserter.assertLocationModelsEqual(self, expected.location, result.location)
Esempio n. 9
0
    def test_save_all(self):
        location = Location.from_entity(Databox.location)
        weather = Weather.from_entity(Databox.weather)
        observation = Observation(reception_time=Databox.reception_time,
                                  location=location,
                                  weather=weather)
        self.assertIsNone(location.pk)
        self.assertIsNone(weather.pk)
        self.assertIsNone(observation.pk)

        observation.save_all()
        self.assertIsNotNone(location.pk)
        self.assertIsNotNone(weather.pk)
        self.assertIsNotNone(observation.pk)
Esempio n. 10
0
    def test_save_all(self):
        location = Location.from_entity(Databox.location)
        ozone = Ozone(
            reference_time=Databox.reference_time,
            location=location,
            du_value=Databox.du_value,
            interval=Databox.ozone_interval,
            reception_time=Databox.reception_time)
        self.assertIsNone(location.pk)
        self.assertIsNone(ozone.pk)

        ozone.save_all()
        self.assertIsNotNone(location.pk)
        self.assertIsNotNone(ozone.pk)
Esempio n. 11
0
    def test_save_all(self):
        location = Location.from_entity(Databox.location)
        coindex = COIndex(
            reference_time=Databox.reference_time,
            location=location,
            interval=Databox.coindex_interval,
            reception_time=Databox.reception_time,
            co_samples=json.dumps(Databox.co_samples))
        self.assertIsNone(location.pk)
        self.assertIsNone(coindex.pk)

        coindex.save_all()
        self.assertIsNotNone(location.pk)
        self.assertIsNotNone(coindex.pk)
Esempio n. 12
0
    def test_save_all(self):
        location = Location.from_entity(Databox.location)
        uvindex = UVIndex(
            reference_time=Databox.reference_time,
            location=location,
            value=Databox.uvindex_intensity,
            interval=Databox.uvindex_interval,
            reception_time=Databox.reception_time)
        self.assertIsNone(location.pk)
        self.assertIsNone(uvindex.pk)

        uvindex.save_all()
        self.assertIsNotNone(location.pk)
        self.assertIsNotNone(uvindex.pk)
Esempio n. 13
0
 def test_to_entity(self):
     model = Ozone(
         reference_time=Databox.reference_time,
         location=Location.from_entity(Databox.location),
         du_value=Databox.du_value,
         interval=Databox.ozone_interval,
         reception_time=Databox.reception_time)
     result = model.to_entity()
     expected = Databox.ozone
     self.assertEquals(expected.get_reference_time(), result.get_reference_time())
     self.assertEquals(expected.get_du_value(), result.get_du_value())
     self.assertEquals(expected.get_interval(), result.get_interval())
     self.assertEquals(expected.get_reception_time(), result.get_reception_time())
     Asserter.assertLocationEntitiesEqual(self, expected.get_location(),
                                          result.get_location())
Esempio n. 14
0
 def test_to_entity(self):
     model = COIndex(
         reference_time=Databox.reference_time,
         location=Location.from_entity(Databox.location),
         interval=Databox.coindex_interval,
         reception_time=Databox.reception_time,
         co_samples=json.dumps(Databox.co_samples))
     result = model.to_entity()
     expected = Databox.coindex
     self.assertEquals(expected.get_reference_time(), result.get_reference_time())
     self.assertEquals(expected.get_co_samples(), result.get_co_samples())
     self.assertEquals(expected.get_interval(), result.get_interval())
     self.assertEquals(expected.get_reception_time(), result.get_reception_time())
     Asserter.assertLocationEntitiesEqual(self, expected.get_location(),
                                          result.get_location())
Esempio n. 15
0
 def test_to_entity(self):
     model = UVIndex(
         reference_time=Databox.reference_time,
         location=Location.from_entity(Databox.location),
         value=Databox.uvindex_intensity,
         interval=Databox.uvindex_interval,
         reception_time=Databox.reception_time)
     result = model.to_entity()
     expected = Databox.uvindex
     self.assertEquals(expected.get_reference_time(), result.get_reference_time())
     self.assertEquals(expected.get_value(), result.get_value())
     self.assertEquals(expected.get_interval(), result.get_interval())
     self.assertEquals(expected.get_reception_time(), result.get_reception_time())
     Asserter.assertLocationEntitiesEqual(self, expected.get_location(),
                                          result.get_location())
Esempio n. 16
0
    def test_save_all(self):
        weathers = [Weather.from_entity(w) for w in Databox.weathers]
        location = Location.from_entity(Databox.location)
        forecast = Forecast(interval=Databox.interval,
                            reception_time=Databox.reception_time,
                            location=location)
        self.assertIsNone(location.pk)
        for w in weathers:
            self.assertIsNone(w.pk)
        self.assertIsNone(forecast.pk)

        for w in weathers:
            w.save()
        forecast.save_all()
        self.assertIsNotNone(location.pk)
        self.assertIsNotNone(forecast.pk)
Esempio n. 17
0
 def test_to_entity(self):
     weats = [Weather.from_entity(w) for w in Databox.weathers]
     for w in weats:
         w.save()
     loc = Location.from_entity(Databox.location)
     loc.save()
     model = Forecast(interval=Databox.interval,
                      reception_time=Databox.reception_time,
                      location=loc)
     model.save()
     for w in weats:
         model.weathers.add(w)
     result = model.to_entity()
     expected = Databox.forecast
     self.assertEquals(expected.get_interval(), result.get_interval())
     self.assertEquals(expected.get_reception_time(), result.get_reception_time())
     Asserter.assertLocationEntitiesEqual(self, expected.get_location(),
                                        result.get_location())
     for ex_w, res_w in zip(expected.get_weathers(), result.get_weathers()):
         Asserter.assertWeatherEntitiesEqual(self, ex_w, res_w)
    def handle(self, *args, **options):
        if Location.objects.exists():
            self.stderr.write('You can save locations only to empty table')
            return

        city_registry = owm.city_id_registry()
        locations = []
        for line in city_registry._get_all_lines():
            tokens = line.strip().split(',')
            try:
                location_entity = LocationEntity(tokens[0], float(tokens[3]),
                                                 float(tokens[2]),
                                                 int(tokens[1]), tokens[4])
                location = Location.from_entity(location_entity)
                locations.append(location)
            except ValueError:
                pass
        Location.objects.bulk_create(locations, 500)
        self.stdout.write(
            self.style.SUCCESS('{} locations saved to database'.format(
                len(locations))))