spoc/tests/test_repo.py

54 lines
1.7 KiB
Python
Raw Permalink Normal View History

2021-07-06 18:06:54 +02:00
from unittest.mock import patch, call
import pytest
2021-07-06 18:06:54 +02:00
from spoc import config
from spoc import repo
@patch('spoc.repo._DATA', {})
2021-07-06 18:06:54 +02:00
@patch('requests.get')
def test_load(req_get):
repo.load()
req_get.assert_called_once_with(config.REPO_FILE_URL, auth=config.REGISTRY_AUTH, timeout=5)
req_get.return_value.raise_for_status.assert_called_once()
req_get.return_value.json.assert_called_once()
2021-07-06 18:06:54 +02:00
@patch('spoc.repo._DATA', {})
2021-07-06 18:06:54 +02:00
@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, auth=config.REGISTRY_AUTH, timeout=5)
req_get.return_value.raise_for_status.assert_called_once()
req_get.return_value.json.assert_called_once()
2021-07-06 18:06:54 +02:00
@patch('spoc.repo._DATA', {})
2021-07-06 18:06:54 +02:00
@patch('requests.get')
def test_load_twice_force(req_get):
repo.load()
repo.load(force=True)
expected_call = call(config.REPO_FILE_URL, auth=config.REGISTRY_AUTH, timeout=5)
2021-07-06 18:06:54 +02:00
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._DATA', {'someapp': {'version': '0.1'}})
@patch('requests.get', side_effect=IOError())
def test_load_empty_on_fail(req_get):
with pytest.raises(IOError):
repo.load(force=True)
req_get.assert_called_once_with(config.REPO_FILE_URL, auth=config.REGISTRY_AUTH, timeout=5)
assert repo._DATA == {} # pylint: disable=protected-access
@patch('spoc.repo._DATA', {'someapp': {'version': '0.1'}})
2021-07-06 18:06:54 +02:00
@patch('spoc.repo.load')
def test_get_apps(repo_load):
apps = repo.get_apps()
2021-07-06 18:06:54 +02:00
repo_load.assert_called_once()
assert apps == {'someapp': {'version': '0.1'}}