Esempio n. 1
0
    def test_api_info_minimal(self):
        filename, callfile = write_script(self.dirname,
                                          output=self.API_INFO_YAML)
        self.cli = CLI.from_version(filename, self.VERSION, self.dirname)
        infos = self.cli.api_info()

        self.assertEquals(
            infos, {
                None:
                APIInfo(
                    ["10.235.227.251:17070"],
                    "admin",
                    "0f154812dd1c02973623c887b2565ea3",
                ),
                "controller":
                APIInfo(
                    ["10.235.227.251:17070"],
                    "admin",
                    "0f154812dd1c02973623c887b2565ea3",
                    "d3a5befc-c392-4722-85fc-631531e74a09",
                ),
                "default":
                APIInfo(
                    ["10.235.227.251:17070"],
                    "admin",
                    "0f154812dd1c02973623c887b2565ea3",
                    "b93f17f2-ad56-456d-8051-06e9f7ba46ec",
                ),
            })
        self.assert_called("show-controller --show-password --format=yaml",
                           callfile)
Esempio n. 2
0
 def test_missing_password(self):
     """
     APIInfo() fails if password is None or empty.
     """
     with self.assertRaises(ValueError):
         APIInfo(["host"], "admin", None)
     with self.assertRaises(ValueError):
         APIInfo(["host"], "admin", "")
Esempio n. 3
0
 def test_missing_user(self):
     """
     APIInfo() fails if user is None or empty.
     """
     with self.assertRaises(ValueError):
         APIInfo(["host"], None, "pw")
     with self.assertRaises(ValueError):
         APIInfo(["host"], "", "pw")
Esempio n. 4
0
 def test_missing_endpoints(self):
     """
     APIInfo() fails if endpoints is None or empty.
     """
     with self.assertRaises(ValueError):
         APIInfo(None, "admin", "pw")
     with self.assertRaises(ValueError):
         APIInfo([], "admin", "pw")
Esempio n. 5
0
    def test_api_info_minimal(self):
        self.version_cli.return_get_api_info_args = ["sub"]
        self.exe.return_run_out = "<output>"
        expected = APIInfo(["host"], "admin", "pw")
        self.version_cli.return_parse_api_info = {"spam": expected._asdict()}
        cli = CLI(self.exe, self.version_cli)
        info = cli.api_info()

        self.assertEqual(info, {"spam": expected})
        self.assertEqual(self.calls, [
            ("get_api_info_args", (None, ), {}),
            ("run_out", ("sub", ), {}),
            ("parse_api_info", ("<output>", None), {}),
        ])
Esempio n. 6
0
    def test_address(self):
        """
        APIInfo.address holds the first endpoint.
        """
        info = APIInfo(["host2", "host1"], "admin", "pw")

        self.assertEqual(info.address, "host2")
Esempio n. 7
0
    def test_conversion(self):
        """
        APIInfo() converts the args to unicode.
        """
        endpoints = ["host2", "host1"]
        info = APIInfo(endpoints, "admin", "pw", "some-uuid")

        self.assertEqual(info.endpoints, (u"host2", u"host1"))
        self.assertEqual(info.user, u"admin")
        self.assertEqual(info.password, u"pw")
        self.assertEqual(info.model_uuid, u"some-uuid")
Esempio n. 8
0
    def test_minimal(self):
        """
        APIInfo() works with minimal args.
        """
        endpoints = (u"host", )
        info = APIInfo(endpoints, u"admin", u"pw")

        self.assertEqual(info.endpoints, (u"host", ))
        self.assertEqual(info.user, u"admin")
        self.assertEqual(info.password, u"pw")
        self.assertIsNone(info.model_uuid)
Esempio n. 9
0
    def test_full(self):
        """
        APIInfo() works with all args provided.
        """
        endpoints = (u"host2", u"host1")
        info = APIInfo(endpoints, u"admin", u"pw", u"some-uuid")

        self.assertEqual(info.endpoints, (u"host2", u"host1"))
        self.assertEqual(info.user, u"admin")
        self.assertEqual(info.password, u"pw")
        self.assertEqual(info.model_uuid, u"some-uuid")
Esempio n. 10
0
    def test_api_info_minimal(self):
        filename, callfile = write_script(self.dirname,
                                          output=self.API_INFO_JSON)
        self.cli = CLI.from_version(filename, self.VERSION, self.dirname)
        infos = self.cli.api_info()

        self.assertEquals(
            infos, {
                None:
                APIInfo(
                    ["10.235.227.251:17070"],
                    "admin",
                    "0f154812dd1c02973623c887b2565ea3",
                ),
                "controller":
                APIInfo(
                    ["10.235.227.251:17070"],
                    "admin",
                    "0f154812dd1c02973623c887b2565ea3",
                    "d3a5befc-c392-4722-85fc-631531e74a09",
                ),
            })
        self.assert_called("api-info --password --refresh --format=json",
                           callfile)