Ejemplo n.º 1
0
async def test_async_remove_games(manager_mock):
    """Test game entities are removed when removed from the wishlist."""
    wishlist_entity = SteamWishlistEntity(manager_mock)
    entities = [
        SteamGameEntity(
            manager_mock,
            get_steam_game(game_id, manager_mock.coordinator.data[game_id]),
        )
        for game_id in manager_mock.coordinator.data
    ]
    wishlist: Dict[int, SteamEntity] = {
        entity.game["steam_id"]: entity for entity in entities
    }
    # add a game to the current wishlist that will not be in the coordinator.data
    # to simulate a user removing a game from their wishlist.
    removed_game: SteamGame = {
        "box_art_url": "url",
        "normal_price": 49.99,
        "percent_off": 0,
        "sale_price": None,
        "steam_id": 12345,
        "title": "Removed",
    }
    removed_game_entity = SteamGameEntity(manager_mock, removed_game)
    # Need to mock this method as the entity platform isn't run so self.hass isn't set.
    removed_game_entity.async_remove = AsyncMock()
    wishlist[removed_game["steam_id"]] = removed_game_entity
    wishlist[sensor_manager.WISHLIST_ID] = wishlist_entity
    await sensor_manager.async_remove_games(wishlist, manager_mock.coordinator)
    # Verify the game was removed from the wishlist.
    assert removed_game["steam_id"] not in wishlist
    # Assert entity removed from HA
    assert removed_game_entity.async_remove.called is True
Ejemplo n.º 2
0
def test_steamgameentity_is_on_property(manager_mock):
    """Test the is_on property of the entity."""
    # Game on sale
    game_id = "975150"
    game = util.get_steam_game(game_id, manager_mock.coordinator.data[game_id])
    entity = SteamGameEntity(manager_mock, game)
    assert entity.is_on is True

    # Game not on sale
    game_id = "952060"
    game = util.get_steam_game(game_id, manager_mock.coordinator.data[game_id])
    entity = SteamGameEntity(manager_mock, game)
    assert entity.is_on is False

    # Game with no pricing information (unreleased)
    game_id = "870780"
    game = util.get_steam_game(game_id, manager_mock.coordinator.data[game_id])
    entity = SteamGameEntity(manager_mock, game)
    assert entity.is_on is False
Ejemplo n.º 3
0
def test_steamgameentity_device_state_attributes_property(manager_mock):
    """Test the device_state_attributes property."""
    game_id = "975150"
    game = util.get_steam_game(game_id, manager_mock.coordinator.data[game_id])
    entity = SteamGameEntity(manager_mock, game)
    expected = {
        "box_art_url":
        "https://steamcdn-a.akamaihd.net/steam/apps/975150/header_292x136.jpg?t=1590678003",
        "normal_price": 19.99,
        "percent_off": 15,
        "sale_price": 16.99,
        "steam_id": "975150",
        "title": "Resolutiion",
    }
    assert expected == entity.device_state_attributes
Ejemplo n.º 4
0
def test_steamgameentity_name_property(manager_mock):
    """Test the name property of the entity."""
    game_id = "975150"
    game = util.get_steam_game(game_id, manager_mock.coordinator.data[game_id])
    entity = SteamGameEntity(manager_mock, game)
    assert "Resolutiion" == entity.name
Ejemplo n.º 5
0
def test_steamgameentity_unique_id_property(manager_mock):
    """Test the unique_id property of the entity."""
    game_id = "975150"
    game = util.get_steam_game(game_id, manager_mock.coordinator.data[game_id])
    entity = SteamGameEntity(manager_mock, game)
    assert "steam_wishlist_resolutiion" == entity.unique_id