コード例 #1
0
    def test_invalid_switches(self, mock):
        """Test the VultrSwitch 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 = {}  # No subscription

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

        self.assertIsNotNone(no_subs_setup)

        bad_conf = {
            CONF_NAME: "Missing Server",
            CONF_SUBSCRIPTION: '665544'
        }  # Sub not associated with API key (not in server_list)

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

        self.assertIsNotNone(wrong_subs_setup)
コード例 #2
0
ファイル: test_vultr.py プロジェクト: oliverbl4/Anassistant
    def test_invalid_sensors(self, mock):
        """Test the VultrBinarySensor 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 = {}  # No subscription

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

        self.assertFalse(no_subs_setup)

        bad_conf = {
            CONF_NAME: "Missing Server",
            CONF_SUBSCRIPTION: '555555'
        }  # Sub not associated with API key (not in server_list)

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

        self.assertFalse(wrong_subs_setup)
コード例 #3
0
    def test_invalid_switches(self, mock):
        """Test the VultrSwitch 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 = {}  # No subscription

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

        self.assertIsNotNone(no_subs_setup)

        bad_conf = {
            CONF_NAME: "Missing Server",
            CONF_SUBSCRIPTION: '665544'
        }  # Sub not associated with API key (not in server_list)

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

        self.assertIsNotNone(wrong_subs_setup)
コード例 #4
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("account_info.json", "vultr"),
        )

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

        bad_conf = {
            CONF_NAME: "Vultr {} {}",
            CONF_SUBSCRIPTION: "",
            CONF_MONITORED_CONDITIONS: vultr.SENSOR_KEYS,
        }  # 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 len(self.DEVICES) == 0
コード例 #5
0
    def test_invalid_sensors(self, mock):
        """Test the VultrBinarySensor fails."""
        mock.get(
            "https://api.vultr.com/v1/account/info?api_key=ABCDEFG1234567",
            text=load_fixture("account_info.json", "vultr"),
        )

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

        bad_conf = {}  # No subscription

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

        assert not no_subs_setup

        bad_conf = {
            CONF_NAME: "Missing Server",
            CONF_SUBSCRIPTION: "555555",
        }  # Sub not associated with API key (not in server_list)

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

        assert not wrong_subs_setup
コード例 #6
0
    def test_invalid_sensors(self, mock):
        """Test the VultrBinarySensor 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 = {}  # No subscription

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

        self.assertFalse(no_subs_setup)

        bad_conf = {
            CONF_NAME: "Missing Server",
            CONF_SUBSCRIPTION: '555555'
        }  # Sub not associated with API key (not in server_list)

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

        self.assertFalse(wrong_subs_setup)
コード例 #7
0
    def test_switch(self, mock):
        """Test successful instance."""
        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)

        # Setup each of our test configs
        for config in self.configs:
            vultr.setup_platform(self.hass, config, self.add_entities, None)

        assert len(self.DEVICES) == 3

        tested = 0

        for device in self.DEVICES:
            if device.subscription == "555555":
                assert device.name == "Vultr {}"
                tested += 1

            device.update()
            device_attrs = device.extra_state_attributes

            if device.subscription == "555555":
                assert device.name == "Vultr Another Server"
                tested += 1

            if device.name == "A Server":
                assert device.is_on is True
                assert device.state == "on"
                assert device.icon == "mdi:server"
                assert device_attrs[ATTR_ALLOWED_BANDWIDTH] == "1000"
                assert device_attrs[ATTR_AUTO_BACKUPS] == "yes"
                assert device_attrs[ATTR_IPV4_ADDRESS] == "123.123.123.123"
                assert device_attrs[ATTR_COST_PER_MONTH] == "10.05"
                assert device_attrs[ATTR_CREATED_AT] == "2013-12-19 14:45:41"
                assert device_attrs[ATTR_SUBSCRIPTION_ID] == "576965"
                tested += 1

            elif device.name == "Failed Server":
                assert device.is_on is False
                assert device.state == "off"
                assert device.icon == "mdi:server-off"
                assert device_attrs[ATTR_ALLOWED_BANDWIDTH] == "1000"
                assert device_attrs[ATTR_AUTO_BACKUPS] == "no"
                assert device_attrs[ATTR_IPV4_ADDRESS] == "192.168.100.50"
                assert device_attrs[ATTR_COST_PER_MONTH] == "73.25"
                assert device_attrs[ATTR_CREATED_AT] == "2014-10-13 14:45:41"
                assert device_attrs[ATTR_SUBSCRIPTION_ID] == "123456"
                tested += 1

        assert tested == 4
