Exemplo n.º 1
0
    def test_parsing_common_phrase_mock(self):
        with mock.patch('requests.post') as MockRequestsPost:
            auth_server_response = TestJellyfinCroft.mocked_responses[
                "jellyfin"]["3.5.2.0"]["auth_server_response"]
            response = MockResponse(200, auth_server_response)
            MockRequestsPost.return_value = response
            jellyfin_croft = JellyfinCroft(HOST, USERNAME, PASSWORD, "none")

            for phrase in TestJellyfinCroft.common_phrases:
                match_type = TestJellyfinCroft.common_phrases[phrase][
                    "match_type"]

                search_response = TestJellyfinCroft.mocked_responses[
                    "jellyfin"]["3.5.2.0"]["common_play"][match_type][
                        "search_response"]
                get_songs_response = TestJellyfinCroft.mocked_responses[
                    "jellyfin"]["3.5.2.0"]["common_play"][match_type][
                        "songs_response"]
                with mock.patch('requests.get') as MockRequestsGet:
                    responses = [
                        MockResponse(200, search_response),
                        MockResponse(200, get_songs_response)
                    ]
                    MockRequestsGet.side_effect = responses

                    match_type, songs = jellyfin_croft.parse_common_phrase(
                        phrase)

                    assert match_type == TestJellyfinCroft.common_phrases[
                        phrase]["match_type"]
                    assert songs
Exemplo n.º 2
0
    def test_host_normalize(self):

        hostname = "noProtocol"
        normaized_host = JellyfinCroft.normalize_host(hostname)
        assert "http://" + hostname == normaized_host

        # assert that if http exists then no change
        hostname = "hTtps://hasProtocol"
        assert hostname == JellyfinCroft.normalize_host(hostname)
Exemplo n.º 3
0
    def test_search_for_song(self):
        song = "And I Told Them I Invented Times New Roman"

        jellyfin_croft = JellyfinCroft(HOST, USERNAME, PASSWORD, "none")
        songs = jellyfin_croft.search_song(song)
        assert len(songs) == 3
        for song_item in songs:
            assert song in song_item.name
            assert song_item.id is not None
            assert song_item.type == MediaItemType.SONG
Exemplo n.º 4
0
    def test_parsing_common_phrase(self):

        jellyfin_croft = JellyfinCroft(HOST, USERNAME, PASSWORD, "none")

        for phrase in TestJellyfinCroft.common_phrases:
            match_type, songs = jellyfin_croft.parse_common_phrase(phrase)

            assert match_type == TestJellyfinCroft.common_phrases[phrase][
                'match_type']
            assert songs
Exemplo n.º 5
0
    def test_diag_public_server_info_happy_path(self):

        jellyfin_croft = JellyfinCroft(HOST,
                                       USERNAME,
                                       PASSWORD,
                                       "none",
                                       diagnostic=True)
        connection_success, info = jellyfin_croft.diag_public_server_info()

        assert connection_success
        assert info is not None
Exemplo n.º 6
0
    def test_diag_public_server_info_bad_host(self):

        jellyfin_croft = JellyfinCroft('badhostHere',
                                       USERNAME,
                                       PASSWORD,
                                       "none",
                                       diagnostic=True)
        connection_success, info = jellyfin_croft.diag_public_server_info()

        assert not connection_success
        assert info is not None
Exemplo n.º 7
0
    def test_diag_public_server_info_bad_host_mock(self):

        jellyfin_croft = JellyfinCroft('badhostHere',
                                       USERNAME,
                                       PASSWORD,
                                       "none",
                                       diagnostic=True)

        with mock.patch('requests.get') as MockRequestsGet:
            MockRequestsGet.side_effect = Exception('Fail')
            connection_success, info = jellyfin_croft.diag_public_server_info()

            assert not connection_success
            assert info is not None
Exemplo n.º 8
0
    def test_diag_public_server_info_happy_path_mock(self):

        jellyfin_croft = JellyfinCroft(HOST,
                                       USERNAME,
                                       PASSWORD,
                                       "none",
                                       diagnostic=True)

        with mock.patch('requests.get') as MockRequestsGet:
            public_info_response = TestJellyfinCroft.mocked_responses[
                "jellyfin"]["4.1.1.0"]["public_info"]
            response = MockResponse(200, public_info_response)
            MockRequestsGet.return_value = response
            connection_success, info = jellyfin_croft.diag_public_server_info()

            assert connection_success
            assert info is not None
Exemplo n.º 9
0
 def test_songs_by_playlist(self):
     playlist = 'Xmas Music'
     client = JellyfinClient(HOST, USERNAME, PASSWORD)
     response = client.search(playlist, [MediaItemType.PLAYLIST.value])
     search_items = JellyfinCroft.parse_search_hints_from_response(response)
     playlists = JellyfinMediaItem.from_list(search_items)
     assert len(playlists) == 1
     playlist_id = playlists[0].id
     songs = client.get_songs_by_playlist(playlist_id)
     assert songs is not None
Exemplo n.º 10
0
 def test_songs_by_album(self):
     album = 'deadweight'
     client = JellyfinClient(HOST, USERNAME, PASSWORD)
     response = client.search(album, [MediaItemType.ALBUM.value])
     search_items = JellyfinCroft.parse_search_hints_from_response(response)
     albums = JellyfinMediaItem.from_list(search_items)
     assert len(albums) == 1
     album_id = albums[0].id
     songs = client.get_songs_by_album(album_id)
     assert songs is not None
     for song in songs.json()['Items']:
         assert album == song['Album'].lower()
