Ejemplo n.º 1
0
 async def test_invert_char_in_operator(self, mock_get_filter_cls, mock_torrent_filter_values):
     mock_get_filter_cls.return_value.INVERT_CHAR = '!'
     mock_torrent_filter_values.return_value = 'mock torrent values'
     cands = await candidates.torrent_filter(Arg('bar!=asdf', curpos=5))
     mock_torrent_filter_values.assert_called_once_with('bar')
     exp_cands = ('mock torrent values',)
     self.assertEqual(cands, exp_cands)
Ejemplo n.º 2
0
 async def test_no_success_when_requesting_torrents(self, mock_torrents):
     mock_torrents.return_value = SimpleNamespace(success=False)
     cands = await candidates.torrent_path(Arg('id=foo/bar/baz', curpos=8))
     self.assert_no_candidates(cands)
     mock_torrents.assert_called_once_with('id=foo',
                                           keys=('files', ),
                                           from_cache=True)
Ejemplo n.º 3
0
 async def test_path_given_completes_torrent_path(self, mock_torrents,
                                                  mock_torrent_filter):
     cands = await candidates.torrent_path(Arg('id=foo/a/b/c', curpos=7))
     mock_torrent_filter.assert_not_called()
     mock_torrents.assert_called_once_with('id=foo',
                                           keys=('files', ),
                                           from_cache=True)
Ejemplo n.º 4
0
 async def test_operator_given_without_filter_name(self, mock_get_filter_cls, mock_torrent_filter_values):
     mock_get_filter_cls.return_value.INVERT_CHAR = '!'
     mock_get_filter_cls.return_value.DEFAULT_FILTER = 'mock default'
     mock_torrent_filter_values.return_value = 'mock torrent values'
     cands = await candidates.torrent_filter(Arg('=asdf', curpos=4))
     mock_torrent_filter_values.assert_called_once_with('mock default')
     exp_cands = ('mock torrent values',)
     self.assertEqual(cands, exp_cands)
Ejemplo n.º 5
0
 async def test_no_path_given_completes_torrent_filter(
         self, mock_torrents, mock_torrent_filter):
     mock_torrent_filter.return_value = (Candidates(
         ('mock torrent_filter() candidates', ), curarg_seps=('.', ',')), )
     cands = await candidates.torrent_path(Arg('id=foo/a/b/c', curpos=6))
     exp_cands = (Candidates(('mock torrent_filter() candidates', ),
                             curarg_seps=('.', ',', '/')), )
     self.assertEqual(cands, exp_cands)
     mock_torrent_filter.assert_called_once_with('id=foo')
     mock_torrents.assert_not_called()
Ejemplo n.º 6
0
 async def test_focusing_filter_name(self, mock_filter_names, mock_get_filter_cls, mock_torrent_filter_values):
     mock_get_filter_cls.return_value.INVERT_CHAR = '!'
     mock_get_filter_cls.return_value.DEFAULT_FILTER = 'mock default filter'
     mock_filter_names.return_value = Candidates(('foo', 'bar', 'baz'),
                                                 curarg_seps=('.', ':'),
                                                 label='Mock Filter Names')
     mock_torrent_filter_values.return_value = 'mock torrent values'
     cands = await candidates.torrent_filter(Arg('bar=asdf', curpos=2))
     mock_torrent_filter_values.assert_called_once_with('mock default filter')
     exp_cands = (
         Candidates(('foo', 'bar', 'baz'), curarg_seps=('.', ':'), label='Mock Filter Names'),
         'mock torrent values'
     )
     self.assertEqual(cands, exp_cands)
Ejemplo n.º 7
0
 async def test_single_file_in_torrent(self, mock_torrents,
                                       mock_find_subtree):
     mock_find_subtree.return_value = None
     mock_torrent_list = [{'name': 'Mock Torrent', 'files': MagicMock()}]
     mock_torrents.return_value = SimpleNamespace(
         success=True, torrents=mock_torrent_list)
     cands = await candidates.torrent_path(Arg('id=foo/a/b/c', curpos=10))
     self.assert_no_candidates(cands)
     mock_torrents.assert_called_once_with('id=foo',
                                           keys=('files', ),
                                           from_cache=True)
     mock_find_subtree.assert_called_once_with(
         mock_torrent_list[0],
         Args(('a', 'b'), curarg_index=1, curarg_curpos=1))
