Ejemplo n.º 1
0
 def test_setup(self, m, mock_get_forecast):
     """Test for successfully setting up the forecast.io platform."""
     uri = ('https://api.darksky.net\/forecast\/(\w+)\/'
            '(-?\d+\.?\d*),(-?\d+\.?\d*)')
     m.get(re.compile(uri), text=load_fixture('darksky.json'))
     darksky.setup_platform(self.hass, self.config, MagicMock())
     self.assertTrue(mock_get_forecast.called)
     self.assertEqual(mock_get_forecast.call_count, 1)
Ejemplo n.º 2
0
 def test_setup(self, mock_req, mock_get_forecast):
     """Test for successfully setting up the forecast.io platform."""
     uri = (r'https://api.(darksky.net|forecast.io)\/forecast\/(\w+)\/'
            r'(-?\d+\.?\d*),(-?\d+\.?\d*)')
     mock_req.get(re.compile(uri), text=load_fixture('darksky.json'))
     darksky.setup_platform(self.hass, self.config, self.add_entities)
     self.assertTrue(mock_get_forecast.called)
     self.assertEqual(mock_get_forecast.call_count, 1)
     self.assertEqual(len(self.entities), 7)
Ejemplo n.º 3
0
 def test_setup(self, m, mock_get_forecast):
     """Test for successfully setting up the forecast.io platform."""
     uri = ('https://api.darksky.net\/forecast\/(\w+)\/'
            '(-?\d+\.?\d*),(-?\d+\.?\d*)')
     m.get(re.compile(uri),
           text=load_fixture('darksky.json'))
     darksky.setup_platform(self.hass, self.config, MagicMock())
     self.assertTrue(mock_get_forecast.called)
     self.assertEqual(mock_get_forecast.call_count, 1)
Ejemplo n.º 4
0
 def test_setup(self, mock_req, mock_get_forecast):
     """Test for successfully setting up the forecast.io platform."""
     uri = (r'https://api.(darksky.net|forecast.io)\/forecast\/(\w+)\/'
            r'(-?\d+\.?\d*),(-?\d+\.?\d*)')
     mock_req.get(re.compile(uri),
                  text=load_fixture('darksky.json'))
     darksky.setup_platform(self.hass, self.config, self.add_entities)
     self.assertTrue(mock_get_forecast.called)
     self.assertEqual(mock_get_forecast.call_count, 1)
     self.assertEqual(len(self.entities), 2)
Ejemplo n.º 5
0
    def test_setup_bad_api_key(self, mock_get_forecast):
        """Test for handling a bad API key."""
        # The Dark Sky API wrapper that we use raises an HTTP error
        # when you try to use a bad (or no) API key.
        url = 'https://api.darksky.net/forecast/{}/{},{}?units=auto'.format(
            self.key, str(self.lat), str(self.lon))
        msg = '400 Client Error: Bad Request for url: {}'.format(url)
        mock_get_forecast.side_effect = HTTPError(msg, )

        response = darksky.setup_platform(self.hass, self.config, MagicMock())
        self.assertFalse(response)
Ejemplo n.º 6
0
    def test_setup_bad_api_key(self, mock_get_forecast):
        """Test for handling a bad API key."""
        # The Dark Sky API wrapper that we use raises an HTTP error
        # when you try to use a bad (or no) API key.
        url = 'https://api.darksky.net/forecast/{}/{},{}?units=auto'.format(
            self.key, str(self.lat), str(self.lon)
        )
        msg = '400 Client Error: Bad Request for url: {}'.format(url)
        mock_get_forecast.side_effect = HTTPError(msg,)

        response = darksky.setup_platform(self.hass, self.config, MagicMock())
        self.assertFalse(response)
Ejemplo n.º 7
0
 def test_setup_no_latitude(self):
     """Test that the component is not loaded without required config."""
     self.hass.config.latitude = None
     self.assertFalse(darksky.setup_platform(self.hass, {}, MagicMock()))
Ejemplo n.º 8
0
 def test_setup_no_latitude(self):
     """Test that the component is not loaded without required config."""
     self.hass.config.latitude = None
     self.assertFalse(darksky.setup_platform(self.hass, {}, MagicMock()))