当前位置: 首页>>代码示例>>Python>>正文


Python MockObject.get_community方法代码示例

本文整理汇总了Python中Tribler.Test.Core.base_test.MockObject.get_community方法的典型用法代码示例。如果您正苦于以下问题:Python MockObject.get_community方法的具体用法?Python MockObject.get_community怎么用?Python MockObject.get_community使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Tribler.Test.Core.base_test.MockObject的用法示例。


在下文中一共展示了MockObject.get_community方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_remove_torrent_playlist

# 需要导入模块: from Tribler.Test.Core.base_test import MockObject [as 别名]
# 或者: from Tribler.Test.Core.base_test.MockObject import get_community [as 别名]
    def test_remove_torrent_playlist(self):
        """
        Testing whether a torrent can be successfully removed from a playlist
        """
        mock_channel_community = MockObject()
        mock_channel_community.called_remove = False
        my_channel_id = self.create_fake_channel("channel", "")

        def verify_torrent_removed(_):
            self.assertTrue(mock_channel_community.called_remove)

        def modify_remove_called(playlist_id, torrents):
            self.assertEqual(playlist_id, 1)
            self.assertEqual(torrents, [42])
            mock_channel_community.called_remove = True

        mock_channel_community.remove_playlist_torrents = modify_remove_called
        mock_dispersy = MockObject()
        mock_dispersy.get_community = lambda _: mock_channel_community
        self.session.get_dispersy_instance = lambda: mock_dispersy

        self.create_playlist(my_channel_id, 1234, 42, "test playlist", "test description")

        yield self.do_request('channels/discovered/%s/playlists/1/abcd' % 'fakedispersyid'.encode('hex'),
                              expected_code=404, request_type='DELETE')

        torrent_list = [[my_channel_id, 1, 1, ('a' * 40).decode('hex'), 1460000000, "ubuntu-torrent.iso",
                         [['file1.txt', 42]], []]]
        self.insert_torrents_into_channel(torrent_list)
        self.insert_torrent_into_playlist(1234, ('a' * 40).decode('hex'))

        yield self.do_request('channels/discovered/%s/playlists/1/%s' % ('fakedispersyid'.encode('hex'), 'a' * 40),
                              expected_code=200, request_type='DELETE', expected_json={'removed': True})\
            .addCallback(verify_torrent_removed)
开发者ID:synctext,项目名称:tribler,代码行数:36,代码来源:test_channels_playlist_endpoint.py

示例2: test_edit_playlist

# 需要导入模块: from Tribler.Test.Core.base_test import MockObject [as 别名]
# 或者: from Tribler.Test.Core.base_test.MockObject import get_community [as 别名]
    def test_edit_playlist(self):
        """
        Testing whether a playlist is correctly modified
        """
        mock_channel_community = MockObject()
        mock_channel_community.called_modify = False
        my_channel_id = self.create_fake_channel("channel", "")

        def verify_playlist_modified(_):
            self.assertTrue(mock_channel_community.called_modify)

        def modify_playlist_called(playlist_id, modifications):
            self.assertEqual(playlist_id, 1)
            self.assertEqual(modifications['name'], 'test')
            self.assertEqual(modifications['description'], 'test')
            mock_channel_community.called_modify = True

        mock_channel_community.modifyPlaylist = modify_playlist_called
        mock_dispersy = MockObject()
        mock_dispersy.get_community = lambda _: mock_channel_community
        self.session.get_dispersy_instance = lambda: mock_dispersy

        self.create_playlist(my_channel_id, 1234, 42, "test playlist", "test description")

        post_params = {'name': 'test', 'description': 'test'}
        return self.do_request('channels/discovered/%s/playlists/1' % 'fakedispersyid'.encode('hex'),
                               expected_code=200, expected_json={"modified": True}, post_data=post_params,
                               request_type='POST').addCallback(verify_playlist_modified)
开发者ID:synctext,项目名称:tribler,代码行数:30,代码来源:test_channels_playlist_endpoint.py

