Пример #1
0
    def test_expired(self):
        """Test that an alert is expired or active"""
        forecast = forecastio.manual(os.path.join('fixtures', 'us_alert.json'))
        alert = models.WeatherAlert(forecast.alerts()[0])
        self.assertTrue(
            alert.expired(
                pytz.utc.localize(datetime.datetime(2017, 10, 18, 4, 4))))
        self.assertFalse(
            alert.expired(
                pytz.utc.localize(datetime.datetime(2016, 10, 18, 4, 4))))
        self.assertFalse(
            alert.expired(
                pytz.utc.localize(datetime.datetime(2015, 10, 18, 4, 4))))

        forecast = forecastio.manual(os.path.join('fixtures', 'ca_alert.json'))
        alert = models.WeatherAlert(forecast.alerts()[0])
        self.assertTrue(
            alert.expired(
                pytz.utc.localize(datetime.datetime(2017, 2, 7, 17, 12))))
        self.assertFalse(
            alert.expired(
                pytz.utc.localize(datetime.datetime(2017, 2, 7, 17, 11))))
        self.assertFalse(
            alert.expired(
                pytz.utc.localize(datetime.datetime(2017, 2, 3, 17, 11))))
Пример #2
0
 def test_no_expires(self):
     """Test that a WeatherAlert is loaded correctly"""
     forecast = forecastio.manual(os.path.join('fixtures', 'ca_alert.json'))
     alert = models.WeatherAlert(forecast.alerts()[0])
     self.assertEqual('Snowfall Warning', alert.title)
     self.assertEqual(pytz.utc.localize(datetime.datetime(2017, 2, 4, 17, 11)), alert.time)
     self.assertEqual('https://weather.gc.ca/warnings/report_e.html?ab6', alert.uri)
     self.assertEqual('warning', alert.severity)
     self.assertEqual('d5c1870d583f95441a41d452355173bad49f60f87c2962f195bd7873f0997d4b', alert.sha())
     self.assertEqual('<WeatherAlert: Snowfall Warning at 2017-02-04 17:11:00+00:00>', str(alert))
Пример #3
0
 def test_init(self, mock_get):
     """Test that a WeatherAlert is loaded correctly"""
     forecast = forecastio.manual(os.path.join('fixtures', 'us_alert.json'))
     alert = models.WeatherAlert(forecast.alerts()[0])
     self.assertEqual('Wind Advisory', alert.title)
     self.assertEqual(pytz.utc.localize(datetime.datetime(2016, 10, 18, 4, 4)), alert.time)
     self.assertEqual(pytz.utc.localize(datetime.datetime(2016, 10, 20, 19, 0)), alert.expires)
     self.assertEqual('https://alerts.weather.gov/cap/wwacapget.php?x=CA12561A519050.WindAdvisory.'
                      '12561A725D30CA.LOXNPWLOX.9240bcf720aae1b01b10f53f012e61bb', alert.uri)
     self.assertEqual('a6bf597275fdf063c76a42b05c3c81ed093701b2344c3c98cfde36875f7a4c3d', alert.sha())
     self.assertEqual('<WeatherAlert: Wind Advisory at 2016-10-18 04:04:00+00:00>', str(alert))
Пример #4
0
 def test_init(self, mock_get):
     """Test that a WeatherAlert is loaded correctly"""
     forecast = forecastio.manual(os.path.join('fixtures', 'us_alert.json'))
     alert = models.WeatherAlert(forecast.alerts()[0])
     self.assertEqual(alert.title, 'Wind Advisory for Los Angeles, CA')
     self.assertEqual(alert.time, pytz.utc.localize(datetime.datetime(2016, 10, 18, 4, 4)))
     self.assertEqual(alert.expires, pytz.utc.localize(datetime.datetime(2016, 10, 20, 19, 0)))
     self.assertEqual(alert.uri, 'https://alerts.weather.gov/cap/wwacapget.php?x=CA12561A519050.WindAdvisory.'
                                 '12561A725D30CA.LOXNPWLOX.9240bcf720aae1b01b10f53f012e61bb')
     self.assertEqual(alert.sha(), '7e220f06588bad306e05953409d8ec7ebe538ab76ecd4f4a562ac0e406a81c2e')
     self.assertEqual(str(alert), '<WeatherAlert: Wind Advisory for Los Angeles, CA at 2016-10-18 04:04:00+00:00>')