def test_diag_public_server_info_bad_host(self):

        emby_croft = EmbyCroft('badhostHere', USERNAME, PASSWORD, diagnostic=True)
        connection_success, info = emby_croft.diag_public_server_info()

        assert not connection_success
        assert info is not None
示例#2
0
    def test_parsing_common_phrase_mock(self):
        with mock.patch('requests.post') as MockRequestsPost:
            auth_server_response = TestEmbyCroft.mocked_responses["emby"][
                "3.5.2.0"]["auth_server_response"]
            response = MockResponse(200, auth_server_response)
            MockRequestsPost.return_value = response
            emby_croft = EmbyCroft(HOST, USERNAME, PASSWORD)

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

                search_response = TestEmbyCroft.mocked_responses["emby"][
                    "3.5.2.0"]["common_play"][match_type]["search_response"]
                get_songs_response = TestEmbyCroft.mocked_responses["emby"][
                    "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 = emby_croft.parse_common_phrase(phrase)

                    assert match_type == TestEmbyCroft.common_phrases[phrase][
                        "match_type"]
                    assert songs
    def test_diag_public_server_info_happy_path(self):

        emby_croft = EmbyCroft(HOST, USERNAME, PASSWORD, diagnostic=True)
        connection_success, info = emby_croft.diag_public_server_info()

        assert connection_success
        assert info is not None
    def test_handle_intent_by_song(self):
        song = "And I Told Them I Invented Times New Roman"

        emby_croft = EmbyCroft(HOST, USERNAME, PASSWORD)
        songs = emby_croft.handle_intent(song, IntentType.SONG)
        assert songs is not None
        assert len(songs) is 1
示例#5
0
    def test_host_normalize(self):

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

        # assert that if http exists then no change
        hostname = "hTtps://hasProtocol"
        assert hostname == EmbyCroft.normalize_host(hostname)
    def test_parsing_common_phrase(self):

        emby_croft = EmbyCroft(HOST, USERNAME, PASSWORD)

        for phrase in TestEmbyCroft.common_phrases:
            match_type, songs = emby_croft.parse_common_phrase(phrase)

            assert match_type == TestEmbyCroft.common_phrases[phrase]['match_type']
            assert songs
    def test_diag_public_server_info_bad_host_mock(self):

        emby_croft = EmbyCroft('badhostHere', USERNAME, PASSWORD, diagnostic=True)

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

            assert not connection_success
            assert info is not None
示例#8
0
    def test_search_for_song(self):
        song = "And I Told Them I Invented Times New Roman"

        emby_croft = EmbyCroft(HOST, USERNAME, PASSWORD)
        songs = emby_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
    def test_diag_public_server_info_happy_path_mock(self):

        emby_croft = EmbyCroft(HOST, USERNAME, PASSWORD, diagnostic=True)

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

            assert connection_success
            assert info is not None
示例#10
0
    def test_handle_intent_by_song_mock(self):
        with mock.patch('requests.post') as MockRequestsPost:
            auth_server_response = TestEmbyCroft.mocked_responses["emby"]["3.5.2.0"]["auth_server_response"]
            response = MockResponse(200, auth_server_response)
            MockRequestsPost.return_value = response
            emby_croft = EmbyCroft(HOST, USERNAME, PASSWORD)

            search_response = TestEmbyCroft.mocked_responses["emby"]["4.4.3.0"]["song_search"][
                "search_response"]
            with mock.patch('requests.get') as MockRequestsGet:
                responses = [MockResponse(200, search_response)]
                MockRequestsGet.side_effect = responses

                songs = emby_croft.handle_intent("test", IntentType.SONG)

                assert songs
                assert len(songs) == 1
示例#11
0
    def test_auth_mock(self):
        with mock.patch('requests.post') as MockRequestsPost:
            auth_server_response = TestEmbyCroft.mocked_responses["emby"]["3.5.2.0"]["auth_server_response"]
            response = MockResponse(200, auth_server_response)
            MockRequestsPost.return_value = response
            emby_croft = EmbyCroft(HOST, USERNAME, PASSWORD)

            assert emby_croft.client.auth.token is auth_server_response["AccessToken"]
            assert emby_croft.client.auth.user_id is auth_server_response["User"]["Id"]
示例#12
0
    def test_instant_mix_mock(self):
        with mock.patch('requests.post') as MockRequestsPost:
            auth_server_response = TestEmbyCroft.mocked_responses["emby"]["3.5.2.0"]["auth_server_response"]
            search_response = TestEmbyCroft.mocked_responses["emby"]["3.5.2.0"]["search_response"]
            get_songs_response = TestEmbyCroft.mocked_responses["emby"]["3.5.2.0"]["get_songs_response"]

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

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

                songs = emby_croft.handle_intent(album, IntentType.MEDIA)
                assert songs is not None
                assert len(songs) is 1
示例#13
0
    def test_find_songs_by_artist_mock(self):
        with mock.patch('requests.post') as MockRequestsPost:
            auth_server_response = TestEmbyCroft.mocked_responses["emby"]["3.5.2.0"]["auth_server_response"]
            response = MockResponse(200, auth_server_response)
            MockRequestsPost.return_value = response
            emby_croft = EmbyCroft(HOST, USERNAME, PASSWORD)

            search_response = TestEmbyCroft.mocked_responses["emby"]["3.5.2.0"]["artist_search"][
                "search_response"]
            get_songs_response = TestEmbyCroft.mocked_responses["emby"]["3.5.2.0"]["artist_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 = emby_croft.handle_intent("dance gavin dance", IntentType.ARTIST)

                assert songs
                assert len(songs) == 4
示例#14
0
 def test_songs_by_playlist(self):
     playlist = 'Xmas Music'
     client = EmbyClient(HOST, USERNAME, PASSWORD)
     response = client.search(playlist, [MediaItemType.PLAYLIST.value])
     search_items = EmbyCroft.parse_search_hints_from_response(response)
     playlists = EmbyMediaItem.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
 def test_songs_by_album(self):
     album = 'deadweight'
     client = EmbyClient(HOST, USERNAME, PASSWORD)
     response = client.search(album, [MediaItemType.ALBUM.value])
     search_items = EmbyCroft.parse_search_hints_from_response(response)
     albums = EmbyMediaItem.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()
 def test_songs_by_artist(self):
     artist = 'slaves'
     client = EmbyClient(HOST, USERNAME, PASSWORD)
     response = client.search(artist, [MediaItemType.ARTIST.value])
     search_items = EmbyCroft.parse_search_hints_from_response(response)
     artists = EmbyMediaItem.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']]
示例#17
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 = EmbyCroft.determine_intent(message['data'])
            assert intent_type == intent_type
            assert intent == intent
示例#18
0
    def test_handle_intent_by_playlist(self):
        playlist = "xmas music"

        emby_croft = EmbyCroft(HOST, USERNAME, PASSWORD)
        songs = emby_croft.handle_intent(playlist, IntentType.PLAYLIST)
        assert songs is not None
示例#19
0
 def test_auth(self):
     emby_client = EmbyCroft(HOST, USERNAME, PASSWORD)
     assert emby_client.client.auth is not None
示例#20
0
    def test_handle_intent_by_album(self):
        album = "deadweight"

        emby_croft = EmbyCroft(HOST, USERNAME, PASSWORD)
        songs = emby_croft.handle_intent(album, IntentType.ALBUM)
        assert songs is not None
示例#21
0
    def test_handle_intent_by_artist(self):
        artist = "dance gavin dance"

        emby_croft = EmbyCroft(HOST, USERNAME, PASSWORD)
        songs = emby_croft.handle_intent(artist, IntentType.ARTIST)
        assert songs is not None
示例#22
0
    def test_instant_mix_live(self):
        album = "This is how the wind shifts"
        emby_croft = EmbyCroft(HOST, USERNAME, PASSWORD)

        songs = emby_croft.instant_mix_for_media(album)
        assert songs is not None