2024-10-30 10:10:57 +00:00
|
|
|
import pytest
|
|
|
|
|
2024-11-19 22:43:27 +00:00
|
|
|
from selfprivacy_api.root_daemon import (
|
|
|
|
get_available_commands,
|
|
|
|
init,
|
|
|
|
main,
|
|
|
|
service_commands,
|
|
|
|
services,
|
|
|
|
)
|
2024-10-30 10:10:57 +00:00
|
|
|
import selfprivacy_api.root_daemon
|
2024-11-19 22:43:27 +00:00
|
|
|
from os.path import join, exists
|
2024-10-30 10:10:57 +00:00
|
|
|
|
|
|
|
from typing import List
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture()
|
|
|
|
def test_socket(mocker, tmpdir):
|
|
|
|
socket_path = join(tmpdir, "test_socket.s")
|
|
|
|
mocker.patch(
|
|
|
|
"selfprivacy_api.root_daemon.SOCKET_PATH",
|
|
|
|
new=socket_path,
|
|
|
|
)
|
2024-11-19 22:43:27 +00:00
|
|
|
return socket_path
|
|
|
|
|
2024-10-30 10:10:57 +00:00
|
|
|
|
|
|
|
def is_in_strings(list: List[str], piece: str):
|
|
|
|
return any([piece in x for x in list])
|
2024-11-19 22:43:27 +00:00
|
|
|
|
2024-10-30 10:10:57 +00:00
|
|
|
|
|
|
|
def test_available_commands():
|
2024-11-19 22:43:27 +00:00
|
|
|
commands = get_available_commands()
|
2024-10-30 10:10:57 +00:00
|
|
|
assert commands != []
|
|
|
|
assert len(commands) >= len(services) * len(service_commands)
|
|
|
|
for service in services:
|
|
|
|
assert is_in_strings(commands, service)
|
|
|
|
|
2024-11-19 22:43:27 +00:00
|
|
|
|
|
|
|
def test_init(test_socket):
|
|
|
|
sock = init()
|
|
|
|
assert exists(test_socket)
|
|
|
|
assert sock is not None
|
|
|
|
|
2024-10-30 10:10:57 +00:00
|
|
|
|
|
|
|
def test_main():
|
|
|
|
# main()
|
|
|
|
pass
|