Example #1
0
 def test_added_to_playlist(self):
     list_items = [
         ListItem('Grape Stomp'),
         ListItem('Boom Goes the Dynamite'),
     ]
     items = self.m.add_to_playlist(list_items)
     for item, call_args in zip(items,
                                self.mock_playlist.add.call_args_list):
         self.assertEqual((item.get_path(), item.as_xbmc_listitem(), 0),
                          call_args)
Example #2
0
    def test_display_listitems_with_multiple_items(self):
        items = [{
            'label': 'A_LABEL',
            'path': 'A_PATH'
        }, {
            'label': 'B_LABEL',
            'path': 'B_PATH'
        }, {
            'label': 'C_LABEL',
            'path': 'C_PATH'
        }]
        list_items = [ListItem.from_dict(**item) for item in items]

        with patch('sys.stdout', new=StringIO.StringIO()) as stdout:
            console.display_listitems(list_items, 'PARENT_URL')

        output = stdout.getvalue().strip()
        self.assertEquals(
            output, '====================\n'
            'Current URL: PARENT_URL\n'
            '--------------------\n'
            ' #  Label   Path\n'
            '--------------------\n'
            '[0] A_LABEL (A_PATH)\n'
            '[1] B_LABEL (B_PATH)\n'
            '[2] C_LABEL (C_PATH)\n'
            '--------------------')
Example #3
0
    def test_add_items_item_specific_info_type(self, add_directory_items,
                                               from_dict):
        plugin = MixedIn(storage_path=tempfile.mkdtemp(),
                         addon=Mock(),
                         added_items=[],
                         request=Mock(),
                         handle=0,
                         info_type='pictures')
        items = [{
            'label': 'Course 1',
            'path': 'plugin.image.test/foo',
            'info_type': 'music'
        }]
        results = plugin.add_items(items)

        self.assertTrue(add_directory_items.called)
        calls = [
            call(label='Course 1',
                 path='plugin.image.test/foo',
                 info_type='music'),
        ]
        from_dict.assert_has_calls(calls)

        list_items = [ListItem.from_dict(**item) for item in items]
        self.assertEqual(results, list_items)
Example #4
0
    def test_display_video(self):
        items = [{'label': 'X', 'path': 'Y'}, {'label': 'Z', 'path': 'Q'}]
        list_items = [ListItem.from_dict(**item) for item in items]

        with patch('sys.stdout', new=StringIO.StringIO()) as stdout:
            console.display_video(list_items)

        output = stdout.getvalue().strip()
        self.assertEquals(
            output, '-------------------\n'
            'Playing Media Z (Q)\n'
            '-------------------\n'
            '[0] X (Y)')
Example #5
0
    def test_add_items_no_info_type(self, add_directory_items, from_dict):
        plugin = MixedIn(storage_path=tempfile.mkdtemp(), addon=Mock(),
                         added_items=[], request=Mock(), handle=0)
        items = [
            {'label': 'Course 1', 'path': 'plugin.image.test/foo'}
        ]
        results = plugin.add_items(items)

        self.assertTrue(add_directory_items.called)
        calls = [
            call(label='Course 1', path='plugin.image.test/foo',
                 info_type='video'),
        ]
        from_dict.assert_has_calls(calls)

        list_items = [ListItem.from_dict(**item) for item in items]
        self.assertEqual(results, list_items)
Example #6
0
    def test_display_listitems_with_single_item(self):
        items = [{'label': '..', 'path': 'Y'}, {'label': 'Z', 'path': 'Q'}]
        list_items = [ListItem.from_dict(**item) for item in items]

        with patch('sys.stdout', new=StringIO.StringIO()) as stdout:
            console.display_listitems(list_items, 'PARENT_URL')

        output = stdout.getvalue().strip()
        self.assertEquals(
            output, '==========\n'
            'Current URL: PARENT_URL\n'
            '----------\n'
            ' #  Label Path\n'
            '----------\n'
            '[0] .. (Y)\n'
            '[1] Z  (Q)\n'
            '----------')
Example #7
0
    def test_display_video_form_listitems(self):
        items = [{
            'label': '..',
            'path': 'Y'
        }, {
            'label': 'Z',
            'path': 'Q',
            'played': True
        }]
        list_items = [ListItem.from_dict(**item) for item in items]
        list_items[1].set_played(True)

        with patch('sys.stdout', new=StringIO.StringIO()) as stdout:
            console.display_listitems(list_items, "PARENT_URL")

        output = stdout.getvalue().strip()
        self.assertEquals(
            output, '-------------------\n'
            'Playing Media Z (Q)\n'
            '-------------------\n'
            '[0] .. (Y)')
Example #8
0
    def test_return_values(self, mock_list_item):
        # Verify dicts are transformed into listitems
        dict_items = [
            {
                'label': 'Grape Stomp'
            },
            {
                'label': 'Boom Goes the Dynamite'
            },
        ]
        self.m.add_to_playlist(dict_items)

        # Verify from_dict was called properly, defaults to info_type=video
        calls = [
            call(label='Grape Stomp', info_type='video'),
            call(label='Boom Goes the Dynamite', info_type='video'),
        ]
        self.assertEqual(mock_list_item.from_dict.call_args_list, calls)

        # Verify with playlist=music
        mock_list_item.from_dict.reset_mock()

        dict_items = [
            {
                'label': 'Grape Stomp'
            },
            {
                'label': 'Boom Goes the Dynamite'
            },
        ]
        self.m.add_to_playlist(dict_items, 'music')

        # Verify from_dict was called properly, defaults to info_type=video
        calls = [
            call(label='Grape Stomp', info_type='music'),
            call(label='Boom Goes the Dynamite', info_type='music'),
        ]
        self.assertEqual(mock_list_item.from_dict.call_args_list, calls)

        # Verify an item's info_dict key is not used
        mock_list_item.from_dict.reset_mock()

        dict_items = [
            {
                'label': 'Grape Stomp',
                'info_type': 'music'
            },
            {
                'label': 'Boom Goes the Dynamite',
                'info_type': 'music'
            },
        ]
        items = self.m.add_to_playlist(dict_items, 'video')

        # Verify from_dict was called properly, defaults to info_type=video
        calls = [
            call(label='Grape Stomp', info_type='video'),
            call(label='Boom Goes the Dynamite', info_type='video'),
        ]
        self.assertEqual(mock_list_item.from_dict.call_args_list, calls)

        # verify ListItems were created correctly
        for item, returned_item in zip(dict_items, items):
            assert isinstance(returned_item, ListItem)
            self.assertEqual(item['label'], returned_item.label)

        # Verify listitems are unchanged
        mock_list_item.from_dict.reset_mock()

        listitems = [
            ListItem('Grape Stomp'),
            ListItem('Boom Goes the Dyanmite'),
        ]
        items = self.m.add_to_playlist(listitems)

        self.assertFalse(mock_list_item.from_dict.called)
        for item, returned_item in zip(listitems, items):
            self.assertEqual(item, returned_item)

        # Verify mixed lists
        # Verify listitems are unchange
        listitems = [
            ListItem('Grape Stomp'),
            {
                'label': 'Boom Goes the Dynamite'
            },
        ]
        items = self.m.add_to_playlist(listitems)
        for item, returned_item in zip(listitems, items):
            assert isinstance(returned_item, ListItem)