Exemple #1
0
    def test_invalid_sensors(self, mock):
        """Test the VultrSensor fails."""
        mock.get(
            'https://api.vultr.com/v1/account/info?api_key=ABCDEFG1234567',
            text=load_fixture('vultr_account_info.json'))

        mock.get('https://api.vultr.com/v1/server/list?api_key=ABCDEFG1234567',
                 text=load_fixture('vultr_server_list.json'))

        base_vultr.setup(self.hass, VALID_CONFIG)

        bad_conf = {
            CONF_MONITORED_CONDITIONS: vultr.MONITORED_CONDITIONS,
        }  # No subs at all

        no_sub_setup = vultr.setup_platform(self.hass, bad_conf,
                                            self.add_devices, None)

        self.assertIsNotNone(no_sub_setup)
        self.assertEqual(0, len(self.DEVICES))
    def test_invalid_sensors(self, mock):
        """Test the VultrSensor fails."""
        mock.get(
            'https://api.vultr.com/v1/account/info?api_key=ABCDEFG1234567',
            text=load_fixture('vultr_account_info.json'))

        with patch('vultr.Vultr.server_list',
                   return_value=json.loads(
                       load_fixture('vultr_server_list.json'))):
            # Setup hub
            base_vultr.setup(self.hass, VALID_CONFIG)

        bad_conf = {
            CONF_MONITORED_CONDITIONS: vultr.MONITORED_CONDITIONS,
        }  # No subs at all

        no_sub_setup = vultr.setup_platform(self.hass, bad_conf,
                                            self.add_entities, None)

        assert no_sub_setup is None
        assert 0 == len(self.DEVICES)
Exemple #3
0
    def test_invalid_sensors(self, mock):
        """Test the VultrSensor fails."""
        mock.get(
            'https://api.vultr.com/v1/account/info?api_key=ABCDEFG1234567',
            text=load_fixture('vultr_account_info.json'))

        with patch(
            'vultr.Vultr.server_list',
            return_value=json.loads(
                load_fixture('vultr_server_list.json'))):
            # Setup hub
            base_vultr.setup(self.hass, VALID_CONFIG)

        bad_conf = {
            CONF_MONITORED_CONDITIONS: vultr.MONITORED_CONDITIONS,
        }  # No subs at all

        no_sub_setup = vultr.setup_platform(
            self.hass, bad_conf, self.add_entities, None)

        assert no_sub_setup is None
        assert 0 == len(self.DEVICES)
    def test_invalid_sensors(self, mock):
        """Test the VultrSensor fails."""
        mock.get(
            'https://api.vultr.com/v1/account/info?api_key=ABCDEFG1234567',
            text=load_fixture('vultr_account_info.json'))

        mock.get(
            'https://api.vultr.com/v1/server/list?api_key=ABCDEFG1234567',
            text=load_fixture('vultr_server_list.json'))

        base_vultr.setup(self.hass, VALID_CONFIG)

        bad_conf = {
            CONF_MONITORED_CONDITIONS: vultr.MONITORED_CONDITIONS,
        }  # No subs at all

        no_sub_setup = vultr.setup_platform(self.hass,
                                            bad_conf,
                                            self.add_devices,
                                            None)

        self.assertIsNotNone(no_sub_setup)
        self.assertEqual(0, len(self.DEVICES))
