Merge pull request 'Fix pull system tests for non-nixos systems' (#10) from NaiJi/selfprivacy-rest-api:chdir-mock into master
continuous-integration/drone/push Build is passing Details

Reviewed-on: #10
pull/11/head
Inex Code 2022-04-05 17:11:08 +03:00
commit 874acb1343
1 changed files with 19 additions and 2 deletions

View File

@ -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