コード例 #8
0
ファイル: test_vultr.py プロジェクト: zzhmy/home-assistant
    def test_binary_sensor(self, mock):
        """Test successful instance."""
        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)

        # Setup each of our test configs
        for config in self.configs:
            vultr.setup_platform(self.hass, config, self.add_devices, None)

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

        for device in self.DEVICES:

            # Test pre data retieval
            if device.subscription == '555555':
                self.assertEqual('Vultr {}', device.name)

            device.update()
            device_attrs = device.device_state_attributes

            if device.subscription == '555555':
                self.assertEqual('Vultr Another Server', device.name)

            if device.name == 'A Server':
                self.assertEqual(True, device.is_on)
                self.assertEqual('power', device.device_class)
                self.assertEqual('on', device.state)
                self.assertEqual('mdi:server', device.icon)
                self.assertEqual('1000', device_attrs[ATTR_ALLOWED_BANDWIDTH])
                self.assertEqual('yes', device_attrs[ATTR_AUTO_BACKUPS])
                self.assertEqual('123.123.123.123',
                                 device_attrs[ATTR_IPV4_ADDRESS])
                self.assertEqual('10.05', device_attrs[ATTR_COST_PER_MONTH])
                self.assertEqual('2013-12-19 14:45:41',
                                 device_attrs[ATTR_CREATED_AT])
                self.assertEqual('576965', device_attrs[ATTR_SUBSCRIPTION_ID])
            elif device.name == 'Failed Server':
                self.assertEqual(False, device.is_on)
                self.assertEqual('off', device.state)
                self.assertEqual('mdi:server-off', device.icon)
                self.assertEqual('1000', device_attrs[ATTR_ALLOWED_BANDWIDTH])
                self.assertEqual('no', device_attrs[ATTR_AUTO_BACKUPS])
                self.assertEqual('192.168.100.50',
                                 device_attrs[ATTR_IPV4_ADDRESS])
                self.assertEqual('73.25', device_attrs[ATTR_COST_PER_MONTH])
                self.assertEqual('2014-10-13 14:45:41',
                                 device_attrs[ATTR_CREATED_AT])
                self.assertEqual('123456', device_attrs[ATTR_SUBSCRIPTION_ID])
コード例 #9
0
def valid_config(hass: HomeAssistant, requests_mock):
    """Load a valid config."""
    requests_mock.get(
        "https://api.vultr.com/v1/account/info?api_key=ABCDEFG1234567",
        text=load_fixture("account_info.json", "vultr"),
    )

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

    yield
コード例 #10
0
ファイル: test_init.py プロジェクト: MoshonkaKita/Golovastik
 def test_setup(self, mock):
     """Test successful setup."""
     with patch('vultr.Vultr.server_list',
                return_value=json.loads(
                    load_fixture('vultr_server_list.json'))):
         response = vultr.setup(self.hass, self.config)
     assert response
コード例 #11
0
ファイル: test_init.py プロジェクト: ManHammer/home-assistant
 def test_setup(self, mock):
     """Test successful setup."""
     with patch(
         'vultr.Vultr.server_list',
         return_value=json.loads(
             load_fixture('vultr_server_list.json'))):
         response = vultr.setup(self.hass, self.config)
     assert response
コード例 #12
0
ファイル: test_init.py プロジェクト: rikroe/core
def test_setup(hass: HomeAssistant):
    """Test successful setup."""
    with patch(
            "vultr.Vultr.server_list",
            return_value=json.loads(load_fixture("server_list.json", "vultr")),
    ):
        response = vultr.setup(hass, VALID_CONFIG)
    assert response
