Skip to content

Commit 5a1e4cc

Browse files
committed
add tests for duplicate or missing higher_level values
1 parent 8a2de0e commit 5a1e4cc

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

api_v2/tests/test_objects.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,44 @@
55

66
API_BASE = f"http://localhost:8000"
77

8+
9+
class TestSpellCastingOptions:
10+
"""Tests to validate spell casting options data integrity."""
11+
12+
def test_all_spells_with_higher_level_have_casting_options(self):
13+
"""Every spell with higher_level text should have at least one casting option."""
14+
response = requests.get(
15+
f"{API_BASE}/v2/spells/?limit=1000",
16+
headers={'Accept': 'application/json'}
17+
).json()
18+
19+
spells_missing_options = []
20+
for spell in response['results']:
21+
if spell.get('higher_level') and not spell.get('casting_options'):
22+
spells_missing_options.append(spell['key'])
23+
24+
assert not spells_missing_options, \
25+
f"Spells with higher_level but no casting_options: {spells_missing_options}"
26+
27+
def test_no_duplicate_casting_option_types(self):
28+
"""No spell should have duplicate casting option types."""
29+
response = requests.get(
30+
f"{API_BASE}/v2/spells/?limit=1000",
31+
headers={'Accept': 'application/json'}
32+
).json()
33+
34+
spells_with_duplicates = []
35+
for spell in response['results']:
36+
casting_options = spell.get('casting_options', [])
37+
types = [opt['type'] for opt in casting_options]
38+
if len(types) != len(set(types)):
39+
duplicates = [t for t in types if types.count(t) > 1]
40+
spells_with_duplicates.append(f"{spell['name']}: {set(duplicates)}")
41+
42+
assert not spells_with_duplicates, \
43+
f"Spells with duplicate casting option types: {spells_with_duplicates}"
44+
45+
846
class TestObjects:
947

1048
def _verify(self, endpoint: str, transformer: Callable[[dict], None] = None):

0 commit comments

Comments
 (0)