Exemplo n.º 11
0
 def test_songs_by_artist(self):
     artist = 'slaves'
     client = JellyfinClient(HOST, USERNAME, PASSWORD)
     response = client.search(artist, [MediaItemType.ARTIST.value])
     search_items = JellyfinCroft.parse_search_hints_from_response(response)
     artists = JellyfinMediaItem.from_list(search_items)
     assert len(artists) == 1
     artist_id = artists[0].id
     songs = client.get_songs_by_artist(artist_id)
     assert songs is not None
     for song in songs.json()['Items']:
         assert artist in [a.lower() for a in song['Artists']]
Exemplo n.º 12
0
    def test_auth_mock(self):
        with mock.patch('requests.post') as MockRequestsPost:
            auth_server_response = TestJellyfinCroft.mocked_responses[
                "jellyfin"]["3.5.2.0"]["auth_server_response"]
            response = MockResponse(200, auth_server_response)
            MockRequestsPost.return_value = response
            jellyfin_croft = JellyfinCroft(HOST, USERNAME, PASSWORD, "none")

            assert jellyfin_croft.client.auth.token is auth_server_response[
                "AccessToken"]
            assert jellyfin_croft.client.auth.user_id is auth_server_response[
                "User"]["Id"]
Exemplo n.º 13
0
    def test_instant_mix_mock(self):
        with mock.patch('requests.post') as MockRequestsPost:
            auth_server_response = TestJellyfinCroft.mocked_responses[
                "jellyfin"]["3.5.2.0"]["auth_server_response"]
            search_response = TestJellyfinCroft.mocked_responses["jellyfin"][
                "3.5.2.0"]["search_response"]
            get_songs_response = TestJellyfinCroft.mocked_responses[
                "jellyfin"]["3.5.2.0"]["get_songs_response"]

            album = "This is how the wind shifts"
            response = MockResponse(200, auth_server_response)
            MockRequestsPost.return_value = response
            jellyfin_croft = JellyfinCroft(HOST, USERNAME, PASSWORD, "none")

            with mock.patch('requests.get') as MockRequestsGet:
                responses = [
                    MockResponse(200, search_response),
                    MockResponse(200, get_songs_response)
                ]
                MockRequestsGet.side_effect = responses

                songs = jellyfin_croft.handle_intent(album, IntentType.MEDIA)
                assert songs is not None
                assert len(songs) is 1
Exemplo n.º 14
0
    def test_determine_intent(self):
        #@ToDo use pytest.parameterize
        dict_test_args = {
            IntentType.ARTIST: 'artistHere',
            IntentType.MEDIA: 'media_here'
        }

        for intent_type, intent in dict_test_args.items():
            message = defaultdict(dict)
            message['data'] = {intent_type.value: intent}

            intent, intent_type = JellyfinCroft.determine_intent(
                message['data'])
            assert intent_type == intent_type
            assert intent == intent
Exemplo n.º 15
0
    def test_handle_intent_by_playlist(self):
        with mock.patch('requests.post') as MockRequestsPost:
            auth_server_response = TestJellyfinCroft.mocked_responses[
                "jellyfin"]["3.5.2.0"]["auth_server_response"]
            response = MockResponse(200, auth_server_response)
            MockRequestsPost.return_value = response
            jellyfin_croft = JellyfinCroft(HOST, USERNAME, PASSWORD, "none")

            search_response = TestJellyfinCroft.mocked_responses["jellyfin"][
                "4.2.1.0"]["playlist_search"]["search_response"]
            get_songs_response = TestJellyfinCroft.mocked_responses[
                "jellyfin"]["4.2.1.0"]["playlist_search"]["songs_response"]
            with mock.patch('requests.get') as MockRequestsGet:
                responses = [
                    MockResponse(200, search_response),
                    MockResponse(200, get_songs_response)
                ]
                MockRequestsGet.side_effect = responses

                songs = jellyfin_croft.handle_intent("xmas music",
                                                     IntentType.PLAYLIST)

                assert songs
                assert len(songs) == 1
Exemplo n.º 16
0
    def test_handle_intent_by_artist(self):
        artist = "dance gavin dance"

        jellyfin_croft = JellyfinCroft(HOST, USERNAME, PASSWORD, "none")
        songs = jellyfin_croft.handle_intent(artist, IntentType.ARTIST)
        assert songs is not None
Exemplo n.º 17
0
 def test_auth(self):
     jellyfin_client = JellyfinCroft(HOST, USERNAME, PASSWORD, "none")
     assert jellyfin_client.client.auth is not None
Exemplo n.º 18
0
    def test_instant_mix_live(self):
        album = "This is how the wind shifts"
        jellyfin_croft = JellyfinCroft(HOST, USERNAME, PASSWORD, "none")

        songs = jellyfin_croft.instant_mix_for_media(album)
        assert songs is not None
Exemplo n.º 19
0
    def test_handle_intent_by_playlist(self):
        playlist = "xmas music"

        jellyfin_croft = JellyfinCroft(HOST, USERNAME, PASSWORD, "none")
        songs = jellyfin_croft.handle_intent(playlist, IntentType.PLAYLIST)
        assert songs is not None
Exemplo n.º 20
0
    def test_handle_intent_by_album(self):
        album = "deadweight"

        jellyfin_croft = JellyfinCroft(HOST, USERNAME, PASSWORD, "none")
        songs = jellyfin_croft.handle_intent(album, IntentType.ALBUM)
        assert songs is not None