Пример #1
0
 def test_add_directory_items(self):
     list_item1 = mock.MagicMock()
     context1 = ListContext(
         [{
             'url': 'plugin://foo',
             'list_item': list_item1,
             'is_folder': True
         }],
         True,
         True,
         True,
         (0,),
         50,
         'movies'
     )
     plugin = Plugin('test.plugin')
     plugin._handle = 1
     plugin.create_list_item = mock.MagicMock()
     plugin._add_directory_items(context1)
     mock_xbmcplugin.setContent.assert_called_with(1, 'movies')
     mock_xbmcplugin.addDirectoryItem.assert_called_with(1, 'plugin://foo', list_item1, True)
     mock_xbmcplugin.addSortMethod.assert_called_with(1, 0)
     mock_xbmcplugin.endOfDirectory.assert_called_with(1, True, True, True)
     mock_xbmc.executebuiltin.assert_called_with('Container.SetViewMode(50)')
     mock_xbmcplugin.addDirectoryItems.reset_mock()
     context2 = ListContext(
         [{
             'url' : 'plugin://foo',
             'label': 'Foo',
             'is_folder': True
         }],
         True,
         True,
         True,
         (0,),
         50,
         'movies'
     )
     list_item2 = mock.MagicMock()
     plugin.create_list_item.return_value = list_item2
     plugin._add_directory_items(context2)
     mock_xbmcplugin.addDirectoryItem.assert_called_with(1, 'plugin://foo', list_item2, True)
     mock_xbmcplugin.addDirectoryItems.reset_mock()
     list_item2.reset_mock()
     context3 = ListContext(
         [{
             'url' : 'plugin://foo',
             'label': 'Foo',
             'is_playable': True
         }],
         True,
         True,
         True,
         (0,),
         50,
         'movies'
     )
     plugin._add_directory_items(context3)
     list_item2.setProperty.assert_called_with('IsPlayable', 'true')
     mock_xbmcplugin.addDirectoryItem.assert_called_with(1, 'plugin://foo', list_item2, False)
Пример #2
0
 def test_add_directory_items(self):
     list_item1 = mock.MagicMock()
     context1 = ListContext([{
         'url': 'plugin://foo',
         'list_item': list_item1,
         'is_folder': True
     }], True, True, True, (0, ), 50, 'movies')
     plugin = Plugin('test.plugin')
     plugin._handle = 1
     plugin.create_list_item = mock.MagicMock()
     plugin._add_directory_items(context1)
     mock_xbmcplugin.setContent.assert_called_with(1, 'movies')
     mock_xbmcplugin.addDirectoryItems.assert_called_with(
         1, [('plugin://foo', list_item1, True)], 1)
     mock_xbmcplugin.addSortMethod.assert_called_with(1, 0)
     mock_xbmcplugin.endOfDirectory.assert_called_with(1, True, True, True)
     mock_xbmc.executebuiltin.assert_called_with(
         'Container.SetViewMode(50)')
     mock_xbmcplugin.addDirectoryItems.reset_mock()
     context2 = ListContext([{
         'url': 'plugin://foo',
         'label': 'Foo',
         'is_folder': True
     }], True, True, True, (0, ), 50, 'movies')
     list_item2 = mock.MagicMock()
     plugin.create_list_item.return_value = list_item2
     plugin._add_directory_items(context2)
     mock_xbmcplugin.addDirectoryItems.assert_called_with(
         1, [('plugin://foo', list_item2, True)], 1)
     mock_xbmcplugin.addDirectoryItems.reset_mock()
     list_item2.reset_mock()
     context3 = ListContext([{
         'url': 'plugin://foo',
         'label': 'Foo',
         'is_playable': True
     }], True, True, True, (0, ), 50, 'movies')
     plugin._add_directory_items(context3)
     list_item2.setProperty.assert_called_with('IsPlayable', 'true')
     mock_xbmcplugin.addDirectoryItems.assert_called_with(
         1, [('plugin://foo', list_item2, False)], 1)
