Esempio n. 1
0
    def test_put(self, _put):
        """`put` will PUT to the smart url."""
        lxd = client._APINode(self.ROOT)

        lxd.fake.put()

        _put.assert_called_once_with('{}/{}'.format(self.ROOT, 'fake'))
Esempio n. 2
0
    def test_delete(self, _delete):
        """`delete` will DELETE to the smart url."""
        lxd = client._APINode(self.ROOT)

        lxd.fake.delete()

        _delete.assert_called_once_with('{}/{}'.format(self.ROOT, 'fake'))
Esempio n. 3
0
    def test_getattr_nested(self):
        """Nested objects return a more detailed path."""
        lxd = client._APINode(self.ROOT)  # NOQA

        self.assertEqual(
            '{}/fake/path'.format(self.ROOT),
            lxd.fake.path._api_endpoint)
Esempio n. 4
0
    def test_getitem(self):
        """`__getitem__` enables dynamic url parts."""
        lxd = client._APINode(self.ROOT)  # NOQA

        self.assertEqual(
            '{}/fake/path'.format(self.ROOT),
            lxd.fake['path']._api_endpoint)
Esempio n. 5
0
    def test_get(self, _get):
        """`get` will make a request to the smart url."""
        lxd = client._APINode(self.ROOT)

        lxd.fake.get()

        _get.assert_called_once_with('{}/{}'.format(self.ROOT, 'fake'))
Esempio n. 6
0
    def test_getitem_integer(self):
        """`__getitem__` with an integer allows dynamic integer url parts."""
        lxd = client._APINode(self.ROOT)  # NOQA

        self.assertEqual(
            '{}/fake/0'.format(self.ROOT),
            lxd.fake[0]._api_endpoint)
Esempio n. 7
0
    def test_getattr(self):
        """API Nodes can use object notation for nesting."""
        node = client._APINode('http://test.com')

        new_node = node.test

        self.assertEqual(
            'http://test.com/test', new_node._api_endpoint)
Esempio n. 8
0
 def test_getitem_leave_underscores_alone(self):
     """Bug 295 erronously changed underscores to '-' -- let's make sure
     it doens't happend again
     """
     node = client._APINode('http://test.com')
     new_node = node.thing['my_snapshot']
     self.assertEqual(
         'http://test.com/thing/my_snapshot', new_node._api_endpoint)
Esempio n. 9
0
    def test_getitem(self):
        """API Nodes can use dict notation for nesting."""
        node = client._APINode('http://test.com')

        new_node = node['test']

        self.assertEqual(
            'http://test.com/test', new_node._api_endpoint)
Esempio n. 10
0
 def test_getattr_storage_pools(self):
     """API node with storage_pool should be storage-pool"""
     node = client._APINode('http://test.com')
     new_node = node.test.storage_pools
     self.assertEqual(
         'http://test.com/test/storage-pools', new_node._api_endpoint)
     # other _ should stay as they were.
     new_node = node.test.some_thing
     self.assertEqual(
         'http://test.com/test/some_thing', new_node._api_endpoint)
Esempio n. 11
0
 def test_delete(self, Session):
     """Perform a session delete."""
     response = mock.Mock(**{
         'status_code': 200,
         'json.return_value': {'type': 'sync'},
     })
     session = mock.Mock(**{'delete.return_value': response})
     Session.return_value = session
     node = client._APINode('http://test.com')
     node.delete()
     session.delete.assert_called_once_with('http://test.com', timeout=None)
Esempio n. 12
0
    def test_get(self, Session):
        """Perform a session get."""
        response = mock.Mock(**{
            'status_code': 200,
            'json.return_value': {'type': 'sync'},
        })
        session = mock.Mock(**{'get.return_value': response})
        Session.return_value = session

        node = client._APINode('http://test.com')
        node.get()
        session.get.assert_called_once_with('http://test.com', timeout=None)
Esempio n. 13
0
 def test_post_200_not_sync(self, Session):
     """A status code of 200 with async request raises an exception."""
     response = mock.Mock(**{
         'status_code': 200,
         'json.return_value': {'type': 'async'},
     })
     session = mock.Mock(**{'post.return_value': response})
     Session.return_value = session
     node = client._APINode('http://test.com')
     self.assertRaises(
         exceptions.LXDAPIException,
         node.post)
Esempio n. 14
0
 def test_post_missing_type_200(self, Session):
     """A missing response type raises an exception."""
     response = mock.Mock(**{
         'status_code': 200,
         'json.return_value': {},
     })
     session = mock.Mock(**{'post.return_value': response})
     Session.return_value = session
     node = client._APINode('http://test.com')
     self.assertRaises(
         exceptions.LXDAPIException,
         node.post)
Esempio n. 15
0
 def test_post_200_not_sync(self, Session):
     """A status code of 200 with async request raises an exception."""
     response = mock.Mock(**{
         'status_code': 200,
         'json.return_value': {
             'type': 'async'
         },
     })
     session = mock.Mock(**{'post.return_value': response})
     Session.return_value = session
     node = client._APINode('http://test.com')
     self.assertRaises(exceptions.LXDAPIException, node.post)
Esempio n. 16
0
    def test_post_missing_type_200(self, Session):
        """A missing response type raises an exception."""
        response = mock.Mock(**{
            'status_code': 200,
            'json.return_value': {},
        })
        session = mock.Mock(**{'post.return_value': response})
        Session.return_value = session

        node = client._APINode('http://test.com')

        self.assertRaises(exceptions.LXDAPIException, node.post)
Esempio n. 17
0
 def test_post_200_not_sync(self, Session):
     """A status code of 200 with async request raises an exception."""
     response = mock.Mock(
         **{
             "status_code": 200,
             "json.return_value": {"type": "async"},
         }
     )
     session = mock.Mock(**{"post.return_value": response})
     Session.return_value = session
     node = client._APINode("http://test.com")
     self.assertRaises(exceptions.LXDAPIException, node.post)
Esempio n. 18
0
 def test_delete(self, Session):
     """Perform a session delete."""
     response = mock.Mock(
         **{
             "status_code": 200,
             "json.return_value": {"type": "sync"},
         }
     )
     session = mock.Mock(**{"delete.return_value": response})
     Session.return_value = session
     node = client._APINode("http://test.com")
     node.delete()
     session.delete.assert_called_once_with("http://test.com", timeout=None)
Esempio n. 19
0
    def test_put(self, Session):
        """Perform a session put."""
        response = mock.Mock(**{
            'status_code': 200,
            'json.return_value': {'type': 'sync'},
        })
        session = mock.Mock(**{'put.return_value': response})
        Session.return_value = session

        node = client._APINode('http://test.com')

        node.put()

        session.put.assert_called_once_with('http://test.com')
Esempio n. 20
0
    def test_delete(self, Session):
        """Perform a session delete."""
        response = mock.Mock(**{
            'status_code': 200,
            'json.return_value': {'type': 'sync'},
        })
        session = mock.Mock(**{'delete.return_value': response})
        Session.return_value = session

        node = client._APINode('http://test.com')

        node.delete()

        session.delete.assert_called_once_with('http://test.com')
Esempio n. 21
0
    def test_getattr(self):
        """`__getattr__` returns a nested node."""
        lxd = client._APINode(self.ROOT)

        self.assertEqual('{}/fake'.format(self.ROOT), lxd.fake._api_endpoint)
Esempio n. 22
0
    def test_session_http(self):
        """HTTP nodes return the default requests session."""
        node = client._APINode('http://test.com')

        self.assertIsInstance(node.session, requests.Session)
Esempio n. 23
0
 def test_session_unix_socket(self):
     """HTTP nodes return a requests_unixsocket session."""
     node = client._APINode("http+unix://test.com")
     self.assertIsInstance(node.session, requests_unixsocket.Session)
Esempio n. 24
0
 def test_session_http(self):
     """HTTP nodes return the default requests session."""
     node = client._APINode("http://test.com")
     self.assertIsInstance(node.session, requests.Session)
Esempio n. 25
0
 def test_getitem(self):
     """API Nodes can use dict notation for nesting."""
     node = client._APINode("http://test.com")
     new_node = node["test"]
     self.assertEqual("http://test.com/test", new_node._api_endpoint)
Esempio n. 26
0
 def test_getattr(self):
     """API Nodes can use object notation for nesting."""
     node = client._APINode("http://test.com")
     new_node = node.test
     self.assertEqual("http://test.com/test", new_node._api_endpoint)
Esempio n. 27
0
    def test_session_unix_socket(self):
        """HTTP nodes return a requests_unixsocket session."""
        node = client._APINode('http+unix://test.com')

        self.assertIsInstance(node.session, requests_unixsocket.Session)