def test_get_torrents_should_filter_by_func():
    sut = QBitTorrent("admin", "adminadmin")
    sut.__GET__ = MagicMock(name="__GET__")
    sut.__GET__.return_value = list([{"state": "downloading"}, {"state": "pausedDL"}])

    torrents = sut.getTorrents(lambda x: x["state"] == "downloading")
    assert_that(generator_len(torrents)).is_equal_to(1)
    sut.__GET__.assert_called_with("/json/torrents")
def test_get_torrents_should_filter_by_tuple():
    sut = QBitTorrent("admin", "adminadmin")
    sut.__GET__ = MagicMock(name="__GET__")
    sut.__GET__.return_value = [{"state": "downloading", "name": "nameA"}, {"state": "pausedDL", "name": "nameB"}]

    torrents = sut.getTorrents(("name", "nameA"))

    assert_that(generator_len(torrents)).is_equal_to(1)
    sut.__GET__.assert_called_with("/json/torrents")
def test_get_torrents_should_filter_by_func():
    sut = QBitTorrent("admin", "adminadmin")
    sut.__GET__ = MagicMock(name='__GET__')
    sut.__GET__.return_value = list([{
        "state": "downloading"
    }, {
        "state": "pausedDL"
    }])

    torrents = sut.getTorrents(lambda x: x["state"] == "downloading")
    assert_that(generator_len(torrents)).is_equal_to(1)
    sut.__GET__.assert_called_with("/json/torrents")
def test_get_torrents_should_filter_by_multiple_states():
    sut = QBitTorrent("admin", "adminadmin")
    sut.__GET__ = MagicMock(name='__GET__')
    sut.__GET__.return_value = [{
        "state": "downloading"
    }, {
        "state": "pausedDL"
    }]

    torrents = sut.getTorrents(["downloading", "pausedDL"])

    assert_that(generator_len(torrents)).is_equal_to(2)
    sut.__GET__.assert_called_with("/json/torrents")