Exemple #5
0
    def test_sensor(self, mock):
        """Test the Vultr sensor class and methods."""
        mock.get(
            'https://api.vultr.com/v1/account/info?api_key=ABCDEFG1234567',
            text=load_fixture('vultr_account_info.json'))

        mock.get('https://api.vultr.com/v1/server/list?api_key=ABCDEFG1234567',
                 text=load_fixture('vultr_server_list.json'))

        base_vultr.setup(self.hass, VALID_CONFIG)

        for config in self.configs:
            setup = vultr.setup_platform(self.hass, config, self.add_devices,
                                         None)

            self.assertIsNone(setup)

        self.assertEqual(5, len(self.DEVICES))

        tested = 0

        for device in self.DEVICES:

            # Test pre update
            if device.subscription == '576965':
                self.assertEqual(vultr.DEFAULT_NAME, device.name)

            device.update()

            if device.unit_of_measurement == 'GB':  # Test Bandwidth Used
                if device.subscription == '576965':
                    self.assertEqual(
                        'Vultr my new server Current Bandwidth Used',
                        device.name)
                    self.assertEqual('mdi:chart-histogram', device.icon)
                    self.assertEqual(131.51, device.state)
                    self.assertEqual('mdi:chart-histogram', device.icon)
                    tested += 1

                elif device.subscription == '123456':
                    self.assertEqual('Server Current Bandwidth Used',
                                     device.name)
                    self.assertEqual(957.46, device.state)
                    tested += 1

            elif device.unit_of_measurement == 'US$':  # Test Pending Charges

                if device.subscription == '576965':  # Default 'Vultr {} {}'
                    self.assertEqual('Vultr my new server Pending Charges',
                                     device.name)
                    self.assertEqual('mdi:currency-usd', device.icon)
                    self.assertEqual(46.67, device.state)
                    self.assertEqual('mdi:currency-usd', device.icon)
                    tested += 1

                elif device.subscription == '123456':  # Custom name with 1 {}
                    self.assertEqual('Server Pending Charges', device.name)
                    self.assertEqual('not a number', device.state)
                    tested += 1

                elif device.subscription == '555555':  # No {} in name
                    self.assertEqual('VPS Charges', device.name)
                    self.assertEqual(5.45, device.state)
                    tested += 1

        self.assertEqual(tested, 5)
    def test_sensor(self, mock):
        """Test the Vultr sensor class and methods."""
        mock.get(
            'https://api.vultr.com/v1/account/info?api_key=ABCDEFG1234567',
            text=load_fixture('vultr_account_info.json'))

        mock.get(
            'https://api.vultr.com/v1/server/list?api_key=ABCDEFG1234567',
            text=load_fixture('vultr_server_list.json'))

        base_vultr.setup(self.hass, VALID_CONFIG)

        for config in self.configs:
            setup = vultr.setup_platform(self.hass,
                                         config,
                                         self.add_devices,
                                         None)

            self.assertIsNone(setup)

        self.assertEqual(5, len(self.DEVICES))

        tested = 0

        for device in self.DEVICES:

            # Test pre update
            if device.subscription == '576965':
                self.assertEqual(vultr.DEFAULT_NAME, device.name)

            device.update()

            if device.unit_of_measurement == 'GB':  # Test Bandwidth Used
                if device.subscription == '576965':
                    self.assertEqual(
                        'Vultr my new server Current Bandwidth Used',
                        device.name)
                    self.assertEqual('mdi:chart-histogram', device.icon)
                    self.assertEqual(131.51, device.state)
                    self.assertEqual('mdi:chart-histogram', device.icon)
                    tested += 1

                elif device.subscription == '123456':
                    self.assertEqual('Server Current Bandwidth Used',
                                     device.name)
                    self.assertEqual(957.46, device.state)
                    tested += 1

            elif device.unit_of_measurement == 'US$':  # Test Pending Charges

                if device.subscription == '576965':  # Default 'Vultr {} {}'
                    self.assertEqual('Vultr my new server Pending Charges',
                                     device.name)
                    self.assertEqual('mdi:currency-usd', device.icon)
                    self.assertEqual(46.67, device.state)
                    self.assertEqual('mdi:currency-usd', device.icon)
                    tested += 1

                elif device.subscription == '123456':  # Custom name with 1 {}
                    self.assertEqual('Server Pending Charges', device.name)
                    self.assertEqual('not a number', device.state)
                    tested += 1

                elif device.subscription == '555555':  # No {} in name
                    self.assertEqual('VPS Charges', device.name)
                    self.assertEqual(5.45, device.state)
                    tested += 1

        self.assertEqual(tested, 5)
