-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathtest_wa_updater.py
169 lines (143 loc) · 3.63 KB
/
test_wa_updater.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
from __future__ import annotations
import pytest
from yarl import URL
from instawow import pkg_management
from instawow.definitions import Defn
from instawow.pkg_models import Pkg
from instawow.shared_ctx import ConfigBoundCtx
from instawow_wa_updater._config import PluginConfig
from instawow_wa_updater._core import WaCompanionBuilder, WeakAura, WeakAuras, _extract_auras
@pytest.fixture
def _wa_saved_vars(
iw_config_ctx: ConfigBoundCtx,
):
saved_vars = (
iw_config_ctx.config.addon_dir.parents[1] / 'WTF' / 'Account' / 'test' / 'SavedVariables'
)
saved_vars.mkdir(parents=True)
(saved_vars / WeakAuras.addon_name).with_suffix('.lua').write_text(
"""\
WeakAurasSaved = {
["displays"] = {
["Foo"] = {
["bar"] = "baz",
},
},
}
"""
)
@pytest.fixture
def builder(
iw_config_ctx: ConfigBoundCtx,
):
return WaCompanionBuilder(
PluginConfig(iw_config_ctx.config).ensure_dirs(),
)
def test_can_parse_empty_displays_table():
assert (
_extract_auras(
WeakAuras,
"""\
WeakAurasSaved = {
["displays"] = {
},
}
""",
).auras
== {}
)
def test_urlless_display_is_discarded():
assert (
_extract_auras(
WeakAuras,
"""\
WeakAurasSaved = {
["displays"] = {
["Foo"] = {
["bar"] = "baz",
},
},
}
""",
).auras
== {}
)
def test_can_parse_minimal_wago_display():
aura = WeakAura(
id='foo',
uid='foo',
parent=None,
url=URL('https://wago.io/foo/1'),
version=1,
)
assert _extract_auras(
WeakAuras,
"""\
WeakAurasSaved = {
["displays"] = {
["Foo"] = {
["bar"] = "baz",
["url"] = "https://wago.io/foo/1",
["version"] = 1,
["id"] = "foo",
["uid"] = "foo",
},
},
}
""",
).auras == {'foo': [aura]}
def test_url_host_not_wago_display_is_discarded():
assert (
_extract_auras(
WeakAuras,
"""\
WeakAurasSaved = {
["displays"] = {
["Foo"] = {
["bar"] = "baz",
["url"] = "https://wafo.io/foo/1",
["version"] = 1,
["id"] = "foo",
["uid"] = "foo",
},
},
}
""",
).auras
== {}
)
def test_can_build_addon_with_empty_seq(
builder: WaCompanionBuilder,
):
builder._generate_addon([])
@pytest.mark.usefixtures('_wa_saved_vars')
async def test_can_build_addon_with_mock_saved_vars(
builder: WaCompanionBuilder,
):
await builder.build()
def test_build_is_reproducible(
builder: WaCompanionBuilder,
):
builder._generate_addon([])
checksum = builder.build_paths.version.read_text(encoding='utf-8')
builder._generate_addon([])
assert checksum == builder.build_paths.version.read_text(encoding='utf-8')
def test_changelog_is_generated(
builder: WaCompanionBuilder,
):
builder._generate_addon([])
assert builder.build_paths.changelog.read_text() == 'n/a'
async def test_can_resolve_wa_companion_pkg(
builder: WaCompanionBuilder,
iw_config_ctx: ConfigBoundCtx,
):
await builder.build()
defn = Defn('instawow', 'weakauras-companion')
resolve_results = await pkg_management.resolve(iw_config_ctx, [defn])
assert type(resolve_results[defn]) is Pkg
async def test_can_resolve_wa_companion_autoupdate_pkg(
iw_config_ctx: ConfigBoundCtx,
):
defn = Defn('instawow', 'weakauras-companion-autoupdate')
resolve_results = await pkg_management.resolve(iw_config_ctx, [defn])
assert type(resolve_results[defn]) is Pkg