spoc/tests/test_repo.py

41 lines
1.1 KiB
Python

from unittest.mock import patch, call
from spoc import config
from spoc import repo
@patch('spoc.repo._data', {})
@patch('requests.get')
def test_load(req_get):
repo.load()
req_get.assert_called_once_with(config.REPO_FILE_URL, timeout=5)
req_get.return_value.raise_for_status.asert_called_once()
req_get.return_value.json.asert_called_once()
@patch('spoc.repo._data', {})
@patch('requests.get')
def test_load_twice_no_force(req_get):
repo.load()
repo.load()
req_get.assert_called_once_with(config.REPO_FILE_URL, timeout=5)
req_get.return_value.raise_for_status.asert_called_once()
req_get.return_value.json.asert_called_once()
@patch('spoc.repo._data', {})
@patch('requests.get')
def test_load_twice_force(req_get):
repo.load()
repo.load(force=True)
expected_call = call(config.REPO_FILE_URL, timeout=5)
assert req_get.call_args_list.count(expected_call) == 2
assert req_get.return_value.raise_for_status.call_count == 2
assert req_get.return_value.json.call_count == 2
@patch('spoc.repo.load')
def test_get_apps(repo_load):
repo.get_apps()
repo_load.assert_called_once()