Esempio n. 1
0
def test_cli_radarr_add_manual_nomovie(mock_input, monkeypatch, mock_exit):
    test_args = [
        "pycliarr",
        "-t", TEST_HOST,
        "-k", TEST_APIKEY,
        "radarr",
        "add",
        "-t", "some movie",
    ]
    monkeypatch.setattr(sys, "argv", test_args)
    mock_sonarr = Mock()
    mock_sonarr.return_value = TEST_JSON
    mock_lookup = Mock()
    mock_lookup.return_value = []
    mock_profiles = Mock()
    mock_profiles.return_value = [{
        'name': 'name',
        'id': '1',
        'items': [{'quality': {'name': 'item1'}, 'allowed': True}]
    }]
    monkeypatch.setattr("pycliarr.cli.cli_cmd.radarr.RadarrCli.get_quality_profiles", mock_profiles)
    monkeypatch.setattr("pycliarr.cli.cli_cmd.sonarr.SonarrCli.get_language_profiles", mock_profiles)
    monkeypatch.setattr("pycliarr.cli.cli_cmd.radarr.RadarrCli.lookup_movie", mock_lookup)
    monkeypatch.setattr("pycliarr.cli.cli_cmd.radarr.RadarrCli.add_movie", mock_sonarr)
    cli.main()
    mock_exit.assert_called_with(2)
Esempio n. 2
0
def test_cli_sonarr_add_manual(mock_input, monkeypatch, mock_exit):
    test_args = [
        "pycliarr",
        "-t", TEST_HOST,
        "-k", TEST_APIKEY,
        "sonarr",
        "add",
        "-t", "some serie",
    ]
    monkeypatch.setattr(sys, "argv", test_args)
    mock_sonarr = Mock()
    mock_sonarr.return_value = TEST_JSON
    mock_lookup = Mock()
    mock_info = Mock(title="test1", year=2020)
    mock_lookup.return_value = [mock_info]
    mock_profiles = Mock()
    mock_profiles.return_value = [{
        'name': 'name',
        'id': '1',
        'items': [{'quality': {'name': 'item1'}, 'allowed': True}]
    }]
    monkeypatch.setattr("pycliarr.cli.cli_cmd.sonarr.SonarrCli.get_quality_profiles", mock_profiles)
    monkeypatch.setattr("pycliarr.cli.cli_cmd.sonarr.SonarrCli.get_language_profiles", mock_profiles)
    monkeypatch.setattr("pycliarr.cli.cli_cmd.sonarr.SonarrCli.lookup_serie", mock_lookup)
    monkeypatch.setattr("pycliarr.cli.cli_cmd.sonarr.SonarrCli.add_serie", mock_sonarr)
    cli.main()
    mock_lookup.assert_called_with(term="some serie")
    mock_sonarr.assert_called_with(
        quality=1, tvdb_id=None, serie_info=mock_info, monitored_seasons=[], season_folder=False, path=None, language=1
    )
    mock_exit.assert_called_with(0)
Esempio n. 3
0
def test_cli_sonarr_add_tvdb_with_seasons(monkeypatch, mock_exit):
    test_args = [
        "pycliarr",
        "-t", TEST_HOST,
        "-k", TEST_APIKEY,
        "sonarr",
        "add",
        "--tvdb", "1234",
        "-q", "1",
        "-l", "1",
        "-s", "1, 3",
        "--path", "some/path"
    ]
    monkeypatch.setattr(sys, "argv", test_args)
    mock_sonarr = Mock()
    mock_sonarr.return_value = TEST_JSON
    monkeypatch.setattr("pycliarr.cli.cli_cmd.sonarr.SonarrCli.add_serie", mock_sonarr)
    cli.main()
    mock_sonarr.assert_called_with(
        quality=1,
        tvdb_id=1234,
        serie_info=None,
        monitored_seasons=[1, 3],
        season_folder=False,
        path="some/path",
        language=1
    )
    mock_exit.assert_called_with(0)