Пример #3
0
    def test_run(self):
        plugin = Plugin('test.plugin')
        plugin.create_listing = mock.MagicMock()
        plugin.resolve_url = mock.MagicMock()
        plugin._add_directory_items = mock.MagicMock()
        plugin._set_resolved_url = mock.MagicMock()
        mock_actions = mock.MagicMock()
        # Test calling 'root' action
        with mock.patch('simpleplugin.sys.argv', ['test.plugin', '1', '']):
            mock_actions.root.return_value = [{'label': 'root'}]
            plugin.actions['root'] = mock_actions.root
            plugin.run(category='Foo')
            mock_actions.root.assert_called_with({})
            plugin.create_listing.assert_called_with([{'label': 'root'}])
            # Test setting plugin category
            mock_xbmcplugin.setPluginCategory.assert_called_with(1, 'Foo')
        # Test calling a child action returning list or generator
        with mock.patch('simpleplugin.sys.argv', ['test.plugin', '1', '?action=foo&param=bar']):
            plugin.create_listing.reset_mock()
            mock_actions.foo.return_value = [{'label': 'foo'}]
            plugin.actions['foo'] = mock_actions.foo
            plugin.run()
            mock_actions.foo.assert_called_with({'action': 'foo', 'param': 'bar'})
            plugin.create_listing.assert_called_with([{'label': 'foo'}])
            plugin.create_listing.reset_mock()
            generator = test_generator()
            mock_actions.foo.return_value = generator
            plugin.run()
            mock_actions.foo.assert_called_with({'action': 'foo', 'param': 'bar'})
            plugin.create_listing.assert_called_with(generator)
        # Test calling a child action returning a str
        with mock.patch('simpleplugin.sys.argv', ['test.plugin', '1', '?action=play_str']):
            mock_actions.play_str.return_value = '/play/path'
            plugin.actions['play_str'] = mock_actions.play_str
            plugin.run()
            plugin.resolve_url.assert_called_with('/play/path')
        # Test calling a child action returning ListContext namedtuple
        with mock.patch('simpleplugin.sys.argv', ['test.plugin', '1', '?action=tuple_listing']):
            plugin._add_directory_items.reset_mock()
            list_context = ListContext(
                [{
                    'url': 'plugin://foo',
                    'label': 'Foo',
                    'is_folder': True
                }],
                True,
                True,
                True,
                (0,),
                50,
                'movies'
            )

            mock_actions.dict_listing.return_value = list_context
            plugin.actions['tuple_listing'] = mock_actions.dict_listing
            plugin.run()
            plugin._add_directory_items.assert_called_with(list_context)
        # Test calling a child action returning PlayContext namedtuple
        with mock.patch('simpleplugin.sys.argv', ['test.plugin', '1', '?action=tuple_play']):
            plugin._set_resolved_url.reset_mock()
            play_context = PlayContext('http://foo.bar', None, True)
            mock_actions.dict_play.return_value = play_context
            plugin.actions['tuple_play'] = mock_actions.dict_play
            plugin.run()
            plugin._set_resolved_url.assert_called_with(play_context)
        # Test unregistered action
        with mock.patch('simpleplugin.sys.argv', ['test.plugin', '1', '?action=invalid']):
            self.assertRaises(SimplePluginError, plugin.run)
Пример #4
0
    def test_run(self):
        plugin = Plugin('test.plugin')
        plugin.create_listing = mock.MagicMock()
        plugin.resolve_url = mock.MagicMock()
        plugin._add_directory_items = mock.MagicMock()
        plugin._set_resolved_url = mock.MagicMock()
        mock_actions = mock.MagicMock()
        # Test calling 'root' action
        with mock.patch('simpleplugin.sys.argv', ['test.plugin', '1', '']):
            mock_actions.root.return_value = [{'label': 'root'}]
            plugin.actions['root'] = mock_actions.root
            plugin.run(category='Foo')
            mock_actions.root.assert_called_with({})
            plugin.create_listing.assert_called_with([{'label': 'root'}])
            # Test setting plugin category
            mock_xbmcplugin.setPluginCategory.assert_called_with(1, 'Foo')
        # Test calling a child action returning list or generator
        with mock.patch('simpleplugin.sys.argv',
                        ['test.plugin', '1', '?action=foo&param=bar']):
            plugin.create_listing.reset_mock()
            mock_actions.foo.return_value = [{'label': 'foo'}]
            plugin.actions['foo'] = mock_actions.foo
            plugin.run()
            mock_actions.foo.assert_called_with({
                'action': 'foo',
                'param': 'bar'
            })
            plugin.create_listing.assert_called_with([{'label': 'foo'}])
            plugin.create_listing.reset_mock()
            generator = test_generator()
            mock_actions.foo.return_value = generator
            plugin.run()
            mock_actions.foo.assert_called_with({
                'action': 'foo',
                'param': 'bar'
            })
            plugin.create_listing.assert_called_with(generator)
        # Test calling a child action returning a str
        with mock.patch('simpleplugin.sys.argv',
                        ['test.plugin', '1', '?action=play_str']):
            mock_actions.play_str.return_value = '/play/path'
            plugin.actions['play_str'] = mock_actions.play_str
            plugin.run()
            plugin.resolve_url.assert_called_with('/play/path')
        # Test calling a child action returning ListContext namedtuple
        with mock.patch('simpleplugin.sys.argv',
                        ['test.plugin', '1', '?action=tuple_listing']):
            plugin._add_directory_items.reset_mock()
            list_context = ListContext([{
                'url': 'plugin://foo',
                'label': 'Foo',
                'is_folder': True
            }], True, True, True, (0, ), 50, 'movies')

            mock_actions.dict_listing.return_value = list_context
            plugin.actions['tuple_listing'] = mock_actions.dict_listing
            plugin.run()
            plugin._add_directory_items.assert_called_with(list_context)
        # Test calling a child action returning PlayContext namedtuple
        with mock.patch('simpleplugin.sys.argv',
                        ['test.plugin', '1', '?action=tuple_play']):
            plugin._set_resolved_url.reset_mock()
            play_context = PlayContext('http://foo.bar', None, True)
            mock_actions.dict_play.return_value = play_context
            plugin.actions['tuple_play'] = mock_actions.dict_play
            plugin.run()
            plugin._set_resolved_url.assert_called_with(play_context)
        # Test unregistered action
        with mock.patch('simpleplugin.sys.argv',
                        ['test.plugin', '1', '?action=invalid']):
            self.assertRaises(SimplePluginError, plugin.run)