def test_repr(self):
     the_dict = {
      '_id': '5853dbe27416a400011b1b77',
      'conditions': [{'_id': '5853dbe27416a400011b1b78',
                      'condition': {'amount': 273, 'expression': '$lt', 'name': 'temp'},
                      'current_value': {'max': 258.62, 'min': 258.62}}],
      'coordinates': {'lat': '53', 'lon': '37'},
      'date': '2016-12-17T00:00:00.000Z',
      'last_update': '2016-12-16T11:19:46.352Z',
      'triggerId': '5852816a9aaacb00153134a3'}
     instance = Alert.from_dict(the_dict)
     print(instance)
 def get_alerts_for(self, trigger):
     """
     Retrieves all of the alerts that were fired for the specified Trigger
     :param trigger: the trigger
     :type trigger: `pyowm.alertapi30.trigger.Trigger`
     :return: list of `pyowm.alertapi30.alert.Alert` objects
     """
     assert trigger is not None
     assert isinstance(trigger.id, str), "Value must be a string"
     status, data = self.http_client.get_json(
         ALERTS_URI % trigger.id,
         params={'appid': self.API_key},
         headers={'Content-Type': 'application/json'})
     return [Alert.from_dict(item) for item in data]
 def get_alert(self, alert_id, trigger):
     """
     Retrieves info about the alert record on the Alert API that has the specified ID and belongs to the specified
     parent Trigger object
     :param trigger: the parent trigger
     :type trigger: `pyowm.alertapi30.trigger.Trigger`
     :param alert_id: the ID of the alert
     :type alert_id `pyowm.alertapi30.alert.Alert`
     :return: an `pyowm.alertapi30.alert.Alert` instance
     """
     assert trigger is not None
     assert alert_id is not None
     assert isinstance(alert_id, str), "Value must be a string"
     assert isinstance(trigger.id, str), "Value must be a string"
     status, data = self.http_client.get_json(
         NAMED_ALERT_URI % (trigger.id, alert_id),
         params={'appid': self.API_key},
         headers={'Content-Type': 'application/json'})
     return Alert.from_dict(data)
    def test_from_dict(self):
        the_dict = {
         '_id': '5853dbe27416a400011b1b77',
         'conditions': [{'_id': '5853dbe27416a400011b1b78',
                         'condition': {'amount': 273, 'expression': '$lt', 'name': 'temp'},
                         'current_value': {'max': 258.62, 'min': 258.62}}],
         'coordinates': {'lat': '53', 'lon': '37'},
         'date': '2016-12-17T00:00:00.000Z',
         'last_update': '2016-12-16T11:19:46.352Z',
         'triggerId': '5852816a9aaacb00153134a3'}
        result = Alert.from_dict(the_dict)
        self.assertIsInstance(result, Alert)

        with self.assertRaises(pyowm.commons.exceptions.ParseAPIResponseError):
            Alert.from_dict(None)

        with self.assertRaises(pyowm.commons.exceptions.ParseAPIResponseError):
            Alert.from_dict(dict(nonexistent='key'))

        value_error_dict = copy.deepcopy(the_dict)
        value_error_dict['last_update'] = 'not_valid_timestamp'
        with self.assertRaises(pyowm.commons.exceptions.ParseAPIResponseError):
            Alert.from_dict(value_error_dict)