53 lines
1.7 KiB
Python
53 lines
1.7 KiB
Python
import pytest
|
|
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, auth=config.REGISTRY_AUTH, 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, auth=config.REGISTRY_AUTH, 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, auth=config.REGISTRY_AUTH, 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._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'}})
|
|
@patch('spoc.repo.load')
|
|
def test_get_apps(repo_load):
|
|
apps = repo.get_apps()
|
|
|
|
repo_load.assert_called_once()
|
|
assert apps == {'someapp': {'version': '0.1'}}
|