-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathtest_version.py
89 lines (75 loc) · 3.24 KB
/
test_version.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
from __future__ import annotations
import aiohttp.web
import attrs
import pytest
from instawow import _version
from instawow.config import GlobalConfig
from .fixtures.http import ResponsesMockServer, Route
@pytest.mark.parametrize(
'_iw_mock_aiohttp_requests',
[set()],
indirect=True,
)
async def test_is_outdated_works_in_variety_of_scenarios(
monkeypatch: pytest.MonkeyPatch,
iw_aresponses: ResponsesMockServer,
iw_global_config_values: dict[str, object],
):
global_config = GlobalConfig.from_values(iw_global_config_values).write()
# version == '0+dev', version not cached
with monkeypatch.context() as patcher:
patcher.setattr(_version, 'get_version', lambda: '0+dev')
assert await _version.is_outdated(global_config) == (False, '')
# Update check disabled, version not cached
assert await _version.is_outdated(attrs.evolve(global_config, auto_update_check=False)) == (
False,
'',
)
# Endpoint not responsive, version not cached
with monkeypatch.context() as patcher:
patcher.setattr(_version, 'get_version', lambda: '0.1.0')
iw_aresponses.add(
Route(
r'//pypi\.org/simple/instawow', aiohttp.web.Response(status=500), single_use=True
)
)
assert await _version.is_outdated(global_config) == (False, '0.1.0')
# Endpoint responsive, version not cached and version different
with monkeypatch.context() as patcher:
patcher.setattr(_version, 'get_version', lambda: '0.1.0')
iw_aresponses.add(
Route(r'//pypi\.org/simple/instawow', {'versions': ['1.0.0']}, single_use=True)
)
assert await _version.is_outdated(global_config) == (True, '1.0.0')
# version == '0+dev', version cached
with monkeypatch.context() as patcher:
patcher.setattr(_version, 'get_version', lambda: '0+dev')
assert await _version.is_outdated(global_config) == (False, '')
# Update check disabled, version cached
assert await _version.is_outdated(attrs.evolve(global_config, auto_update_check=False)) == (
False,
'',
)
# Endpoint not responsive, version cached
with monkeypatch.context() as patcher:
patcher.setattr(_version, 'get_version', lambda: '0.1.0')
iw_aresponses.add(
Route(
r'//pypi\.org/simple/instawow', aiohttp.web.Response(status=500), single_use=True
)
)
assert await _version.is_outdated(global_config) == (True, '1.0.0')
# Endpoint responsive, version cached and version same
with monkeypatch.context() as patcher:
patcher.setattr(_version, 'get_version', lambda: '0.1.0')
iw_aresponses.add(
Route(r'//pypi\.org/simple/instawow', {'versions': ['1.0.0']}, single_use=True)
)
assert await _version.is_outdated(global_config) == (True, '1.0.0')
# Endpoint responsive, version cached and version different
with monkeypatch.context() as patcher:
patcher.setattr(_version, 'get_version', lambda: '1.0.0')
iw_aresponses.add(
Route(r'//pypi\.org/simple/instawow', {'versions': ['1.0.0']}, single_use=True)
)
assert await _version.is_outdated(global_config) == (False, '1.0.0')