Exemplo n.º 1
0
def test_fetch_series_happy_path(mocker, config, series):
    config['series'].append(series)

    # Mock a datasource
    mock_datasource = MagicMock()
    mock_datasource.episodes_for_series.return_value = [(1, 1), (1, 2), (1, 3),
                                                        (1, 4), (1, 5)]
    # Mock a provider
    mock_provider = MagicMock()
    mock_provider.links_for.return_value = [Link('U', 'P', lambda x: '://'+x)]

    # Patch the download method
    mocker.patch('seriesbutler.functions.download')
    functions.download.return_value = True

    # Call the fetch method
    functions.fetch_series(config, series, [mock_provider], mock_datasource)

    # Verify the download method was called properly
    functions.download.assert_called_once_with('://U', os.path.join(
        config['working_directory'], series['name']), 's01e05', {})

    # Verify that the start_from value has been updated
    assert config['series'][0]['start_from']['episode'] == 5
    assert config['series'][0]['start_from']['season'] == 1
Exemplo n.º 2
0
def test_fetch_series_download_fails(mocker, config, series):
    config['series'].append(series)

    # Mock a datasource
    mock_datasource = MagicMock()
    mock_datasource.episodes_for_series.return_value = [(1, 1), (1, 2), (1, 3),
                                                        (1, 4), (1, 5)]
    # Mock a provider
    mock_provider = MagicMock()
    mock_provider.links_for.return_value = [Link('U', 'P', lambda x: '://'+x)]

    # Patch the download method
    mocker.patch('seriesbutler.functions.download')
    functions.download.return_value = False

    # Patch the logger
    mocker.patch('seriesbutler.functions.logger.error')

    # Call the fetch method
    functions.fetch_series(config, series, [mock_provider], mock_datasource)

    # Verify that the error messages were logged
    functions.logger.error.assert_any_call('Failed to download Brooklyn Nine-'
                                           'Nine s1e5')

    functions.logger.error.assert_any_call('Could not download Brooklyn Nine-'
                                           'Nine s1e5. No working links found')
Exemplo n.º 3
0
def test_fetch_series_no_links_found(mocker, config, series):
    config['series'].append(series)

    mock_datasource = MagicMock()
    mock_datasource.episodes_for_series.return_value = [(1, 1), (1, 2), (1, 3),
                                                        (1, 4), (1, 5), (1, 6)]
    # Patch the logger
    mocker.patch('seriesbutler.functions.logger.error')

    functions.fetch_series(config, series, [], mock_datasource)

    # assert the fact that there were no links found got reported
    assert functions.logger.error.call_count == 2
    functions.logger.error.assert_any_call('Could not download Brooklyn Nine-'
                                           'Nine s1e5. No working links found')
    functions.logger.error.assert_any_call('Could not download Brooklyn Nine-'
                                           'Nine s1e6. No working links found')
Exemplo n.º 4
0
def test_fetch_series_series_not_in_cfg(config, series):
    with pytest.raises(SeriesbutlerException) as exceptionInfo:
        functions.fetch_series(config, series, [], None)

    assert (str(exceptionInfo.value) == 'The given series is not registered '
            'in the given configuration!')