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)
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())
def test_from_entity(self): expected = Weather( reference_time=Databox.reference_time, sunset_time=Databox.sunset_time, sunrise_time=Databox.sunrise_time, clouds=Databox.clouds, rain=json.dumps(Databox.rain), snow=json.dumps(Databox.snow), wind=json.dumps(Databox.wind), humidity=Databox.humidity, pressure=json.dumps(Databox.pressure), temperature=json.dumps(Databox.temperature), status=Databox.status, detailed_status=Databox.detailed_status, weather_code=Databox.weather_code, weather_icon_name=Databox.weather_icon_name, visibility_distance=Databox.visibility_distance, dewpoint=Databox.dewpoint, humidex=Databox.humidex, heat_index=Databox.heat_index) result = Weather.from_entity(Databox.weather) Asserter.assertWeatherModelsEqual(self, expected, result)
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)
def test_save_all(self): last_weather = Weather.from_entity(Databox.weather) station = Station(name=Databox.station_name, station_id=Databox.station_id, station_type=Databox.station_type, station_status=Databox.station_status, lat=Databox.lat, lon=Databox.lon, distance=Databox.station_distance, last_weather=last_weather) self.assertIsNone(last_weather.pk) self.assertIsNone(station.pk) station.save_all() self.assertIsNotNone(last_weather.pk) self.assertIsNotNone(station.pk)
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)
def test_from_entity(self): expected = Station(name=Databox.station_name, station_id=Databox.station_id, station_type=Databox.station_type, station_status=Databox.station_status, lat=Databox.lat, lon=Databox.lon, distance=Databox.station_distance, last_weather=Weather.from_entity(Databox.weather)) result = Station.from_entity(Databox.station) self.assertEquals(expected.name, result.name) self.assertEquals(expected.station_id, result.station_id) self.assertEquals(expected.station_type, result.station_type) self.assertEquals(expected.station_status, result.station_status) self.assertEquals(expected.lat, result.lat) self.assertEquals(expected.lon, result.lon) self.assertEquals(expected.distance, result.distance) Asserter.assertWeatherModelsEqual(self, expected.last_weather, result.last_weather)
def test_to_entity(self): model = Station(name=Databox.station_name, station_id=Databox.station_id, station_type=Databox.station_type, station_status=Databox.station_status, lat=Databox.lat, lon=Databox.lon, distance=Databox.station_distance, last_weather=Weather.from_entity(Databox.weather)) result = model.to_entity() expected = Databox.station self.assertEquals(expected.get_name(), result.get_name()) self.assertEquals(expected.get_station_ID(), result.get_station_ID()) self.assertEquals(expected.get_station_type(), result.get_station_type()) self.assertEquals(expected.get_status(), result.get_status()) self.assertEquals(expected.get_lat(), result.get_lat()) self.assertEquals(expected.get_lon(), result.get_lon()) self.assertEquals(expected.get_distance(), result.get_distance()) Asserter.assertWeatherEntitiesEqual(self, expected.get_last_weather(), result.get_last_weather())
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)