Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

import base64 

import os 

import warnings 

 

import pytest 

from twisted.trial import unittest 

 

import common 

from deluge import component 

from deluge.core.core import Core 

from deluge.core.rpcserver import RPCServer 

from deluge.error import InvalidTorrentError 

 

warnings.filterwarnings("ignore", category=RuntimeWarning) 

warnings.resetwarnings() 

 

common.disable_new_release_check() 

 

 

class TorrentmanagerTestCase(unittest.TestCase): 

 

    def setUp(self):  # NOQA 

        common.set_tmp_config_dir() 

        self.rpcserver = RPCServer(listen=False) 

        self.core = Core() 

        self.torrentmanager = self.core.torrentmanager 

        return component.start() 

 

    def tearDown(self):  # NOQA 

        def on_shutdown(result): 

            component._ComponentRegistry.components = {} 

            del self.rpcserver 

            del self.core 

            del self.torrentmanager 

        return component.shutdown().addCallback(on_shutdown) 

 

    def test_remove_torrent(self): 

        filename = os.path.join(os.path.dirname(__file__), "test.torrent") 

        torrent_id = self.core.add_torrent_file(filename, base64.encodestring(open(filename).read()), {}) 

        self.assertTrue(self.torrentmanager.remove(torrent_id, False)) 

 

    @pytest.mark.todo 

    def test_remove_torrent_false(self): 

        """Test when remove_torrent returns False""" 

        TorrentmanagerTestCase.test_remove_torrent_false.im_func.todo = "To be written" 

        raise unittest.SkipTest("Todo") 

 

    def test_remove_invalid_torrent(self): 

        self.assertRaises(InvalidTorrentError, self.torrentmanager.remove, "torrentidthatdoesntexist")