コード例 #13
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))
コード例 #14
0
ファイル: test_vultr.py プロジェクト: oliverbl4/Anassistant
    def test_setup(self, mock):
        """Test successful setup."""
        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'))

        response = vultr.setup(self.hass, self.config)
        self.assertTrue(response)
コード例 #15
0
ファイル: test_vultr.py プロジェクト: MoshonkaKita/Golovastik
    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)
コード例 #16
0
ファイル: test_vultr.py プロジェクト: arsaboo/home-assistant
    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)
コード例 #17
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))
コード例 #18
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)
コード例 #19
0
    def test_binary_sensor(self, mock):
        """Test successful instance."""
        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)

        # Setup each of our test configs
        for config in self.configs:
            vultr.setup_platform(self.hass,
                                 config,
                                 self.add_entities,
                                 None)

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

        for device in self.DEVICES:

            # Test pre data retrieval
            if device.subscription == '555555':
                self.assertEqual('Vultr {}', device.name)

            device.update()
            device_attrs = device.device_state_attributes

            if device.subscription == '555555':
                self.assertEqual('Vultr Another Server', device.name)

            if device.name == 'A Server':
                self.assertEqual(True, device.is_on)
                self.assertEqual('power', device.device_class)
                self.assertEqual('on', device.state)
                self.assertEqual('mdi:server', device.icon)
                self.assertEqual('1000',
                                 device_attrs[ATTR_ALLOWED_BANDWIDTH])
                self.assertEqual('yes',
                                 device_attrs[ATTR_AUTO_BACKUPS])
                self.assertEqual('123.123.123.123',
                                 device_attrs[ATTR_IPV4_ADDRESS])
                self.assertEqual('10.05',
                                 device_attrs[ATTR_COST_PER_MONTH])
                self.assertEqual('2013-12-19 14:45:41',
                                 device_attrs[ATTR_CREATED_AT])
                self.assertEqual('576965',
                                 device_attrs[ATTR_SUBSCRIPTION_ID])
            elif device.name == 'Failed Server':
                self.assertEqual(False, device.is_on)
                self.assertEqual('off', device.state)
                self.assertEqual('mdi:server-off', device.icon)
                self.assertEqual('1000',
                                 device_attrs[ATTR_ALLOWED_BANDWIDTH])
                self.assertEqual('no',
                                 device_attrs[ATTR_AUTO_BACKUPS])
                self.assertEqual('192.168.100.50',
                                 device_attrs[ATTR_IPV4_ADDRESS])
                self.assertEqual('73.25',
                                 device_attrs[ATTR_COST_PER_MONTH])
                self.assertEqual('2014-10-13 14:45:41',
                                 device_attrs[ATTR_CREATED_AT])
                self.assertEqual('123456',
                                 device_attrs[ATTR_SUBSCRIPTION_ID])
コード例 #20
0
ファイル: test_vultr.py プロジェクト: MoshonkaKita/Golovastik
    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
コード例 #21
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)
コード例 #22
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 len(self.DEVICES) == 5

        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 == DATA_GIGABYTES:  # Test Bandwidth Used
                if device.subscription == "576965":
                    assert device.name == "Vultr my new server Current Bandwidth Used"
                    assert device.icon == "mdi:chart-histogram"
                    assert device.state == 131.51
                    assert device.icon == "mdi:chart-histogram"
                    tested += 1

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

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

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

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

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

        assert tested == 5
