certbot.tests.util module¶
Test utilities.
-
certbot.tests.util.
make_lineage
(config_dir, testfile, ec=False)[source]¶ Creates a lineage defined by testfile.
This creates the archive, live, and renewal directories if necessary and creates a simple lineage.
- Parameters
config_dir (str) – path to the configuration directory
testfile (str) – configuration file to base the lineage on
- Returns
path to the renewal conf file for the created lineage
- Return type
str
-
certbot.tests.util.
patch_get_utility
(target='zope.component.getUtility')[source]¶ Patch zope.component.getUtility to use a special mock IDisplay.
The mock IDisplay works like a regular mock object, except it also also asserts that methods are called with valid arguments.
- Parameters
target (str) – path to patch
- Returns
mock zope.component.getUtility
- Return type
mock.MagicMock
-
certbot.tests.util.
patch_get_utility_with_stdout
(target='zope.component.getUtility', stdout=None)[source]¶ Patch zope.component.getUtility to use a special mock IDisplay.
The mock IDisplay works like a regular mock object, except it also also asserts that methods are called with valid arguments.
The
message
argument passed to the IDisplay methods is passed to stdout’s write method.- Parameters
target (str) – path to patch
stdout (object) – object to write standard output to; it is expected to have a
write
method
- Returns
mock zope.component.getUtility
- Return type
mock.MagicMock
-
class
certbot.tests.util.
FreezableMock
(frozen=False, func=None, return_value=sentinel.DEFAULT)[source]¶ Bases:
object
Mock object with the ability to freeze attributes.
This class works like a regular mock.MagicMock object, except attributes and behavior set before the object is frozen cannot be changed during tests.
If a func argument is provided to the constructor, this function is called first when an instance of FreezableMock is called, followed by the usual behavior defined by MagicMock. The return value of func is ignored.
-
class
certbot.tests.util.
TempDirTestCase
(methodName='runTest')[source]¶ Bases:
unittest.case.TestCase
Base test class which sets up and tears down a temporary directory
-
class
certbot.tests.util.
ConfigTestCase
(methodName='runTest')[source]¶ Bases:
certbot.tests.util.TempDirTestCase
Test class which sets up a NamespaceConfig object.
-
certbot.tests.util.
lock_and_call
(callback, path_to_lock)[source]¶ Grab a lock on path_to_lock from a foreign process then execute the callback. :param callable callback: object to call after acquiring the lock :param str path_to_lock: path to file or directory to lock