示例3: test_create_playlist

# 需要导入模块: from Tribler.Test.Core.base_test import MockObject [as 别名]
# 或者: from Tribler.Test.Core.base_test.MockObject import get_community [as 别名]
    def test_create_playlist(self):
        """
        Testing whether the API can create a new playlist in a given channel
        """
        mock_channel_community = MockObject()
        mock_channel_community.called_create = False
        self.create_fake_channel("channel", "")

        def verify_playlist_created(_):
            self.assertTrue(mock_channel_community.called_create)

        def create_playlist_called(name, description, _):
            self.assertEqual(name, "test1")
            self.assertEqual(description, "test2")
            mock_channel_community.called_create = True

        mock_channel_community.create_playlist = create_playlist_called
        mock_dispersy = MockObject()
        mock_dispersy.get_community = lambda _: mock_channel_community
        self.session.get_dispersy_instance = lambda: mock_dispersy

        expected_json = {"created": True}
        post_params = {"name": "test1", "description": "test2"}

        return self.do_request('channels/discovered/%s/playlists' % 'fakedispersyid'.encode('hex'), expected_code=200,
                               expected_json=expected_json, post_data=post_params, request_type='PUT')\
            .addCallback(verify_playlist_created)
开发者ID:synctext,项目名称:tribler,代码行数:29,代码来源:test_channels_playlist_endpoint.py

示例4: test_remove_torrent_no_community

# 需要导入模块: from Tribler.Test.Core.base_test import MockObject [as 别名]
# 或者: from Tribler.Test.Core.base_test.MockObject import get_community [as 别名]
    def test_remove_torrent_no_community(self):
        """
        Testing whether an error 404 is returned when a torrent from a playlist without channel community
        """
        def mocked_get_community(_):
            raise CommunityNotFoundException("abcd")

        mock_dispersy = MockObject()
        mock_dispersy.get_community = mocked_get_community
        self.session.get_dispersy_instance = lambda: mock_dispersy

        channel_cid = 'fakedispersyid'.encode('hex')
        my_channel_id = self.create_my_channel("my channel", "this is a short description")
        self.create_playlist(my_channel_id, 1234, 42, "test playlist", "test description")
        return self.do_request('channels/discovered/%s/playlists/1/abcd' % channel_cid,
                               expected_code=404, request_type='DELETE')
开发者ID:synctext,项目名称:tribler,代码行数:18,代码来源:test_channels_playlist_endpoint.py

示例5: test_add_torrent_no_playlist

# 需要导入模块: from Tribler.Test.Core.base_test import MockObject [as 别名]
# 或者: from Tribler.Test.Core.base_test.MockObject import get_community [as 别名]
    def test_add_torrent_no_playlist(self):
        """
        Testing whether an error 404 is returned when a torrent is added to a non-existing playlist
        """
        mock_channel_community = MockObject()
        mock_channel_community.called_add = False
        self.create_fake_channel("channel", "")

        mock_dispersy = MockObject()
        mock_dispersy.get_community = lambda _: mock_channel_community
        self.session.get_dispersy_instance = lambda: mock_dispersy

        channel_cid = 'fakedispersyid'.encode('hex')
        self.create_my_channel("my channel", "this is a short description")
        return self.do_request('channels/discovered/%s/playlists/1/abcd' % channel_cid,
                               expected_code=404, request_type='PUT')
开发者ID:synctext,项目名称:tribler,代码行数:18,代码来源:test_channels_playlist_endpoint.py

示例6: test_edit_playlist_no_community

