Command line script to manage the cpi lab journal users.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

104 lines
3.0 KiB

# import pytest
from datetime import datetime
def test_elabuser_string_representation():
from elab_users.users import ElabUser
eu = ElabUser("John Doe", "Some Group")
assert str(eu) == "John Doe"
def test_elabuser_set_new_password(stub_handler):
from elab_users.users import ElabUser
eu = ElabUser("John Doe", "Some Group")
password = eu.set_new_password("some path", 12, handler=stub_handler)
assert len(password) == 12
assert len(stub_handler.stack) == 1
called = stub_handler.stack[0]
assert called.func == "check_call"
assert called.args == [
"htpasswd",
"-b",
"some path",
"John Doe",
password,
]
assert called.kargs == {}
def test_elabuser_delete_password(stub_handler):
from elab_users.users import ElabUser
eu = ElabUser("John Doe", "Some Group")
eu.delete_password("some path", handler=stub_handler)
assert len(stub_handler.stack) == 1
called = stub_handler.stack[0]
assert called.func == "check_call"
assert called.args == [
"htpasswd",
"-D",
"some path",
"John Doe",
]
assert list(called.kargs.keys()) == ["stderr"]
def test_elabuser_create_new_repo(stub_handler):
from elab_users.users import ElabUser
eu = ElabUser("John Doe", "Some Group")
eu.create_new_repository("some path", handler=stub_handler)
today = datetime.now()
current_month = today.month
current_year = today.year
assert len(stub_handler.stack) == 8 + (12 - current_month)
called = stub_handler.stack[0]
assert called.func == "check_call"
assert called.args == ["svnadmin", "create", "some path/John Doe"]
assert called.kargs == {"stderr": stub_handler.STDOUT}
called = stub_handler.stack[1]
assert called.func == "check_call"
assert called.args[:3] == ["svn", "checkout", "file://some path/John Doe"]
assert called.args[3].startswith("/tmp/") # noqa: S108
assert called.kargs == {}
called = stub_handler.stack[2]
assert called.func == "check_call"
assert called.args[0] == "touch"
assert called.args[1].startswith("/tmp/") # noqa: S108
assert called.args[1].endswith(
f"/{current_year:0>4}/{current_month:0>2}/.empty"
)
assert called.kargs == {}
called = stub_handler.stack[-3]
assert called.func == "check_call"
assert called.args[0] == "cp"
assert called.args[1] == "some path/template-toc.doc"
assert called.args[2].startswith("/tmp/") # noqa: S108
assert called.args[2].endswith("/template-toc.doc")
assert called.kargs == {}
called = stub_handler.stack[-2]
assert called.func == "check_call"
assert called.args[:3] == ["svn", "add", "--force"]
assert called.args[3].startswith("/tmp/") # noqa: S108
assert called.args[3].endswith("/")
assert called.kargs == {}
called = stub_handler.stack[-1]
assert called.func == "check_call"
assert called.args[:4] == ["svn", "commit", "-m", "New User: John Doe"]
assert called.args[4].startswith("/tmp/") # noqa: S108