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'))
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'))
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)
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)
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'))
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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')
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')
def test_getattr(self): """`__getattr__` returns a nested node.""" lxd = client._APINode(self.ROOT) self.assertEqual('{}/fake'.format(self.ROOT), lxd.fake._api_endpoint)
def test_session_http(self): """HTTP nodes return the default requests session.""" node = client._APINode('http://test.com') self.assertIsInstance(node.session, requests.Session)
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)
def test_session_http(self): """HTTP nodes return the default requests session.""" node = client._APINode("http://test.com") self.assertIsInstance(node.session, requests.Session)
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)
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)
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)