Esempio n. 4
0
def test_cli_sonarr_get_exclusion_all(monkeypatch, mock_exit):
    test_args = [
        "pycliarr",
        "-t", TEST_HOST,
        "-k", TEST_APIKEY,
        "sonarr",
        "exclusion",
    ]
    monkeypatch.setattr(sys, "argv", test_args)
    mock_sonarr = Mock(return_value=[{"id": 12345}, {"id": 2233}])
    monkeypatch.setattr("pycliarr.cli.cli_cmd.sonarr.SonarrCli.get_exclusion", mock_sonarr)
    cli.main()
    mock_exit.assert_called_with(0)
Esempio n. 5
0
def test_cli_sonarr_delete_exclusion(monkeypatch, mock_exit):
    test_args = [
        "pycliarr",
        "-t", TEST_HOST,
        "-k", TEST_APIKEY,
        "sonarr",
        "delete-exclusion",
        "-i", "12345",
    ]
    monkeypatch.setattr(sys, "argv", test_args)
    mock_sonarr = Mock(return_value={"id": 12345})
    monkeypatch.setattr("pycliarr.cli.cli_cmd.sonarr.SonarrCli.delete_exclusion", mock_sonarr)
    cli.main()
    mock_exit.assert_called_with(0)
Esempio n. 6
0
def test_cli_sonarr_tagitems_badtag(monkeypatch, mock_exit):
    test_args = [
        "pycliarr",
        "-t", TEST_HOST,
        "-k", TEST_APIKEY,
        "sonarr",
        "tag-items",
        "-l", "something",
    ]
    monkeypatch.setattr(sys, "argv", test_args)
    mock_sonarr = Mock(return_value=[{"id": 456, "label": "value2"}])
    monkeypatch.setattr("pycliarr.cli.cli_cmd.sonarr.SonarrCli.get_tag_detail", mock_sonarr)
    cli.main()
    mock_exit.assert_called_with(0)
Esempio n. 7
0
def test_cli_api_exception(monkeypatch, mock_exit):
    test_args = [
        "pycliarr",
        "-t", TEST_HOST,
        "-k", TEST_APIKEY,
        "radarr",
        "get",
    ]
    monkeypatch.setattr(sys, "argv", test_args)
    mock_sonarr = Mock()
    mock_sonarr.side_effect = Exception
    monkeypatch.setattr("pycliarr.cli.cli_cmd.radarr.RadarrCli.get_movie", mock_sonarr)
    cli.main()
    mock_sonarr.assert_called()
    mock_exit.assert_called_with(2)
Esempio n. 8
0
def test_cli_radarr_tag_all(monkeypatch, mock_exit):
    test_args = [
        "pycliarr",
        "-t", TEST_HOST,
        "-k", TEST_APIKEY,
        "radarr",
        "tag",
    ]
    monkeypatch.setattr(sys, "argv", test_args)
    mock_sonarr = Mock()
    mock_sonarr.return_value = TEST_JSON
    monkeypatch.setattr("pycliarr.cli.cli_cmd.radarr.RadarrCli.get_tag", mock_sonarr)
    cli.main()
    mock_sonarr.assert_called_with(None)
    mock_exit.assert_called_with(0)
Esempio n. 9
0
def test_cli_radarr_search_missing(monkeypatch, mock_exit):
    test_args = [
        "pycliarr",
        "-t", TEST_HOST,
        "-k", TEST_APIKEY,
        "radarr",
        "search-missing",
    ]
    monkeypatch.setattr(sys, "argv", test_args)
    mock_sonarr = Mock()
    mock_sonarr.return_value = TEST_JSON
    monkeypatch.setattr("pycliarr.cli.cli_cmd.radarr.RadarrCli.missing_movies_search", mock_sonarr)
    cli.main()
    mock_sonarr.assert_called()
    mock_exit.assert_called_with(0)
Esempio n. 10
0
def test_cli_radarr_blocklist_all(monkeypatch, mock_exit):
    test_args = [
        "pycliarr",
        "-t", TEST_HOST,
        "-k", TEST_APIKEY,
        "radarr",
        "blocklist",
    ]
    monkeypatch.setattr(sys, "argv", test_args)
    mock_sonarr = Mock()
    mock_sonarr.return_value = TEST_JSON
    monkeypatch.setattr("pycliarr.cli.cli_cmd.radarr.RadarrCli.get_blocklist", mock_sonarr)
    cli.main()
    mock_sonarr.assert_called_with(page=1, sort_key="date", page_size=20, sort_dir="descending")
    mock_exit.assert_called_with(0)
