forked from DGNum/gestioCOF
cof -- Add tests for registration views
This commit is contained in:
parent
776ff28141
commit
7160a9c954
3 changed files with 378 additions and 0 deletions
|
@ -92,6 +92,38 @@ class TestCaseMixin:
|
|||
else:
|
||||
self.assertEqual(actual, expected)
|
||||
|
||||
def mockLDAP(self, results):
|
||||
class Elt:
|
||||
def __init__(self, value):
|
||||
self.value = value
|
||||
|
||||
class Entry:
|
||||
def __init__(self, **kwargs):
|
||||
for k, v in kwargs.items():
|
||||
setattr(self, k, Elt(v))
|
||||
|
||||
results_as_ldap = [
|
||||
Entry(uid=uid, cn=name) for uid, name in results
|
||||
]
|
||||
|
||||
mock_connection = mock.MagicMock()
|
||||
mock_connection.entries = results_as_ldap
|
||||
|
||||
# Connection is used as a context manager.
|
||||
mock_context_manager = mock.MagicMock()
|
||||
mock_context_manager.return_value.__enter__.return_value = (
|
||||
mock_connection
|
||||
)
|
||||
|
||||
patcher = mock.patch(
|
||||
'gestioncof.autocomplete.Connection',
|
||||
new=mock_context_manager,
|
||||
)
|
||||
patcher.start()
|
||||
self.addCleanup(patcher.stop)
|
||||
|
||||
return mock_connection
|
||||
|
||||
|
||||
class ViewTestCaseMixin(TestCaseMixin):
|
||||
"""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue