示例#1
0
    def test_update_sku_from_dict(self):
        sku_tests = {"test_empty": ([""], {}),
                     "test_all": (["sku"], {"os": "sku", 1: "sku", 3: "sku"}),
                     "test_os": (["os=sku"], {"os": "sku"}),
                     "test_lun": (["1=sku"], {1: "sku"}),
                     "test_os_lun": (["os=sku", "1=sku_1"], {"os": "sku", 1: "sku_1"}),
                     "test_os_mult_lun": (["1=sku_1", "os=sku_os", "2=sku_2"],
                                          {1: "sku_1", "os": "sku_os", 2: "sku_2"}),
                     "test_double_equ": (["os==foo"], {"os": "=foo"}),
                     "test_err_no_eq": (["os=sku_1", "foo"], None),
                     "test_err_lone_eq": (["foo ="], None),
                     "test_err_float": (["2.7=foo"], None),
                     "test_err_bad_key": (["bad=foo"], None)}

        for test_sku, expected in sku_tests.values():
            if isinstance(expected, dict):
                # build info dict from expected values.
                info_dict = {lun: dict(managedDisk={'storageAccountType': None}) for lun in expected if lun != "os"}
                if "os" in expected:
                    info_dict["os"] = {}

                update_disk_sku_info(info_dict, test_sku)
                for lun in info_dict:
                    if lun == "os":
                        self.assertEqual(info_dict[lun]['storageAccountType'], expected[lun])
                    else:
                        self.assertEqual(info_dict[lun]['managedDisk']['storageAccountType'], expected[lun])
            elif expected is None:
                dummy_expected = ["os", 1, 2]
                info_dict = {lun: dict(managedDisk={'storageAccountType': None}) for lun in dummy_expected if lun != "os"}
                if "os" in dummy_expected:
                    info_dict["os"] = {}

                with self.assertRaises(CLIError):
                    update_disk_sku_info(info_dict, dummy_expected)
            else:
                self.fail("Test Expected value should be a dict or None, instead it is {}.".format(expected))
示例#2
0
    def test_update_sku_from_dict(self):
        sku_tests = {"test_empty": ([""], {}),
                     "test_all": (["sku"], {"os": "sku", 1: "sku", 3: "sku"}),
                     "test_os": (["os=sku"], {"os": "sku"}),
                     "test_lun": (["1=sku"], {1: "sku"}),
                     "test_os_lun": (["os=sku", "1=sku_1"], {"os": "sku", 1: "sku_1"}),
                     "test_os_mult_lun": (["1=sku_1", "os=sku_os", "2=sku_2"],
                                          {1: "sku_1", "os": "sku_os", 2: "sku_2"}),
                     "test_double_equ": (["os==foo"], {"os": "=foo"}),
                     "test_err_no_eq": (["os=sku_1", "foo"], None),
                     "test_err_lone_eq": (["foo ="], None),
                     "test_err_float": (["2.7=foo"], None),
                     "test_err_bad_key": (["bad=foo"], None)}

        for test_sku, expected in sku_tests.values():
            if isinstance(expected, dict):
                # build info dict from expected values.
                info_dict = {lun: dict(managedDisk={'storageAccountType': None}) for lun in expected if lun != "os"}
                if "os" in expected:
                    info_dict["os"] = {}

                update_disk_sku_info(info_dict, test_sku)
                for lun in info_dict:
                    if lun == "os":
                        self.assertEqual(info_dict[lun]['storageAccountType'], expected[lun])
                    else:
                        self.assertEqual(info_dict[lun]['managedDisk']['storageAccountType'], expected[lun])
            elif expected is None:
                dummy_expected = ["os", 1, 2]
                info_dict = {lun: dict(managedDisk={'storageAccountType': None}) for lun in dummy_expected if lun != "os"}
                if "os" in dummy_expected:
                    info_dict["os"] = {}

                with self.assertRaises(CLIError):
                    update_disk_sku_info(info_dict, dummy_expected)
            else:
                self.fail("Test Expected value should be a dict or None, instead it is {}.".format(expected))