1
# Copyright 2010 Canonical Ltd. This software is licensed under the
2
# GNU Affero General Public License version 3 (see the file LICENSE).
13
from unittest import (
18
from lpx.disk import backend
19
from lpx.disk.backend import (
24
from lpx.disk.connection import Connection
25
from lpx.disk.uri import URI
27
from lpx.disk.testing.layers import FunctionalLayer
30
class TestCreateBackend(TestCase):
32
module_name = "lpx.disk.backends.backend_module"
35
super(TestCreateBackend, self).setUp()
36
self.backend_module = new.module("backend_module")
39
def create_from_uri(uri):
43
self.backend_module.create_from_uri = create_from_uri
44
sys.modules[self.module_name] = self.backend_module
47
del sys.modules[self.module_name]
48
super(TestCreateBackend, self).tearDown()
51
create_backend("backend-module:/path")
52
self.assertTrue(self.uri)
53
self.assertEquals(self.uri.scheme, "backend-module")
54
self.assertEquals(self.uri.path, "/path")
56
def test_unicode(self):
57
create_backend(u"backend-module:/path")
58
self.assertTrue(self.uri)
59
self.assertEquals(self.uri.scheme, "backend-module")
60
self.assertEquals(self.uri.path, "/path")
63
uri = URI("backend-module:/path")
65
self.assertTrue(self.uri is uri)
68
class TestRegisterScheme(TestCase):
73
if "factory" in backend._backend_schemes:
74
del backend._backend_schemes["factory"]
76
super(TestRegisterScheme, self).tearDown()
78
def test_register(self):
82
return "FACTORY RESULT"
84
register_scheme("factory", factory)
85
self.assertEqual(backend._backend_schemes["factory"], factory)
86
# Check that we can create backends that use this scheme ...
87
result = create_backend("factory:/path")
88
self.assertEqual(result, "FACTORY RESULT")
89
self.assertTrue(self.uri)
90
self.assertEqual(self.uri.scheme, "factory")
91
self.assertEqual(self.uri.path, "/path")
94
class TestBackendMixin:
96
layer = FunctionalLayer
99
raise NotImplementedError
102
backend = self.getBackend()
103
self.assertTrue(isinstance(backend, Backend))
105
def test_connect(self):
106
backend = self.getBackend()
107
connection = backend.connect()
108
self.assertTrue(isinstance(connection, Connection))
112
return defaultTestLoader.loadTestsFromName(__name__)