示例#1
0
    def test_str(self, lib_mock):
        sp_link = spotify.ffi.cast('sp_link *', 42)
        lib_mock.sp_link_create_from_string.return_value = sp_link
        string = 'foo'

        lib_mock.sp_link_as_string.side_effect = tests.buffer_writer(string)
        link = spotify.Link(self.session, string)

        self.assertEqual(str(link), link.uri)
示例#2
0
    def test_url_expands_uri_to_http_url(self, lib_mock):
        sp_link = spotify.ffi.cast('sp_link *', 42)
        lib_mock.sp_link_create_from_string.return_value = sp_link
        string = 'spotify:track:foo'
        lib_mock.sp_link_as_string.side_effect = tests.buffer_writer(string)
        link = spotify.Link(self.session, string)

        result = link.url

        self.assertEqual(result, 'https://open.spotify.com/track/foo')
示例#3
0
    def test_repr(self, lib_mock):
        sp_link = spotify.ffi.new('int *')
        lib_mock.sp_link_create_from_string.return_value = sp_link
        string = 'foo'

        lib_mock.sp_link_as_string.side_effect = tests.buffer_writer(string)
        link = spotify.Link(string)

        result = repr(link)

        self.assertEqual(result, 'Link(%r)' % string)
示例#4
0
    def test_remembered_user_name_grows_buffer_to_fit_username(self, lib_mock):
        username = '******' * 100

        lib_mock.sp_session_remembered_user.side_effect = (
            tests.buffer_writer(username))
        session = tests.create_real_session(lib_mock)

        result = session.remembered_user_name

        lib_mock.sp_session_remembered_user.assert_called_with(
            session._sp_session, mock.ANY, mock.ANY)
        self.assertEqual(result, username)
示例#5
0
    def test_uri_grows_buffer_to_fit_link(self, lib_mock):
        sp_link = spotify.ffi.cast('sp_link *', 42)
        lib_mock.sp_link_create_from_string.return_value = sp_link
        string = 'foo' * 100

        lib_mock.sp_link_as_string.side_effect = tests.buffer_writer(string)
        link = spotify.Link(self.session, string)

        result = link.uri

        lib_mock.sp_link_as_string.assert_called_with(sp_link, mock.ANY,
                                                      mock.ANY)
        self.assertEqual(result, string)
示例#6
0
    def test_as_playlist_if_starred(self, playlist_lib_mock, lib_mock):
        uri = 'spotify:user:alice:starred'
        sp_link = spotify.ffi.cast('sp_link *', 42)
        lib_mock.sp_link_create_from_string.return_value = sp_link
        lib_mock.sp_link_type.return_value = spotify.LinkType.STARRED
        lib_mock.sp_link_as_string.side_effect = tests.buffer_writer(uri)
        sp_playlist = spotify.ffi.cast('sp_playlist *', 43)
        lib_mock.sp_session_starred_for_user_create.return_value = sp_playlist

        link = spotify.Link(self.session, uri)
        self.assertEqual(link.as_playlist()._sp_playlist, sp_playlist)

        lib_mock.sp_session_starred_for_user_create.assert_called_once_with(
            self.session._sp_session, b'alice')