/usr/lib/python3/dist-packages/pylxd/deprecated/tests/test_client.py is in python3-pylxd 2.0.0~b1-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | # Copyright (c) 2016 Canonical Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
"""Tests for pylxd.client."""
import unittest
import mock
from pylxd import client
class Test_APINode(unittest.TestCase):
"""Tests for pylxd.client._APINode."""
ROOT = 'http://lxd/api'
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_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_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)
@mock.patch('pylxd.client.requests.get')
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'))
@mock.patch('pylxd.client.requests.post')
def test_post(self, _post):
"""`post` will POST to the smart url."""
lxd = client._APINode(self.ROOT)
lxd.fake.post()
_post.assert_called_once_with('{}/{}'.format(self.ROOT, 'fake'))
@mock.patch('pylxd.client.requests.put')
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'))
@mock.patch('pylxd.client.requests.delete')
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'))
|