Esempio n. 11
0
def test_cli_sonarr_tagitems_badval(monkeypatch, mock_exit):
    test_args = [
        "pycliarr",
        "-t", TEST_HOST,
        "-k", TEST_APIKEY,
        "sonarr",
        "tag-items",
        "-i", "456",
    ]
    monkeypatch.setattr(sys, "argv", test_args)
    mock_sonarr = Mock(return_value={"id": 456, "label": "value2"})
    monkeypatch.setattr("pycliarr.cli.cli_cmd.sonarr.SonarrCli.get_tag_detail", mock_sonarr)
    mock_sonarr2 = Mock(return_value=sonarr.SonarrSerieItem())
    monkeypatch.setattr("pycliarr.cli.cli_cmd.sonarr.SonarrCli.get_serie", mock_sonarr2)
    cli.main()
    mock_exit.assert_called_with(0)
Esempio n. 12
0
def test_cli_radarr_deletenotification(monkeypatch, mock_exit):
    test_args = [
        "pycliarr",
        "-t", TEST_HOST,
        "-k", TEST_APIKEY,
        "radarr",
        "delete-notification",
        "-i", "1234",
    ]
    monkeypatch.setattr(sys, "argv", test_args)
    mock_sonarr = Mock()
    mock_sonarr.return_value = TEST_JSON
    monkeypatch.setattr("pycliarr.cli.cli_cmd.radarr.RadarrCli.delete_notification", mock_sonarr)
    cli.main()
    mock_sonarr.assert_called_with(1234)
    mock_exit.assert_called_with(0)
Esempio n. 13
0
def test_cli_sonarr_deleteepisode(monkeypatch, mock_exit):
    test_args = [
        "pycliarr",
        "-t", TEST_HOST,
        "-k", TEST_APIKEY,
        "sonarr",
        "delete-episode-file",
        "-i", "1234",
    ]
    monkeypatch.setattr(sys, "argv", test_args)
    mock_sonarr = Mock()
    mock_sonarr.return_value = TEST_JSON
    monkeypatch.setattr("pycliarr.cli.cli_cmd.sonarr.SonarrCli.delete_episode_file", mock_sonarr)
    cli.main()
    mock_sonarr.assert_called_with(1234)
    mock_exit.assert_called_with(0)
Esempio n. 14
0
def test_cli_sonarr_getepisode(monkeypatch, mock_exit):
    test_args = [
        "pycliarr",
        "-t", TEST_HOST,
        "-k", TEST_APIKEY,
        "sonarr",
        "get-episode",
        "-i", "1234",
    ]
    monkeypatch.setattr(sys, "argv", test_args)
    mock_sonarr = Mock()
    mock_sonarr.return_value = TEST_JSON
    monkeypatch.setattr("pycliarr.cli.cli_cmd.sonarr.SonarrCli.get_episode", mock_sonarr)
    cli.main()
    mock_sonarr.assert_called_with(serie_id=1234, episode_id=None)
    mock_exit.assert_called_with(0)
Esempio n. 15
0
def test_cli_radarr_create_exclusion(monkeypatch, mock_exit):
    test_args = [
        "pycliarr",
        "-t", TEST_HOST,
        "-k", TEST_APIKEY,
        "radarr",
        "create-exclusion",
        "-t", "a title",
        "-i", "12345"
        "-y", "2020"
    ]
    monkeypatch.setattr(sys, "argv", test_args)
    mock_sonarr = Mock(return_value={"id": 12345})
    monkeypatch.setattr("pycliarr.cli.cli_cmd.radarr.RadarrCli.create_exclusion", mock_sonarr)
    cli.main()
    mock_exit.assert_called_with(0)
Esempio n. 16
0
def test_cli_radarr_refresh(monkeypatch, mock_exit):
    test_args = [
        "pycliarr",
        "-t", TEST_HOST,
        "-k", TEST_APIKEY,
        "radarr",
        "refresh",
        "-i", "1234",
    ]
    monkeypatch.setattr(sys, "argv", test_args)
    mock_sonarr = Mock()
    mock_sonarr.return_value = TEST_JSON
    monkeypatch.setattr("pycliarr.cli.cli_cmd.radarr.RadarrCli.refresh_movie", mock_sonarr)
    cli.main()
    mock_sonarr.assert_called_with(1234)
    mock_exit.assert_called_with(0)
