Ejemplo n.º 1
0
    def test_validate_edit(self, dao_find, template_id_exists, plugin_exists,
                           mac_exists):
        device_found = Mock(Device)
        device_found.mac = '00:11:22:33:44:54'

        dao_find.return_value = device_found
        template_id_exists.return_value = True
        plugin_exists.return_value = True
        mac_exists.return_value = False

        device_id = '123abc'

        device = {
            'id': device_id,
            'mac': '00:11:22:33:44:55',
            'ip': '10.0.0.1',
            'template_id': 'defaultconfigdevice',
            'plugin': 'null',
        }

        device = Device(**device)

        validator.validate_edit(device)

        dao_find.assert_called_once_with(device_id)
        template_id_exists.assert_called_once_with(device.template_id)
        plugin_exists.assert_called_once_with(device.plugin)
        mac_exists.assert_called_once_with(device.mac)
Ejemplo n.º 2
0
    def test_validate_edit(self, dao_find, template_id_exists, plugin_exists, mac_exists):
        device_found = Mock(Device)
        device_found.mac = '00:11:22:33:44:54'

        dao_find.return_value = device_found
        template_id_exists.return_value = True
        plugin_exists.return_value = True
        mac_exists.return_value = False

        device_id = '123abc'

        device = {
            'id': device_id,
            'mac': '00:11:22:33:44:55',
            'ip': '10.0.0.1',
            'template_id': 'defaultconfigdevice',
            'plugin': 'null',
        }

        device = Device(**device)

        validator.validate_edit(device)

        dao_find.assert_called_once_with(device_id)
        template_id_exists.assert_called_once_with(device.template_id)
        plugin_exists.assert_called_once_with(device.plugin)
        mac_exists.assert_called_once_with(device.mac)
Ejemplo n.º 3
0
    def test_validate_edited_device_has_no_mac(self, dao_find, mac_exists):
        mac_found = '00:11:22:33:44:56'
        device_id = '123abc'

        device_found = Mock(Device)
        device_found.mac = mac_found
        dao_find.return_value = device_found

        device = {
            'id': device_id,
        }

        device = Device(**device)

        validator.validate_edit(device)

        dao_find.assert_called_once_with(device_id)
        assert_that(mac_exists.call_count, equal_to(0))
Ejemplo n.º 4
0
    def test_validate_edited_device_has_no_mac(self, dao_find, mac_exists):
        mac_found = '00:11:22:33:44:56'
        device_id = '123abc'

        device_found = Mock(Device)
        device_found.mac = mac_found
        dao_find.return_value = device_found

        device = {
            'id': device_id,
        }

        device = Device(**device)

        validator.validate_edit(device)

        dao_find.assert_called_once_with(device_id)
        assert_that(mac_exists.call_count, equal_to(0))
Ejemplo n.º 5
0
    def test_validate_different_mac(self, dao_find, mac_exists):
        mac_found = '00:11:22:33:44:55'
        new_mac = '00:11:22:33:44:56'
        device_id = '123abc'

        device_found = Mock(Device)
        device_found.mac = mac_found

        dao_find.return_value = device_found
        mac_exists.return_value = False

        device = {
            'id': device_id,
            'mac': new_mac,
        }

        device = Device(**device)

        validator.validate_edit(device)

        dao_find.assert_called_once_with(device_id)
        mac_exists.assert_called_once_with(new_mac)
Ejemplo n.º 6
0
    def test_validate_different_mac(self, dao_find, mac_exists):
        mac_found = '00:11:22:33:44:55'
        new_mac = '00:11:22:33:44:56'
        device_id = '123abc'

        device_found = Mock(Device)
        device_found.mac = mac_found

        dao_find.return_value = device_found
        mac_exists.return_value = False

        device = {
            'id': device_id,
            'mac': new_mac,
        }

        device = Device(**device)

        validator.validate_edit(device)

        dao_find.assert_called_once_with(device_id)
        mac_exists.assert_called_once_with(new_mac)