summaryrefslogtreecommitdiffstats
path: root/deluge/tests/test_torrentview.py
blob: 8d0568866781d4362d81e1b12a0dc83577bd7d55 (plain)
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
#
# Copyright (C) 2014 Bro <bro.development@gmail.com>
# Copyright (C) 2014 Calum Lind <calumlind@gmail.com>
#
# This file is part of Deluge and is licensed under GNU General Public License 3.0, or later, with
# the additional special exception to link portions of this program with the OpenSSL library.
# See LICENSE for more details.
#

import pytest

import deluge.component as component
from deluge.configmanager import ConfigManager
from deluge.conftest import BaseTestCase
from deluge.i18n import setup_translation

# Allow running other tests without GTKUI dependencies available
try:
    # pylint: disable=ungrouped-imports
    from gi.repository.GObject import TYPE_UINT64

    from deluge.ui.gtk3.gtkui import DEFAULT_PREFS
    from deluge.ui.gtk3.mainwindow import MainWindow
    from deluge.ui.gtk3.menubar import MenuBar
    from deluge.ui.gtk3.torrentdetails import TorrentDetails
    from deluge.ui.gtk3.torrentview import TorrentView
except (ImportError, ValueError):
    libs_available = False
    TYPE_UINT64 = 'Whatever'
else:
    libs_available = True

setup_translation()


@pytest.mark.gtkui
class TestTorrentview(BaseTestCase):

    default_column_index = [
        'filter',
        'torrent_id',
        'dirty',
        '#',
        'Name',
        'Size',
        'Downloaded',
        'Uploaded',
        'Remaining',
        'Progress',
        'Seeds',
        'Peers',
        'Seeds:Peers',
        'Down Speed',
        'Up Speed',
        'Down Limit',
        'Up Limit',
        'ETA',
        'Ratio',
        'Avail',
        'Added',
        'Completed',
        'Complete Seen',
        'Last Transfer',
        'Tracker',
        'Download Folder',
        'Owner',
        'Shared',
    ]
    default_liststore_columns = [
        bool,
        str,
        bool,
        int,
        str,
        str,  # Name
        TYPE_UINT64,
        TYPE_UINT64,
        TYPE_UINT64,
        TYPE_UINT64,
        float,
        str,  # Progress
        int,
        int,
        int,
        int,
        float,  # Seeds, Peers
        int,
        int,
        float,
        float,
        int,
        float,
        float,  # ETA, Ratio, Avail
        int,
        int,
        int,
        int,
        str,
        str,  # Tracker
        str,
        str,
        bool,
    ]  # shared

    def set_up(self):
        if libs_available is False:
            pytest.skip('GTKUI dependencies not available')

        # MainWindow loads this config file, so lets make sure it contains the defaults
        ConfigManager('gtk3ui.conf', defaults=DEFAULT_PREFS)
        self.mainwindow = MainWindow()
        self.torrentview = TorrentView()
        self.torrentdetails = TorrentDetails()
        self.menubar = MenuBar()

    def tear_down(self):
        return component.shutdown()

    def test_torrentview_columns(self):
        assert self.torrentview.column_index == self.default_column_index
        assert self.torrentview.liststore_columns == self.default_liststore_columns
        assert self.torrentview.columns['Download Folder'].column_indices == [30]

    def test_add_column(self):
        # Add a text column
        test_col = 'Test column'
        self.torrentview.add_text_column(test_col, status_field=['label'])
        assert (
            len(self.torrentview.liststore_columns)
            == len(self.default_liststore_columns) + 1
        )
        assert len(self.torrentview.column_index) == len(self.default_column_index) + 1
        assert self.torrentview.column_index[-1] == test_col
        assert self.torrentview.columns[test_col].column_indices == [33]

    def test_add_columns(self):
        # Add a text column
        test_col = 'Test column'
        self.torrentview.add_text_column(test_col, status_field=['label'])

        # Add a second text column
        test_col2 = 'Test column2'
        self.torrentview.add_text_column(test_col2, status_field=['label2'])

        assert (
            len(self.torrentview.liststore_columns)
            == len(self.default_liststore_columns) + 2
        )
        assert len(self.torrentview.column_index) == len(self.default_column_index) + 2
        # test_col
        assert self.torrentview.column_index[-2] == test_col
        assert self.torrentview.columns[test_col].column_indices == [33]

        # test_col2
        assert self.torrentview.column_index[-1] == test_col2
        assert self.torrentview.columns[test_col2].column_indices == [34]

    def test_remove_column(self):
        # Add and remove text column
        test_col = 'Test column'
        self.torrentview.add_text_column(test_col, status_field=['label'])
        self.torrentview.remove_column(test_col)

        assert len(self.torrentview.liststore_columns) == len(
            self.default_liststore_columns
        )
        assert len(self.torrentview.column_index) == len(self.default_column_index)
        assert self.torrentview.column_index[-1] == self.default_column_index[-1]
        assert self.torrentview.columns[
            self.default_column_index[-1]
        ].column_indices == [32]

    def test_remove_columns(self):
        # Add two columns
        test_col = 'Test column'
        self.torrentview.add_text_column(test_col, status_field=['label'])
        test_col2 = 'Test column2'
        self.torrentview.add_text_column(test_col2, status_field=['label2'])

        # Remove test_col
        self.torrentview.remove_column(test_col)
        assert (
            len(self.torrentview.liststore_columns)
            == len(self.default_liststore_columns) + 1
        )
        assert len(self.torrentview.column_index) == len(self.default_column_index) + 1
        assert self.torrentview.column_index[-1] == test_col2
        assert self.torrentview.columns[test_col2].column_indices == [33]

        # Remove test_col2
        self.torrentview.remove_column(test_col2)
        assert len(self.torrentview.liststore_columns) == len(
            self.default_liststore_columns
        )
        assert len(self.torrentview.column_index) == len(self.default_column_index)
        assert self.torrentview.column_index[-1] == self.default_column_index[-1]
        assert self.torrentview.columns[
            self.default_column_index[-1]
        ].column_indices == [32]

    def test_add_remove_column_multiple_types(self):
        # Add a column with multiple column types
        test_col3 = 'Test column3'
        self.torrentview.add_progress_column(
            test_col3, status_field=['progress', 'label3'], col_types=[float, str]
        )
        assert (
            len(self.torrentview.liststore_columns)
            == len(self.default_liststore_columns) + 2
        )
        assert len(self.torrentview.column_index) == len(self.default_column_index) + 1
        assert self.torrentview.column_index[-1] == test_col3
        assert self.torrentview.columns[test_col3].column_indices == [33, 34]

        # Remove multiple column-types column
        self.torrentview.remove_column(test_col3)

        assert len(self.torrentview.liststore_columns) == len(
            self.default_liststore_columns
        )
        assert len(self.torrentview.column_index) == len(self.default_column_index)
        assert self.torrentview.column_index[-1] == self.default_column_index[-1]
        assert self.torrentview.columns[
            self.default_column_index[-1]
        ].column_indices == [32]