Esempio n. 1
0
 def test_get_bot_client(self):
     """
     test _get_bot_client
     """
     client_get = patch('js9.j.clients.telegram_bot.get',
                        MagicMock()).start()
     hw = HardwareCheck(name='hw', data=self.valid_data)
     hw._get_bot_client()
     data = {
         'bot_token_': hw.data['botToken'],
     }
     client_get.assert_called_with(instance=hw.guid,
                                   data=data,
                                   create=True,
                                   die=True)
Esempio n. 2
0
    def test_check_fail(self):
        """
        Test that check fails if any of hardware specs arent supported
        """
        patch('js9.j.clients.zos.get', MagicMock()).start()
        hw = HardwareCheck(name='hw', data=self.valid_data)
        supported = self.valid_data['supported'][0]
        hw._disk = MagicMock(return_value=(supported['hddCount'],
                                           supported['ssdCount']))
        hw._cpu = MagicMock(return_value=supported['cpu'])
        client = MagicMock()
        hw._get_bot_client = MagicMock(return_value=client)

        # check with no supported ram
        hw._ram = MagicMock(return_value=supported['ram'] - 6)
        with pytest.raises(
                j.exceptions.RuntimeError,
                message='Template should raise error if ram is not supported'):
            hw.check('node')
        hw._ram = MagicMock(return_value=supported['ram'])

        # check with no supported cpu
        hw._cpu = MagicMock(return_value='othercpu')
        with pytest.raises(
                j.exceptions.RuntimeError,
                message='Template should raise error if cpu is not supported'):
            hw.check('node')
        hw._cpu = MagicMock(return_value=supported['cpu'])

        # check with no supported hdd
        hw._disk = MagicMock(return_value=(0, supported['ssdCount']))
        with pytest.raises(
                j.exceptions.RuntimeError,
                message=
                'Template should raise error if hddCount is not supported'):
            hw.check('node')
        hw._disk = MagicMock(return_value=(supported['hddCount'],
                                           supported['ssdCount']))

        # check with no supported ssd
        hw._disk = MagicMock(return_value=(supported['hddCount'], 0))
        with pytest.raises(
                j.exceptions.RuntimeError,
                message=
                'Template should raise error if ssdCount is not supported'):
            hw.check('node')
Esempio n. 3
0
    def test_check_succussful(self):
        """
        Test check is successful when hardware is supported
        :return:
        """
        patch('js9.j.clients.zos.get', MagicMock()).start()
        hw = HardwareCheck(name='hw', data=self.valid_data)
        supported = self.valid_data['supported'][0]
        hw._disk = MagicMock(return_value=(supported['hddCount'],
                                           supported['ssdCount']))
        hw._ram = MagicMock(return_value=supported['ram'])
        hw._cpu = MagicMock(return_value=supported['cpu'])
        client = MagicMock()
        hw._get_bot_client = MagicMock(return_value=client)
        hw.check('node')

        client.send_message.assert_called_once_with(
            'chatId',
            'Node with id node has completed the hardwarecheck successfully.')