Exemple #7
0
    def test_sensor(self, mock):
        """Test the Vultr sensor class and methods."""
        mock.get(
            'https://api.vultr.com/v1/account/info?api_key=ABCDEFG1234567',
            text=load_fixture('vultr_account_info.json'))

        with patch(
            'vultr.Vultr.server_list',
            return_value=json.loads(
                load_fixture('vultr_server_list.json'))):
            # Setup hub
            base_vultr.setup(self.hass, VALID_CONFIG)

        for config in self.configs:
            setup = vultr.setup_platform(
                self.hass, config, self.add_entities, None)

            assert setup is None

        assert 5 == len(self.DEVICES)

        tested = 0

        for device in self.DEVICES:

            # Test pre update
            if device.subscription == '576965':
                assert vultr.DEFAULT_NAME == device.name

            device.update()

            if device.unit_of_measurement == 'GB':  # Test Bandwidth Used
                if device.subscription == '576965':
                    assert 'Vultr my new server Current Bandwidth Used' == \
                        device.name
                    assert 'mdi:chart-histogram' == device.icon
                    assert 131.51 == device.state
                    assert 'mdi:chart-histogram' == device.icon
                    tested += 1

                elif device.subscription == '123456':
                    assert 'Server Current Bandwidth Used' == \
                        device.name
                    assert 957.46 == device.state
                    tested += 1

            elif device.unit_of_measurement == 'US$':  # Test Pending Charges

                if device.subscription == '576965':  # Default 'Vultr {} {}'
                    assert 'Vultr my new server Pending Charges' == \
                        device.name
                    assert 'mdi:currency-usd' == device.icon
                    assert 46.67 == device.state
                    assert 'mdi:currency-usd' == device.icon
                    tested += 1

                elif device.subscription == '123456':  # Custom name with 1 {}
                    assert 'Server Pending Charges' == device.name
                    assert 'not a number' == device.state
                    tested += 1

                elif device.subscription == '555555':  # No {} in name
                    assert 'VPS Charges' == device.name
                    assert 5.45 == device.state
                    tested += 1

        assert tested == 5
    def test_sensor(self, mock):
        """Test the Vultr sensor class and methods."""
        mock.get(
            'https://api.vultr.com/v1/account/info?api_key=ABCDEFG1234567',
            text=load_fixture('vultr_account_info.json'))

        with patch('vultr.Vultr.server_list',
                   return_value=json.loads(
                       load_fixture('vultr_server_list.json'))):
            # Setup hub
            base_vultr.setup(self.hass, VALID_CONFIG)

        for config in self.configs:
            setup = vultr.setup_platform(self.hass, config, self.add_entities,
                                         None)

            assert setup is None

        assert 5 == len(self.DEVICES)

        tested = 0

        for device in self.DEVICES:

            # Test pre update
            if device.subscription == '576965':
                assert vultr.DEFAULT_NAME == device.name

            device.update()

            if device.unit_of_measurement == 'GB':  # Test Bandwidth Used
                if device.subscription == '576965':
                    assert 'Vultr my new server Current Bandwidth Used' == \
                        device.name
                    assert 'mdi:chart-histogram' == device.icon
                    assert 131.51 == device.state
                    assert 'mdi:chart-histogram' == device.icon
                    tested += 1

                elif device.subscription == '123456':
                    assert 'Server Current Bandwidth Used' == \
                        device.name
                    assert 957.46 == device.state
                    tested += 1

            elif device.unit_of_measurement == 'US$':  # Test Pending Charges

                if device.subscription == '576965':  # Default 'Vultr {} {}'
                    assert 'Vultr my new server Pending Charges' == \
                        device.name
                    assert 'mdi:currency-usd' == device.icon
                    assert 46.67 == device.state
                    assert 'mdi:currency-usd' == device.icon
                    tested += 1

                elif device.subscription == '123456':  # Custom name with 1 {}
                    assert 'Server Pending Charges' == device.name
                    assert 'not a number' == device.state
                    tested += 1

                elif device.subscription == '555555':  # No {} in name
                    assert 'VPS Charges' == device.name
                    assert 5.45 == device.state
                    tested += 1

        assert tested == 5