Beispiel #1
0
    def test_apply_model_only_combobox(self):
        invalid_types = [1, "One", u'1', {'1': "one"}, VMListModeler(
            mock_domains_info)]

        for invalid_type in invalid_types:
            with self.assertRaises(TypeError):
                self.apply_model(invalid_type, [])
Beispiel #2
0
 def _new_vm_list_modeler(self):
     return VMListModeler(mock_domains_info)
Beispiel #3
0
 def setUp(self):
     self.modeler = VMListModeler(mock_domains_info)
Beispiel #4
0
class VMListModelerTest(unittest.TestCase):
    def setUp(self):
        self.modeler = VMListModeler(mock_domains_info)

    def test_entries_gets_loaded(self):
        self.assertIsNotNone(self.modeler._entries)

    def test_valid_qube_name(self):
        self.modeler.apply_model(Gtk.ComboBox(),
                                 list(mock_domains_info.keys()))

        for name in [
                "test-red1",
                "test-red2",
                "test-red3",
                "test-target",
                "Disposable VM (test-disp6)",
        ]:

            mock = MockComboEntry(name)
            self.assertEqual(
                name,
                self.modeler._get_valid_qube_name(mock, mock, mock_whitelist),
            )
            self.assertEqual(
                name,
                self.modeler._get_valid_qube_name(None, mock, mock_whitelist),
            )
            self.assertEqual(
                name,
                self.modeler._get_valid_qube_name(mock, None, mock_whitelist),
            )
            self.assertIsNone(
                self.modeler._get_valid_qube_name(None, None, mock_whitelist))

    def test_valid_qube_name_whitelist(self):
        list_exc = ["@dispvm:test-disp6", "test-red2"]

        whitelist = [name for name in mock_whitelist if name not in list_exc]
        self.modeler.apply_model(Gtk.ComboBox(), whitelist)

        for name in list_exc:
            mock = MockComboEntry(name)
            self.assertIsNone(
                self.modeler._get_valid_qube_name(mock, mock, whitelist))
            self.assertIsNone(
                self.modeler._get_valid_qube_name(None, mock, whitelist))
            self.assertIsNone(
                self.modeler._get_valid_qube_name(mock, None, whitelist))

    def test_invalid_qube_name(self):
        self.modeler.apply_model(Gtk.ComboBox(), mock_whitelist)

        for name in ["test-nonexistant", None, "", 1]:

            mock = MockComboEntry(name)
            self.assertIsNone(
                self.modeler._get_valid_qube_name(mock, mock, mock_whitelist))
            self.assertIsNone(
                self.modeler._get_valid_qube_name(None, mock, mock_whitelist))
            self.assertIsNone(
                self.modeler._get_valid_qube_name(mock, None, mock_whitelist))

    def test_apply_model(self):
        new_object = Gtk.ComboBox()
        self.assertIsNone(new_object.get_model())

        self.modeler.apply_model(new_object, mock_whitelist)

        self.assertIsNotNone(new_object.get_model())

    def test_apply_model_with_entry(self):
        new_object = Gtk.ComboBox.new_with_entry()

        self.assertIsNone(new_object.get_model())

        self.modeler.apply_model(new_object, [])

        self.assertIsNotNone(new_object.get_model())

    def test_apply_model_only_combobox(self):
        invalid_types = [
            1,
            "One",
            "1",
            {
                "1": "one"
            },
            VMListModeler(mock_domains_info),
        ]

        for invalid_type in invalid_types:
            with self.assertRaises(TypeError):
                self.modeler.apply_model(invalid_type, [])

    def test_apply_model_whitelist(self):
        combo = Gtk.ComboBox()

        self.modeler.apply_model(combo, list(mock_domains_info.keys()))
        self.assertEqual(7, len(combo.get_model()))

        names = [entry["api_name"] for entry in self.modeler._entries.values()]

        self.modeler.apply_model(combo, [names[0]])
        self.assertEqual(1, len(combo.get_model()))

        self.modeler.apply_model(combo, [names[0], names[1]])
        self.assertEqual(2, len(combo.get_model()))

    def test_apply_icon(self):
        new_object = Gtk.Entry()

        self.assertIsNone(
            new_object.get_icon_pixbuf(Gtk.EntryIconPosition.PRIMARY))

        self.modeler.apply_icon(new_object, "Disposable VM (test-disp6)")

        self.assertIsNotNone(
            new_object.get_icon_pixbuf(Gtk.EntryIconPosition.PRIMARY))

    def test_apply_icon_only_entry(self):
        invalid_types = [1, "One", "1", {"1": "one"}, Gtk.ComboBox()]

        for invalid_type in invalid_types:
            with self.assertRaises(TypeError):
                self.modeler.apply_icon(invalid_type, "test-disp6")

    def test_apply_icon_only_existing(self):
        new_object = Gtk.Entry()

        for name in [
                "test-red1",
                "test-red2",
                "test-red3",
                "test-target",
                "Disposable VM (test-disp6)",
        ]:
            self.modeler.apply_icon(new_object, name)

        for name in ["test-nonexistant", None, "", 1]:
            with self.assertRaises(ValueError):
                self.modeler.apply_icon(new_object, name)
Beispiel #5
0
 def __init__(self, *args, **kwargs):
     unittest.TestCase.__init__(self, *args, **kwargs)
     VMListModeler.__init__(self, mock_domains_info)