1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
|
"""
Copyright (c) 2023 Proton AG
This file is part of Proton.
Proton is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Proton is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with ProtonVPN. If not, see <https://www.gnu.org/licenses/>.
"""
from proton.utils.environment import ProductExecutionEnvironment
import shutil
import pytest
from unittest.mock import Mock, patch
import os
@pytest.fixture
def config_mock(tmp_path):
d = tmp_path / "etc"
d.mkdir()
yield d
shutil.rmtree(str(d))
@pytest.fixture
def cache_mock(tmp_path):
d = tmp_path / "var" / "cache"
d.mkdir(parents=True)
yield d
shutil.rmtree(str(d))
@pytest.fixture
def runtime_mock(tmp_path):
d = tmp_path / "run"
d.mkdir(parents=True)
yield d
shutil.rmtree(str(d))
@patch("proton.utils.environment.BaseDirectory")
@patch("proton.utils.environment.os.getuid")
def test_successfully_create_product_dirs_when_creating_new_product_class(
get_uid_mock, base_directory_mock, config_mock, cache_mock, runtime_mock
):
get_uid_mock.return_value = 1
base_directory_mock.xdg_config_home = config_mock
base_directory_mock.xdg_cache_home = cache_mock
base_directory_mock.get_runtime_dir.return_value = runtime_mock
class MockEnv(ProductExecutionEnvironment):
PRODUCT = "mock"
assert MockEnv().path_config == str(config_mock / "Proton" / "mock")
assert MockEnv().path_cache == str(cache_mock / "Proton" / "mock")
assert MockEnv().path_logs == str(cache_mock / "Proton" / "logs" / "mock")
assert MockEnv().path_runtime == str(runtime_mock / "Proton" / "mock")
def test_raises_exception_when_creating_new_product_class_and_not_setting_product_class_property():
class MockEnv(ProductExecutionEnvironment):
...
with pytest.raises(RuntimeError):
MockEnv()
|