async def test_on_location_collected(client: MultiworldClient, tmpdir, exists,
                                     wrong_game):
    client._data = Data(Path(tmpdir).joinpath("data.json"))
    client._data.collected_locations = {10, 15} if exists else {10}
    client.start_notify_collect_locations_task = MagicMock()

    if wrong_game and not exists:
        expected_locations = {10}
    else:
        expected_locations = {10, 15}

    if not wrong_game:
        client._expected_game = RandovaniaGame.METROID_PRIME_ECHOES

    # Run
    await client.on_location_collected(RandovaniaGame.METROID_PRIME_ECHOES,
                                       PickupIndex(15))

    # Assert
    assert client._data.collected_locations == expected_locations

    if exists or wrong_game:
        client.start_notify_collect_locations_task.assert_not_called()
    else:
        client.start_notify_collect_locations_task.assert_called_once_with()
Exemplo n.º 2
0
async def test_on_game_updated(client, tmpdir):
    client.refresh_received_pickups = AsyncMock()
    client._received_pickups = MagicMock()

    client._data = Data(Path(tmpdir).joinpath("data.json"))

    # Run
    await client.on_network_game_updated()

    # Assert
    client.game_connection.set_permanent_pickups.assert_called_once_with(
        client._received_pickups)
async def test_on_game_updated(client, tmpdir):
    client._data = Data(Path(tmpdir).joinpath("data.json"))
    pickups = MagicMock()

    # Run
    await client.on_network_game_updated(pickups)

    # Assert
    client.game_connection.set_expected_game.assert_called_once_with(
        pickups.game)
    client.game_connection.set_permanent_pickups.assert_called_once_with(
        pickups.pickups)
Exemplo n.º 4
0
async def test_on_game_updated(client, tmpdir):
    client.refresh_received_pickups = AsyncMock()
    client._received_messages = ["Message A", "Message B", "Message C"]
    client._received_pickups = [MagicMock(), MagicMock(), MagicMock()]

    client._data = Data(Path(tmpdir).joinpath("data.json"))
    client._data.latest_message_displayed = 1

    # Run
    await client.on_game_updated()

    # Assert
    client.game_connection.display_message.assert_has_calls([call("Message B"), call("Message C")])
    client.game_connection.set_permanent_pickups.assert_called_once_with(client._received_pickups)
    assert client._data.latest_message_displayed == 3
Exemplo n.º 5
0
async def test_on_location_collected(client, tmpdir, exists):
    client._data = Data(Path(tmpdir).joinpath("data.json"))
    client._data.collected_locations = {10, 15} if exists else {10}
    client.start_notify_collect_locations_task = MagicMock()

    # Run
    await client.on_location_collected(15)

    # Assert
    assert client._data.collected_locations == {10, 15}

    if exists:
        client.start_notify_collect_locations_task.assert_not_called()
    else:
        client.start_notify_collect_locations_task.assert_called_once_with()
Exemplo n.º 6
0
async def test_notify_collect_locations(client, tmpdir):
    data_path = Path(tmpdir).joinpath("data.json")
    network_client = client.network_client
    network_client.game_session_collect_locations = AsyncMock(side_effect=[
        RuntimeError("connection issue!"),
        None,
    ])

    data_path.write_text(json.dumps({
        "collected_locations": [10, 15],
        "uploaded_locations": [15],
        "latest_message_displayed": 0,
    }))
    client._data = Data(data_path)

    # Run
    await client._notify_collect_locations()

    # Assert
    network_client.game_session_collect_locations.assert_has_awaits([call((10,)), call((10,))])
    assert set(json.loads(data_path.read_text())["uploaded_locations"]) == {10, 15}