Example #1
0
def test_load_sorts_by_downloads():
    subtitles = [
        MagicMock(spec=Subtitle,
                  id='A',
                  encoding='c',
                  format='srt',
                  partial=False,
                  downloads=1),
        MagicMock(spec=Subtitle,
                  id='B',
                  encoding='c',
                  format='srt',
                  partial=False,
                  downloads=100),
        MagicMock(spec=Subtitle,
                  id='C',
                  encoding='c',
                  format='srt',
                  partial=False,
                  downloads=1000),
    ]

    api_mock = MagicMock()
    api_mock.find_subtitles_for_movie = MagicMock(return_value=subtitles)

    loader = Loader(api_mock)
    s = loader.load('<id>')
    assert s is subtitles[2]
Example #2
0
def test_load_none_found():
    api_mock = MagicMock()
    api_mock.find_subtitles_for_movie = MagicMock(return_value=[])

    loader = Loader(api_mock)
    s = loader.load('<id>')
    assert s is None
Example #3
0
def test_load():
    subtitles = [
        MagicMock(spec=Subtitle,
                  id='A',
                  encoding='c',
                  format='srt',
                  partial=False,
                  downloads=100,
                  text='<text>'),
    ]

    api_mock = MagicMock()
    api_mock.find_subtitles_for_movie = MagicMock(return_value=subtitles)
    api_mock.load_text = MagicMock(return_value='<text>')

    loader = Loader(api_mock)
    s = loader.load('<id>')

    assert s is subtitles[0]
    api_mock.find_subtitles_for_movie.assert_called_with('<id>')
    api_mock.load_text.assert_called_with(subtitles[0].id,
                                          subtitles[0].encoding)
Example #4
0
def test_load_none_valid():
    invalid_subtitles = [
        MagicMock(spec=Subtitle,
                  id='A',
                  encoding='c',
                  format='ssa',
                  partial=False,
                  downloads=1),
        MagicMock(spec=Subtitle,
                  id='B',
                  encoding='c',
                  format='srt',
                  partial=True,
                  downloads=1),
    ]

    api_mock = MagicMock()
    api_mock.find_subtitles_for_movie = MagicMock(
        return_value=invalid_subtitles)

    loader = Loader(api_mock)
    s = loader.load('<id>')
    assert s is None
Example #5
0
def create_routes(app):
    app.jinja_loader = jinja2.FileSystemLoader(os.path.join(os.getcwd(), TEMPLATE_ROOT))

    opensubtitle_credentials = (app.config['OPENSUBTITLES_USER'], app.config['OPENSUBTITLES_PASS'])
    subtitle_api = OpenSubtitles(opensubtitle_credentials)

    fanart_key = app.config['FANART_TV_KEY']
    poster_api = FanArt(fanart_key)

    wordnik_key = app.config['WORDNIK_KEY']
    wordnik_api = Wordnik(wordnik_key)

    searcher = Searcher(subtitle_api, poster_api)

    corpus = Corpus(CorpusDatabase.FULL)
    loader = Loader(subtitle_api)
    parser = Parser()
    analyser = Analyser(loader, parser, corpus)

    @app.route('/')
    def home_route():
        return bootstrap()

    @app.route('/m/<id>')
    def analysis_route(id):
        return bootstrap()

    @app.route('/m/<id>/w/<word>')
    def word_route(id, word):
        return bootstrap()

    @app.route('/error')
    def error_route():
        return error()

    @app.route('/api/search/<query>')
    @as_json
    def search_api_route(query):
        return search_api(searcher, query)

    @app.route('/api/analysis/<id>')
    @as_json
    def analysis_api_route(id):
        return analysis_api(analyser, poster_api, id)

    @app.route('/api/words/<token>')
    @as_json
    def words_api_route(token):
        return words_api(wordnik_api, token)