From 035796ecc7d372a409607fe81449d3134da84a7f Mon Sep 17 00:00:00 2001 From: NaiJi Date: Sun, 3 Apr 2022 22:04:49 +0300 Subject: [PATCH] Fix pull system tests for non-nixos systems --- tests/test_system.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/tests/test_system.py b/tests/test_system.py index a4e24ad..9ed2617 100644 --- a/tests/test_system.py +++ b/tests/test_system.py @@ -1,6 +1,9 @@ # pylint: disable=redefined-outer-name # pylint: disable=unused-argument +# pylint: disable=missing-function-docstring + import json +import os import pytest from selfprivacy_api.utils import get_domain @@ -76,6 +79,12 @@ def mock_subprocess_popen(mocker): return mock +@pytest.fixture +def mock_os_chdir(mocker): + mock = mocker.patch("os.chdir", autospec=True) + return mock + + @pytest.fixture def mock_broken_service(mocker): mock = mocker.patch( @@ -384,14 +393,22 @@ def test_pull_system_unauthorized(client, mock_subprocess_popen): assert mock_subprocess_popen.call_count == 0 -def test_pull_system(authorized_client, mock_subprocess_popen): +def test_pull_system(authorized_client, mock_subprocess_popen, mock_os_chdir): + current_dir = os.getcwd() response = authorized_client.get("/system/configuration/pull") assert response.status_code == 200 assert mock_subprocess_popen.call_count == 1 assert mock_subprocess_popen.call_args[0][0] == ["git", "pull"] + assert mock_os_chdir.call_count == 2 + assert mock_os_chdir.call_args_list[0][0][0] == "/etc/nixos" + assert mock_os_chdir.call_args_list[1][0][0] == current_dir -def test_pull_system_broken_repo(authorized_client, mock_broken_service): +def test_pull_system_broken_repo(authorized_client, mock_broken_service, mock_os_chdir): + current_dir = os.getcwd() response = authorized_client.get("/system/configuration/pull") assert response.status_code == 500 assert mock_broken_service.call_count == 1 + assert mock_os_chdir.call_count == 2 + assert mock_os_chdir.call_args_list[0][0][0] == "/etc/nixos" + assert mock_os_chdir.call_args_list[1][0][0] == current_dir