def testDetect(self): fake_geo_api = FakeGeoApi({'Stockholm': ('Stockholm', 'Sweden')}) fake_weather_api = FakeWeatherApi(1000, 1400) detector = SunlightDetector('Stockholm', fake_geo_api, fake_weather_api) self.assertEqual(detector.detect(), ('Stockholm', 'Sweden', 1000, 1400))
def location(request): location = request.path.strip('/') try: detector = SunlightDetector(location, GeoApi(urllib), WeatherApi(urllib)) (city, country, sunrise, sunset) = detector.detect() sunrise_readable = "%s:%s" % (sunrise / 100, sunrise % 100) sunset_readable = "%s:%s" % (sunset / 100, sunrise % 100) daylight_readable = str(int(round((sunset - sunrise) / 2400.0 * 100))) context = { 'city': city, 'country': country, 'sunrise': sunrise, 'sunset': sunset, 'sunrise_readable': sunrise_readable, 'daylight_readable': daylight_readable, 'sunset_readable': sunset_readable } return render_to_response('location.html', context) except: context = RequestContext(request) context.update({'location': location}) return render_to_response('detector_error.html', context)
def testTextForANotDepressingPlace(self): fake_weather_api = FakeWeatherApi(sunrise = 759, sunset = 2201) detector = SunlightDetector('barcelona', fake_weather_api) depression_indicator = detector.detect() assert "Not Depressing" == depression_indicator.text()
def testTextForAVeryDepressingPlace(self): fake_weather_api = FakeWeatherApi(sunrise = 1000, sunset = 1400) detector = SunlightDetector('stockholm', fake_weather_api) depression_indicator = detector.detect() assert "Very Depressing" == depression_indicator.text()
def testTextForANotDepressingPlace(self): fake_weather_api = FakeWeatherApi(sunrise=759, sunset=2201) detector = SunlightDetector('barcelona', fake_weather_api) depression_indicator = detector.detect() assert "Not Depressing" == depression_indicator.text()
def testTextForAVeryDepressingPlace(self): fake_weather_api = FakeWeatherApi(sunrise=1000, sunset=1400) detector = SunlightDetector('stockholm', fake_weather_api) depression_indicator = detector.detect() assert "Very Depressing" == depression_indicator.text()