コード例 #23
0
ファイル: test_vultr.py プロジェクト: MoshonkaKita/Golovastik
    def test_switch(self, mock):
        """Test successful instance."""
        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)

        # Setup each of our test configs
        for config in self.configs:
            vultr.setup_platform(self.hass, config, self.add_entities, None)

        assert len(self.DEVICES) == 3

        tested = 0

        for device in self.DEVICES:
            if device.subscription == '555555':
                assert 'Vultr {}' == device.name
                tested += 1

            device.update()
            device_attrs = device.device_state_attributes

            if device.subscription == '555555':
                assert 'Vultr Another Server' == device.name
                tested += 1

            if device.name == 'A Server':
                assert device.is_on is True
                assert 'on' == device.state
                assert 'mdi:server' == device.icon
                assert '1000' == \
                    device_attrs[ATTR_ALLOWED_BANDWIDTH]
                assert 'yes' == \
                    device_attrs[ATTR_AUTO_BACKUPS]
                assert '123.123.123.123' == \
                    device_attrs[ATTR_IPV4_ADDRESS]
                assert '10.05' == \
                    device_attrs[ATTR_COST_PER_MONTH]
                assert '2013-12-19 14:45:41' == \
                    device_attrs[ATTR_CREATED_AT]
                assert '576965' == \
                    device_attrs[ATTR_SUBSCRIPTION_ID]
                tested += 1

            elif device.name == 'Failed Server':
                assert device.is_on is False
                assert 'off' == device.state
                assert 'mdi:server-off' == device.icon
                assert '1000' == \
                    device_attrs[ATTR_ALLOWED_BANDWIDTH]
                assert 'no' == \
                    device_attrs[ATTR_AUTO_BACKUPS]
                assert '192.168.100.50' == \
                    device_attrs[ATTR_IPV4_ADDRESS]
                assert '73.25' == \
                    device_attrs[ATTR_COST_PER_MONTH]
                assert '2014-10-13 14:45:41' == \
                    device_attrs[ATTR_CREATED_AT]
                assert '123456' == \
                    device_attrs[ATTR_SUBSCRIPTION_ID]
                tested += 1

        assert 4 == tested
コード例 #24
0
ファイル: test_vultr.py プロジェクト: arsaboo/home-assistant
    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
コード例 #25
0
    def test_switch(self, mock):
        """Test successful instance."""
        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)

        # Setup each of our test configs
        for config in self.configs:
            vultr.setup_platform(self.hass,
                                 config,
                                 self.add_entities,
                                 None)

        assert len(self.DEVICES) == 3

        tested = 0

        for device in self.DEVICES:
            if device.subscription == '555555':
                assert 'Vultr {}' == device.name
                tested += 1

            device.update()
            device_attrs = device.device_state_attributes

            if device.subscription == '555555':
                assert 'Vultr Another Server' == device.name
                tested += 1

            if device.name == 'A Server':
                assert device.is_on is True
                assert 'on' == device.state
                assert 'mdi:server' == device.icon
                assert '1000' == \
                    device_attrs[ATTR_ALLOWED_BANDWIDTH]
                assert 'yes' == \
                    device_attrs[ATTR_AUTO_BACKUPS]
                assert '123.123.123.123' == \
                    device_attrs[ATTR_IPV4_ADDRESS]
                assert '10.05' == \
                    device_attrs[ATTR_COST_PER_MONTH]
                assert '2013-12-19 14:45:41' == \
                    device_attrs[ATTR_CREATED_AT]
                assert '576965' == \
                    device_attrs[ATTR_SUBSCRIPTION_ID]
                tested += 1

            elif device.name == 'Failed Server':
                assert device.is_on is False
                assert 'off' == device.state
                assert 'mdi:server-off' == device.icon
                assert '1000' == \
                    device_attrs[ATTR_ALLOWED_BANDWIDTH]
                assert 'no' == \
                    device_attrs[ATTR_AUTO_BACKUPS]
                assert '192.168.100.50' == \
                    device_attrs[ATTR_IPV4_ADDRESS]
                assert '73.25' == \
                    device_attrs[ATTR_COST_PER_MONTH]
                assert '2014-10-13 14:45:41' == \
                    device_attrs[ATTR_CREATED_AT]
                assert '123456' == \
                    device_attrs[ATTR_SUBSCRIPTION_ID]
                tested += 1

        assert 4 == tested
コード例 #26
0
 def test_failed_hub(self):
     """Test a hub setup failure."""
     base_vultr.setup(self.hass, VALID_CONFIG)
コード例 #27
0
ファイル: test_vultr.py プロジェクト: oliverbl4/Anassistant
 def test_failed_hub(self):
     """Test a hub setup failure."""
     base_vultr.setup(self.hass, VALID_CONFIG)