import pytest

from perms.services.get_permissions import get_all_linked_permissions, get_linked_permissions_name

PERMISSIONS_TEST_DATA = (
    ([], set()),
    ((), set()),
    (set(), set()),
    (['can_view_user'], {'can_view_user', 'can_view_user_list'}),
    (['can_control_sensors', 'can_delete_sensors'], {'can_view_sensors', 'can_view_sensors_list', 'can_control_sensors',
                                                     'can_delete_sensors'}),
)


PERMISSIONS_TEST_NAME_DATA = (
    ([], {}),
    (['can_view_sensors'], {'Can view sensor': 'Can view sensors list'}),
)


@pytest.mark.unit
@pytest.mark.parametrize('perms,result', PERMISSIONS_TEST_DATA)
def test_get_updated_permissions(perms, result) -> None:
    permissions = get_all_linked_permissions(perms)
    assert permissions == result


@pytest.mark.unit
@pytest.mark.django_db
@pytest.mark.parametrize('perms,result', PERMISSIONS_TEST_NAME_DATA)
def test_get_linked_permissions_name_service(perms, result) -> None:
    got_names = get_linked_permissions_name(perms)
    assert result == got_names
