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


Python MockObject.called_add方法代码示例

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


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

示例1: test_add_torrent_no_playlist

# 需要导入模块: from Tribler.Test.Core.base_test import MockObject [as 别名]
# 或者: from Tribler.Test.Core.base_test.MockObject import called_add [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

示例2: test_add_torrent_playlist

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

        def verify_torrent_added(_):
            self.assertTrue(mock_channel_community.called_add)

        def modify_add_called(playlist_id, torrents):
            self.assertEqual(playlist_id, 1)
            self.assertEqual(torrents, [('a' * 40).decode('hex')])
            mock_channel_community.called_add = True

        mock_channel_community.create_playlist_torrents = modify_add_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='PUT')

        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)

        yield self.do_request('channels/discovered/%s/playlists/1/%s' % ('fakedispersyid'.encode('hex'), 'a' * 40),
                              expected_code=200, expected_json={'added': True}, request_type='PUT')\
            .addCallback(verify_torrent_added)

        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=409, request_type='PUT')
开发者ID:synctext,项目名称:tribler,代码行数:40,代码来源:test_channels_playlist_endpoint.py


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