# 需要导入模块: from Tribler.Test.Core.base_test import MockObject [as 别名]
# 或者: from Tribler.Test.Core.base_test.MockObject import get_community [as 别名]
    def test_edit_playlist_no_community(self):
        """
        Testing whether an error 404 is returned when a playlist is edited from a channel without community
        """
        def mocked_get_community(_):
            raise CommunityNotFoundException("abcd")

        mock_dispersy = MockObject()
        mock_dispersy.get_community = mocked_get_community
        self.session.get_dispersy_instance = lambda: mock_dispersy

        post_params = {'name': 'test', 'description': 'test'}
        channel_cid = 'fakedispersyid'.encode('hex')
        my_channel_id = self.create_my_channel("my channel", "this is a short description")
        self.create_playlist(my_channel_id, 1234, 42, "test playlist", "test description")
        return self.do_request('channels/discovered/%s/playlists/1' % channel_cid,
                               expected_code=404, request_type='POST', post_data=post_params)
开发者ID:synctext,项目名称:tribler,代码行数:19,代码来源:test_channels_playlist_endpoint.py

示例7: test_create_playlist_no_cmty

# 需要导入模块: from Tribler.Test.Core.base_test import MockObject [as 别名]
# 或者: from Tribler.Test.Core.base_test.MockObject import get_community [as 别名]
    def test_create_playlist_no_cmty(self):
        """
        Testing whether the API returns error 404 if the the channel community is missing when creating a new playlist
        """
        self.create_my_channel("my channel", "this is a short description")
        expected_json = {"error": "description parameter missing"}
        post_params = {"name": "test1", "description": "test2"}

        def mocked_get_community(_):
            raise CommunityNotFoundException("abcd")

        mock_dispersy = MockObject()
        mock_dispersy.get_community = mocked_get_community
        self.session.get_dispersy_instance = lambda: mock_dispersy

        return self.do_request('channels/discovered/%s/playlists' % 'fakedispersyid'.encode('hex'), expected_code=404,
                               expected_json=expected_json, post_data=post_params, request_type='PUT')
开发者ID:synctext,项目名称:tribler,代码行数:19,代码来源:test_channels_playlist_endpoint.py

示例8: test_delete_playlist

# 需要导入模块: from Tribler.Test.Core.base_test import MockObject [as 别名]
# 或者: from Tribler.Test.Core.base_test.MockObject import get_community [as 别名]
    def test_delete_playlist(self):
        """
        Testing whether a playlist is correctly removed
        """
        mock_channel_community = MockObject()
        mock_channel_community.called_remove = False
        mock_channel_community.called_remove_torrents = False
        my_channel_id = self.create_fake_channel("channel", "")

        def verify_playlist_removed(_):
            self.assertTrue(mock_channel_community.called_remove_torrents)
            self.assertTrue(mock_channel_community.called_remove)

        def remove_playlist_called(playlists):
            self.assertEqual(playlists, [1234])
            mock_channel_community.called_remove = True

        def remove_torrents_called(playlist_id, torrents):
            self.assertEqual(playlist_id, 1234)
            self.assertEqual(torrents, [42])
            mock_channel_community.called_remove_torrents = True

        mock_channel_community.remove_playlists = remove_playlist_called
        mock_channel_community.remove_playlist_torrents = remove_torrents_called
        mock_dispersy = MockObject()
        mock_dispersy.get_community = lambda _: mock_channel_community
        self.session.get_dispersy_instance = lambda: mock_dispersy

        # Create a playlist and add a torrent to it
        self.create_playlist(my_channel_id, 1234, 42, "test playlist", "test description")
        torrent_list = [[my_channel_id, 1, 1, ('a' * 40).decode('hex'), 1460000000, "ubuntu-torrent.iso",
                         [['file1.txt', 42]], []]]
        self.insert_torrents_into_channel(torrent_list)
        self.insert_torrent_into_playlist(1234, ('a' * 40).decode('hex'))

        return self.do_request('channels/discovered/%s/playlists/1' % 'fakedispersyid'.encode('hex'),
                               expected_code=200, expected_json={"removed": True},
                               request_type='DELETE').addCallback(verify_playlist_removed)
开发者ID:synctext,项目名称:tribler,代码行数:40,代码来源:test_channels_playlist_endpoint.py


注:本文中的Tribler.Test.Core.base_test.MockObject.get_community方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。