Esempio n. 17
0
def test_cli_radarr_delete(monkeypatch, mock_exit):
    test_args = [
        "pycliarr",
        "-t", TEST_HOST,
        "-k", TEST_APIKEY,
        "radarr",
        "delete",
        "-i", "1234",
    ]
    monkeypatch.setattr(sys, "argv", test_args)
    mock_sonarr = Mock()
    mock_sonarr.return_value = TEST_JSON
    monkeypatch.setattr("pycliarr.cli.cli_cmd.radarr.RadarrCli.delete_movie", mock_sonarr)
    cli.main()
    mock_sonarr.assert_called_with(1234, delete_files=False, add_exclusion=False)
    mock_exit.assert_called_with(0)
Esempio n. 18
0
def test_cli_radarr_list(monkeypatch, mock_exit):
    test_args = [
        "pycliarr",
        "-t", TEST_HOST,
        "-k", TEST_APIKEY,
        "-u", TEST_USER,
        "-p", TEST_PASS,
        "radarr",
        "get",
    ]
    monkeypatch.setattr(sys, "argv", test_args)
    mock_sonarr = Mock()
    monkeypatch.setattr("pycliarr.cli.cli_cmd.radarr.RadarrCli.get_movie", mock_sonarr)
    cli.main()
    mock_sonarr.assert_called()
    mock_exit.assert_called_with(0)
Esempio n. 19
0
def test_cli_radarr_tagitems_serie(monkeypatch, mock_exit):
    test_args = [
        "pycliarr",
        "-t", TEST_HOST,
        "-k", TEST_APIKEY,
        "radarr",
        "tag-items",
        "-l", "value",
    ]
    monkeypatch.setattr(sys, "argv", test_args)
    mock_sonarr = Mock(return_value=[{"id": 1234, "label": "value", "movieIds": [1, 2, 3]}])
    monkeypatch.setattr("pycliarr.cli.cli_cmd.radarr.RadarrCli.get_tag_detail", mock_sonarr)
    mock_sonarr2 = Mock(return_value=radarr.RadarrMovieItem())
    monkeypatch.setattr("pycliarr.cli.cli_cmd.radarr.RadarrCli.get_movie", mock_sonarr2)
    cli.main()
    mock_sonarr2.assert_has_calls([call(1), call(2), call(3)])
    mock_exit.assert_called_with(0)
Esempio n. 20
0
def test_cli_radarr_putnotificationfile(monkeypatch, mock_exit):
    test_args = [
        "pycliarr",
        "-t", TEST_HOST,
        "-k", TEST_APIKEY,
        "radarr",
        "put-notification",
        "-i", "1234",
        "-f", 'test/data.json',
    ]
    monkeypatch.setattr(sys, "argv", test_args)
    mock_sonarr = Mock()
    mock_sonarr.return_value = TEST_JSON
    monkeypatch.setattr("pycliarr.cli.cli_cmd.radarr.RadarrCli.put_notification", mock_sonarr)
    cli.main()
    mock_sonarr.assert_called_with(1234, {'key': 'value'})
    mock_exit.assert_called_with(0)
Esempio n. 21
0
def test_cli_radarr_edittag(monkeypatch, mock_exit):
    test_args = [
        "pycliarr",
        "-t", TEST_HOST,
        "-k", TEST_APIKEY,
        "radarr",
        "edit-tag",
        "-i", "1234",
        "-l", "value",
    ]
    monkeypatch.setattr(sys, "argv", test_args)
    mock_sonarr = Mock()
    mock_sonarr.return_value = TEST_JSON
    monkeypatch.setattr("pycliarr.cli.cli_cmd.radarr.RadarrCli.edit_tag", mock_sonarr)
    cli.main()
    mock_sonarr.assert_called_with(1234, 'value')
    mock_exit.assert_called_with(0)
