/usr/lib/python2.7/dist-packages/pylxd/tests/models/test_profile.py is in python-pylxd 2.2.6-0ubuntu1.
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 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 | import json
from pylxd import exceptions, models
from pylxd.tests import testing
class TestProfile(testing.PyLXDTestCase):
"""Tests for pylxd.models.Profile."""
def test_get(self):
"""A profile is fetched."""
name = 'an-profile'
an_profile = models.Profile.get(self.client, name)
self.assertEqual(name, an_profile.name)
def test_get_not_found(self):
"""LXDAPIException is raised on unknown profiles."""
def not_found(request, context):
context.status_code = 404
return json.dumps({
'type': 'error',
'error': 'Not found',
'error_code': 404})
self.add_rule({
'text': not_found,
'method': 'GET',
'url': r'^http://pylxd.test/1.0/profiles/an-profile$',
})
self.assertRaises(
exceptions.LXDAPIException,
models.Profile.get, self.client, 'an-profile')
def test_get_error(self):
"""LXDAPIException is raised on get error."""
def error(request, context):
context.status_code = 500
return json.dumps({
'type': 'error',
'error': 'Not found',
'error_code': 500})
self.add_rule({
'text': error,
'method': 'GET',
'url': r'^http://pylxd.test/1.0/profiles/an-profile$',
})
self.assertRaises(
exceptions.LXDAPIException,
models.Profile.get, self.client, 'an-profile')
def test_exists(self):
name = 'an-profile'
self.assertTrue(models.Profile.exists(self.client, name))
def test_not_exists(self):
def not_found(request, context):
context.status_code = 404
return json.dumps({
'type': 'error',
'error': 'Not found',
'error_code': 404})
self.add_rule({
'text': not_found,
'method': 'GET',
'url': r'^http://pylxd.test/1.0/profiles/an-profile$',
})
name = 'an-profile'
self.assertFalse(models.Profile.exists(self.client, name))
def test_all(self):
"""A list of all profiles is returned."""
profiles = models.Profile.all(self.client)
self.assertEqual(1, len(profiles))
def test_create(self):
"""A new profile is created."""
an_profile = models.Profile.create(
self.client, name='an-new-profile', config={}, devices={})
self.assertIsInstance(an_profile, models.Profile)
self.assertEqual('an-new-profile', an_profile.name)
def test_rename(self):
"""A profile is renamed."""
an_profile = models.Profile.get(self.client, 'an-profile')
an_renamed_profile = an_profile.rename('an-renamed-profile')
self.assertEqual('an-renamed-profile', an_renamed_profile.name)
def test_update(self):
"""A profile is updated."""
# XXX: rockstar (03 Jun 2016) - This just executes
# a code path. There should be an assertion here, but
# it's not clear how to assert that, just yet.
an_profile = models.Profile.get(self.client, 'an-profile')
an_profile.save()
self.assertEqual({}, an_profile.config)
def test_fetch(self):
"""A partially fetched profile is made complete."""
an_profile = self.client.profiles.all()[0]
an_profile.sync()
self.assertEqual('An description', an_profile.description)
def test_fetch_notfound(self):
"""LXDAPIException is raised on bogus profile fetches."""
def not_found(request, context):
context.status_code = 404
return json.dumps({
'type': 'error',
'error': 'Not found',
'error_code': 404})
self.add_rule({
'text': not_found,
'method': 'GET',
'url': r'^http://pylxd.test/1.0/profiles/an-profile$',
})
an_profile = models.Profile(self.client, name='an-profile')
self.assertRaises(exceptions.LXDAPIException, an_profile.sync)
def test_fetch_error(self):
"""LXDAPIException is raised on fetch error."""
def error(request, context):
context.status_code = 500
return json.dumps({
'type': 'error',
'error': 'Not found',
'error_code': 500})
self.add_rule({
'text': error,
'method': 'GET',
'url': r'^http://pylxd.test/1.0/profiles/an-profile$',
})
an_profile = models.Profile(self.client, name='an-profile')
self.assertRaises(exceptions.LXDAPIException, an_profile.sync)
def test_delete(self):
"""A profile is deleted."""
# XXX: rockstar (03 Jun 2016) - This just executes
# a code path. There should be an assertion here, but
# it's not clear how to assert that, just yet.
an_profile = self.client.profiles.all()[0]
an_profile.delete()
|