Ejemplo n.º 8
0
    async def test_only_auto_with_path_pointing_to_file(self, mock_torrents):
        mock_files = MockTree(foo=MockTree(
            bar=MockFile('bar'), ber=MockTree(), bir=MockFile('bir')))
        mock_torrent_list = [{'name': 'foo', 'files': mock_files}]
        mock_torrents.return_value = SimpleNamespace(
            success=True, torrents=mock_torrent_list)

        cands = tuple(await candidates.torrent_path(Arg('id=foo/bir',
                                                        curpos=10),
                                                    only='auto'))
        exp_cands = (Candidates(('bar', 'bir'),
                                curarg_seps=('/', ),
                                label='Files in mock/path'), )
        self.assertEqual(cands, exp_cands)
        mock_torrents.assert_called_with('id=foo',
                                         keys=('files', ),
                                         from_cache=True)
Ejemplo n.º 9
0
 async def test_cursor_is_on_leading_inverting_character(
         self, mock_filter_values, mock_get_filter_cls):
     mock_get_filter_cls.return_value.INVERT_CHAR = '!'
     mock_get_filter_cls.return_value.DEFAULT_FILTER = 'mock default filter'
     mock_filter_values.return_value = 'mock items values'
     cands = await candidates._filter(Arg('!bar', curpos=0),
                                      'MockFilter',
                                      'mock objects getter',
                                      filter_names=False,
                                      items_getter='mock items getter')
     mock_filter_values.assert_called_once_with(
         'MockFilter',
         'mock default filter',
         objects_getter='mock objects getter',
         items_getter='mock items getter')
     exp_cands = ('mock items values', )
     self.assertEqual(cands, exp_cands)
Ejemplo n.º 10
0
 async def test_invert_char_in_operator(self, mock_filter_values,
                                        mock_get_filter_cls):
     mock_get_filter_cls.return_value.INVERT_CHAR = '!'
     mock_get_filter_cls.return_value.DEFAULT_FILTER = 'mock default filter'
     mock_filter_values.return_value = 'mock items values'
     cands = await candidates._filter(Arg('bar!=asdf', curpos=5),
                                      'MockFilter',
                                      'mock objects getter',
                                      filter_names=True,
                                      items_getter='mock items getter')
     mock_filter_values.assert_called_once_with(
         'MockFilter',
         'bar',
         objects_getter='mock objects getter',
         items_getter='mock items getter')
     exp_cands = ('mock items values', )
     self.assertEqual(cands, exp_cands)
Ejemplo n.º 11
0
    async def test_only_any(self, mock_torrents, mock_find_subtree):
        mock_files = MockTree(
            foo=MockTree(bar=MockTree(), ber=MockTree(), bir=MockFile('bir')))
        mock_torrent_list = [{'name': 'foo', 'files': mock_files}]
        mock_torrents.return_value = SimpleNamespace(
            success=True, torrents=mock_torrent_list)
        mock_find_subtree.return_value = mock_files['foo']

        cands = tuple(await candidates.torrent_path(Arg('id=foo/', curpos=7),
                                                    only='any'))
        exp_cands = (Candidates(('bar', 'ber', 'bir'),
                                curarg_seps=('/', ),
                                label='mock/path'), )
        self.assertEqual(cands, exp_cands)
        mock_torrents.assert_called_with('id=foo',
                                         keys=('files', ),
                                         from_cache=True)
        self.assertEqual(mock_find_subtree.call_args_list,
                         [call(mock_torrent_list[0], ('', ))])
Ejemplo n.º 12
0
 async def test_focusing_filter_name_without_filter_names(
         self, mock_filter_values, mock_filter_names, mock_get_filter_cls):
     mock_get_filter_cls.return_value.INVERT_CHAR = '!'
     mock_get_filter_cls.return_value.DEFAULT_FILTER = 'mock default filter'
     mock_filter_names.return_value = Candidates(('foo', 'bar', 'baz'),
                                                 curarg_seps=('.', ':'),
                                                 label='Mock Filter Names')
     mock_filter_values.return_value = 'mock items values'
     cands = await candidates._filter(Arg('bar=asdf', curpos=2),
                                      'MockFilter',
                                      'mock objects getter',
                                      filter_names=False,
                                      items_getter='mock items getter')
     mock_filter_values.assert_called_once_with(
         'MockFilter',
         'mock default filter',
         objects_getter='mock objects getter',
         items_getter='mock items getter')
     exp_cands = ('mock items values', )
     self.assertEqual(cands, exp_cands)