34
36
env_var = 'PSERV_TEST_COBBLER_URL'
36
help_text = dedent("""
38
help_text_available = dedent("""\
37
39
Set %s to the URL for a Cobbler instance to test against,
40
e.g. http://username:password@example.com/cobbler_api.
41
WARNING: this will modify your Cobbler database.
44
help_text_local = dedent("""\
45
Set %s to the URL for a *local* Cobbler instance to test against,
38
46
e.g. http://username:password@localhost/cobbler_api.
39
47
WARNING: this will modify your Cobbler database.
40
""".lstrip('\n') % env_var)
42
50
def __init__(self):
43
51
self.url = environ.get(self.env_var)
46
54
self.username = urlparts.username or 'cobbler'
47
55
self.password = urlparts.password or ''
49
58
def is_available(self):
50
"""Is a real Cobbler available for tests?
52
Use this to disable real-Cobbler tests if no real Cobbler is
53
available: annotate them with
56
not real_cobbler.is_available(), RealCobbler.help_text)
59
"""Is a real Cobbler available for tests?"""
58
60
return self.url is not None
63
def skip_unless_available(self):
64
"""Decorator to disable tests if no real Cobbler is available.
66
Annotate tests like so::
68
@real_cobbler.skip_unless_available
69
def test_something_that_requires_a_real_cobbler(self):
73
return skipIf(not self.is_available, self.help_text_available)
77
"""Is a real Cobbler installed locally available for tests?"""
79
hostname = urlparse(self.url).hostname
80
return hostname == "localhost" or hostname.startswith("127.")
85
def skip_unless_local(self):
86
"""Decorator to disable tests if no real *local* Cobbler is available.
88
Annotate tests like so::
90
@real_cobbler.skip_unless_local
91
def test_something_that_requires_a_real_local_cobbler(self):
95
return skipIf(not self.is_local, self.help_text_local)
60
97
def get_session(self):
61
98
"""Obtain a session on the real Cobbler.
63
100
Returns None if no real Cobbler is available.
65
if self.is_available():
102
if self.is_available:
66
103
return CobblerSession(self.url, self.username, self.password)