Esempio n. 22
0
def test_cli_radarr_add_imdb(monkeypatch, mock_exit):
    test_args = [
        "pycliarr",
        "-t", TEST_HOST,
        "-k", TEST_APIKEY,
        "radarr",
        "add",
        "--imdb", "tt1234",
        "-q", "1",
    ]
    monkeypatch.setattr(sys, "argv", test_args)
    mock_sonarr = Mock()
    mock_sonarr.return_value = TEST_JSON
    monkeypatch.setattr("pycliarr.cli.cli_cmd.radarr.RadarrCli.add_movie", mock_sonarr)
    cli.main()
    mock_sonarr.assert_called_with(quality=1, tmdb_id=None, imdb_id='tt1234', movie_info=None, path=None)
    mock_exit.assert_called_with(0)
Esempio n. 23
0
def test_cli_sonarr_add_tvdb_with_invalidseasons(monkeypatch, mock_exit):
    test_args = [
        "pycliarr",
        "-t", TEST_HOST,
        "-k", TEST_APIKEY,
        "sonarr",
        "add",
        "--tvdb", "1234",
        "-q", "1",
        "-l", "1",
        "-s", "1, x"
    ]
    monkeypatch.setattr(sys, "argv", test_args)
    mock_sonarr = Mock()
    mock_sonarr.return_value = TEST_JSON
    monkeypatch.setattr("pycliarr.cli.cli_cmd.sonarr.SonarrCli.add_serie", mock_sonarr)
    cli.main()
    mock_sonarr.assert_not_called
    mock_exit.assert_called_with(2)
Esempio n. 24
0
def test_cli_radarr_profile(monkeypatch, mock_exit):
    test_args = [
        "pycliarr",
        "-t", TEST_HOST,
        "-k", TEST_APIKEY,
        '-d',
        "radarr",
        "profiles",
    ]
    monkeypatch.setattr(sys, "argv", test_args)
    mock_sonarr = Mock()
    profiles_json = [{
        'name': 'name',
        'id': 'id',
        'items': [{'quality': {'name': 'item1'}, 'allowed': 'true'}]
    }]
    mock_sonarr.return_value = profiles_json
    monkeypatch.setattr("pycliarr.cli.cli_cmd.radarr.RadarrCli.get_quality_profiles", mock_sonarr)
    cli.main()
    mock_sonarr.assert_called()
    mock_exit.assert_called_with(0)
Esempio n. 25
0
def test_cli_radarr_add_one_result(mock_input, monkeypatch, mock_exit):
    test_args = [
        "pycliarr",
        "-t", TEST_HOST,
        "-k", TEST_APIKEY,
        "radarr",
        "add",
        "-t", "some movie",
        # "-q", 1
    ]
    monkeypatch.setattr(sys, "argv", test_args)
    mock_sonarr = Mock()
    mock_sonarr.return_value = TEST_JSON
    mock_lookup = Mock()
    mock_info = radarr.RadarrMovieItem(title="test1", year=2020)
    mock_lookup.return_value = mock_info
    mock_profiles = Mock()
    mock_profiles.return_value = [{
        'name': 'name',
        'id': '1',
        'items': [
            {'quality': {'name': 'item1'}, 'allowed': True},
            {'quality': {'name': 'item2'}, 'allowed': False},
            {'id': '2', 'allowed': True},
            {
                'name': 'name2',
                'id': '2',
                'allowed': True,
                'items': [{'quality': {'name': 'item2'}, 'allowed': True}]
            },
        ]
    }]
    monkeypatch.setattr("pycliarr.cli.cli_cmd.radarr.RadarrCli.get_quality_profiles", mock_profiles)
    monkeypatch.setattr("pycliarr.cli.cli_cmd.sonarr.SonarrCli.get_language_profiles", mock_profiles)
    monkeypatch.setattr("pycliarr.cli.cli_cmd.radarr.RadarrCli.lookup_movie", mock_lookup)
    monkeypatch.setattr("pycliarr.cli.cli_cmd.radarr.RadarrCli.add_movie", mock_sonarr)
    cli.main()
    mock_lookup.assert_called_with(term="some movie")
    mock_sonarr.assert_called_with(quality=1, tmdb_id=None, imdb_id=None, movie_info=mock_info, path=None)
    mock_exit.assert_called_with(0)