def test_resource_ls(self, mock_colorize, mock_get):
     ShellContext.current_path = Path('/foo')
     mock_get.return_value = {
         "foo": {
             "href": Path("/foo/ec1afeaa-8930-43b0-a60a-939f23a50724"),
             "attr": None,
             "fq_name": [
                 "foo",
                 "ec1afeaa-8930-43b0-a60a-939f23a50724"
             ],
             "bar_refs": [
                 {
                     "href": Path("/bar/ec1afeaa-8930-43b0-a60a-939f23a50724"),
                     "to": [
                         "bar",
                         "ec1afeaa-8930-43b0-a60a-939f23a50724"
                     ]
                 }
             ]
         }
     }
     mock_colorize.side_effect = lambda d: d
     expected_resource = {
         "href": Path("ec1afeaa-8930-43b0-a60a-939f23a50724"),
         "fq_name": "foo:ec1afeaa-8930-43b0-a60a-939f23a50724",
         "bar_refs": [
             {
                 "href": Path("/bar/ec1afeaa-8930-43b0-a60a-939f23a50724"),
                 "to": "bar:ec1afeaa-8930-43b0-a60a-939f23a50724"
             }
         ]
     }
     result = cmds.ls(resource='ec1afeaa-8930-43b0-a60a-939f23a50724')
     self.assertEqual(result, expected_resource)
    def test_fqname_ls(self, mock_colorize, mock_get, mock_fqname_to_id):
        ShellContext.current_path = Path('/foo')
        fq_name = "default-domain:foo:b25f5a6b-292f-4d0c-b5c6-22ad7209abe5"
        expected_path = Path("/foo/b25f5a6b-292f-4d0c-b5c6-22ad7209abe5")

        mock_colorize.side_effect = lambda d: d
        mock_fqname_to_id.return_value = expected_path

        cmds.ls(resource=fq_name)

        mock_fqname_to_id.assert_has_calls([
            mock.call(ShellContext.current_path, fq_name)
        ])
        mock_get.assert_has_calls([
            mock.call(expected_path)
        ])
 def test_resources_ls(self, mock_get):
     ShellContext.current_path = Path("/instance-ip")
     mock_get.return_value = {
         "instance-ips": [
             {"href": Path("/instance-ip/ec1afeaa-8930-43b0-a60a-939f23a50724"),
              "uuid": "ec1afeaa-8930-43b0-a60a-939f23a50724"},
             {"href": Path("/instance-ip/c2588045-d6fb-4f37-9f46-9451f653fb6a"),
              "uuid": "c2588045-d6fb-4f37-9f46-9451f653fb6a"}
         ]
     }
     expected_resources = [
         Path("/instance-ip/ec1afeaa-8930-43b0-a60a-939f23a50724"),
         Path("/instance-ip/c2588045-d6fb-4f37-9f46-9451f653fb6a"),
     ]
     result = cmds.ls()
     self.assertEqual(result, expected_resources)
    def test_home_ls(self, mock_get):
        ShellContext.current_path = Path("/")
        expected_home_resources = [
            Path("/instance-ip"),
        ]

        mock_get.return_value = {
            "href": APIClient.base_url,
            "links": [
                {"link": {"href": Path("/instance-ip"),
                          "name": "instance-ip",
                          "rel": "collection"}},
                {"link": {"href": Path("/instance-ip"),
                          "name": "instance-ip",
                          "rel": "resource-base"}}
            ]
        }
        result = cmds.ls()
        self.assertEqual(result, expected_home_resources)
    def test_home_ls(self, mock_request):
        p = Path()
        expected_home_resources = [
            Path("instance-ip"),
        ]

        mock_request.return_value = {
            "href": APIClient.base_url,
            "links": [
                {"link": {"href": Path("instance-ip"),
                          "name": "instance-ip",
                          "rel": "collection"}},
                {"link": {"href": Path("instance-ip"),
                          "name": "instance-ip",
                          "rel": "resource-base"}}
            ]
        }
        result = cmds.ls(p)
        self.assertEqual(result, expected_home_resources)
 def test_notfound_fqname_ls(self, mock_get, mock_fqname_to_id):
     ShellContext.current_path = Path('foo')
     mock_fqname_to_id.return_value = None
     result = cmds.ls(resource="default-domain:foo")
     self.assertIsNone(result)
     self.assertFalse(mock_get.called)