56 lines
1.9 KiB
Python
56 lines
1.9 KiB
Python
|
# Copyright 2024 Zoé Cassiopée Gauthier.
|
||
|
#
|
||
|
# Use of this source code is governed by an MIT-style
|
||
|
# license that can be found in the LICENSE file or at
|
||
|
# https://opensource.org/licenses/MIT.
|
||
|
|
||
|
import unittest.mock
|
||
|
|
||
|
import pytest
|
||
|
import requests
|
||
|
from pogo_scaled_estimators.pokebattler_proxy import MovesetResult, PokebattlerProxy, Raid
|
||
|
|
||
|
|
||
|
class MockSession(requests.Session):
|
||
|
def __init__(self, *args, **kwargs):
|
||
|
kwargs.pop("cache_control", None)
|
||
|
kwargs.pop("use_cache_dir", None)
|
||
|
super().__init__(*[], **kwargs)
|
||
|
|
||
|
|
||
|
@pytest.fixture(autouse=True)
|
||
|
def _disable_requests_cache():
|
||
|
"""Replace CachedSession with a regular Session for all test functions"""
|
||
|
with unittest.mock.patch("requests_cache.CachedSession", MockSession):
|
||
|
yield
|
||
|
|
||
|
|
||
|
def test_simulate(requests_mock):
|
||
|
requests_mock.get(
|
||
|
"https://fight.pokebattler.com/raids/defenders/MEWTWO_SHADOW_FORM/levels/RAID_LEVEL_5_SHADOW/attackers/levels/40/strategies/CINEMATIC_ATTACK_WHEN_POSSIBLE/DEFENSE_RANDOM_MC",
|
||
|
json={
|
||
|
"attackers": [
|
||
|
{
|
||
|
"randomMove": {
|
||
|
"move1": "RANDOM",
|
||
|
"move2": "RANDOM",
|
||
|
"defenders": [
|
||
|
{
|
||
|
"pokemonId": "BIDOOF",
|
||
|
"byMove": [
|
||
|
{"move1": "TACKLE_FAST", "move2": "HYPER_FANG", "result": {"estimator": 5.4321}},
|
||
|
],
|
||
|
"cp": 721,
|
||
|
}
|
||
|
],
|
||
|
}
|
||
|
}
|
||
|
]
|
||
|
},
|
||
|
)
|
||
|
|
||
|
pokebattler_proxy = PokebattlerProxy()
|
||
|
raid = Raid("RAID_LEVEL_5_SHADOW", "MEWTWO_SHADOW_FORM")
|
||
|
results = pokebattler_proxy.simulate(raid)
|
||
|
assert results == {"BIDOOF": [MovesetResult("TACKLE_FAST", "HYPER_FANG", 5.4321)]}
|