TestContentApi.test_mark_read__workspace()   F
last analyzed

Complexity

Conditions 13

Size

Total Lines 102
Code Lines 79

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 13
eloc 79
nop 1
dl 0
loc 102
rs 2
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

Complexity

Complex classes like tracim.tests.library.test_content_api.TestContentApi.test_mark_read__workspace() often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

1
# -*- coding: utf-8 -*-
0 ignored issues
show
coding-style introduced by
Too many lines in module (2087/1000)
Loading history...
Coding Style introduced by
This module should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
2
3
import transaction
4
import pytest
0 ignored issues
show
introduced by
Unable to import 'pytest'
Loading history...
5
6
from tracim.config import CFG
0 ignored issues
show
Unused Code introduced by
Unused CFG imported from tracim.config
Loading history...
7
from tracim.lib.core.content import compare_content_for_sorting_by_type_and_name
8
from tracim.lib.core.content import ContentApi
9
# TODO - G.M - 28-03-2018 - [GroupApi] Re-enable GroupApi
0 ignored issues
show
Coding Style introduced by
TODO and FIXME comments should generally be avoided.
Loading history...
10
from tracim.lib.core.group import GroupApi
11
from tracim.lib.core.user import UserApi
12
from tracim.exceptions import SameValueError
13
# TODO - G.M - 28-03-2018 - [RoleApi] Re-enable RoleApi
0 ignored issues
show
Coding Style introduced by
TODO and FIXME comments should generally be avoided.
Loading history...
14
from tracim.lib.core.workspace import RoleApi
15
# TODO - G.M - 28-03-2018 - [WorkspaceApi] Re-enable WorkspaceApi
0 ignored issues
show
Coding Style introduced by
TODO and FIXME comments should generally be avoided.
Loading history...
16
from tracim.lib.core.workspace import WorkspaceApi
17
from tracim.models.revision_protection import new_revision
18
from tracim.models.auth import User
19
from tracim.models.auth import Group
20
21
from tracim.models.data import ActionDescription
22
from tracim.models.data import ContentRevisionRO
23
from tracim.models.data import Workspace
24
from tracim.models.data import Content
25
from tracim.models.data import ContentType
26
from tracim.models.data import UserRoleInWorkspace
27
from tracim.fixtures.users_and_groups import Test as FixtureTest
28
from tracim.tests import DefaultTest
29
from tracim.tests import eq_
30
31
32
class TestContentApi(DefaultTest):
0 ignored issues
show
Coding Style introduced by
This class should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
Unused Code introduced by
The variable __class__ seems to be unused.
Loading history...
best-practice introduced by
Too many public methods (26/20)
Loading history...
33
34
    def test_compare_content_for_sorting_by_type(self):
0 ignored issues
show
Coding Style Naming introduced by
The name test_compare_content_for_sorting_by_type does not conform to the method naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
35
        c1 = Content()
0 ignored issues
show
Coding Style Naming introduced by
The name c1 does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
36
        c1.label = ''
37
        c1.type = 'file'
38
39
        c2 = Content()
0 ignored issues
show
Coding Style Naming introduced by
The name c2 does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
40
        c2.label = ''
41
        c2.type = 'folder'
42
43
        c11 = c1
44
45
        eq_(1, compare_content_for_sorting_by_type_and_name(c1, c2))
46
        eq_(-1, compare_content_for_sorting_by_type_and_name(c2, c1))
47
        eq_(0, compare_content_for_sorting_by_type_and_name(c1, c11))
48
49
    def test_compare_content_for_sorting_by_label(self):
0 ignored issues
show
Coding Style Naming introduced by
The name test_compare_content_for_sorting_by_label does not conform to the method naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
50
        c1 = Content()
0 ignored issues
show
Coding Style Naming introduced by
The name c1 does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
51
        c1.label = 'bbb'
52
        c1.type = 'file'
53
54
        c2 = Content()
0 ignored issues
show
Coding Style Naming introduced by
The name c2 does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
55
        c2.label = 'aaa'
56
        c2.type = 'file'
57
58
        c11 = c1
59
60
        eq_(1, compare_content_for_sorting_by_type_and_name(c1, c2))
61
        eq_(-1, compare_content_for_sorting_by_type_and_name(c2, c1))
62
        eq_(0, compare_content_for_sorting_by_type_and_name(c1, c11))
63
64
    def test_sort_by_label_or_filename(self):
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
65
        c1 = Content()
0 ignored issues
show
Coding Style Naming introduced by
The name c1 does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
66
        c1.label = 'ABCD'
67
        c1.type = 'file'
68
69
        c2 = Content()
0 ignored issues
show
Coding Style Naming introduced by
The name c2 does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
70
        c2.label = ''
71
        c2.type = 'file'
72
        c2.file_name = 'AABC'
73
74
        c3 = Content()
0 ignored issues
show
Coding Style Naming introduced by
The name c3 does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
75
        c3.label = 'BCDE'
76
        c3.type = 'file'
77
78
        items = [c1, c2, c3]
79
        sorteds = ContentApi.sort_content(items)
80
81
        eq_(sorteds[0], c2)
82
        eq_(sorteds[1], c1)
83
        eq_(sorteds[2], c3)
84
85
    def test_sort_by_content_type(self):
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
86
        c1 = Content()
0 ignored issues
show
Coding Style Naming introduced by
The name c1 does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
87
        c1.label = 'AAAA'
88
        c1.type = 'file'
89
90
        c2 = Content()
0 ignored issues
show
Coding Style Naming introduced by
The name c2 does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
91
        c2.label = 'BBBB'
92
        c2.type = 'folder'
93
94
        items = [c1, c2]
95
        sorteds = ContentApi.sort_content(items)
96
97
        eq_(sorteds[0], c2,
98
            'value is {} instead of {}'.format(sorteds[0].content_id,
99
                                               c2.content_id))
100
        eq_(sorteds[1], c1,
101
            'value is {} instead of {}'.format(sorteds[1].content_id,
102
                                               c1.content_id))
103
104
    def test_delete(self):
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
105
        uapi = UserApi(
106
            session=self.session,
107
            config=self.app_config,
108
            current_user=None,
109
        )
110
        group_api = GroupApi(current_user=None,session=self.session)
0 ignored issues
show
Coding Style introduced by
Exactly one space required after comma
Loading history...
111
        groups = [group_api.get_one(Group.TIM_USER),
112
                  group_api.get_one(Group.TIM_MANAGER),
113
                  group_api.get_one(Group.TIM_ADMIN)]
114
115
        user = uapi.create_user(email='this.is@user',
116
                                groups=groups, save_now=True)
117
        workspace = WorkspaceApi(
118
            current_user=user,
119
            session=self.session
120
        ).create_workspace('test workspace', save_now=True)
121
        api = ContentApi(
122
            current_user=user,
123
            session=self.session,
124
            config=self.app_config,
125
        )
126
        item = api.create(ContentType.Folder, workspace, None,
0 ignored issues
show
Unused Code introduced by
The variable item seems to be unused.
Loading history...
127
                          'not_deleted', True)
128
        item2 = api.create(ContentType.Folder, workspace, None,
0 ignored issues
show
Unused Code introduced by
The variable item2 seems to be unused.
Loading history...
129
                           'to_delete', True)
130
        uid = user.user_id
131
        wid = workspace.workspace_id
132
        transaction.commit()
133
134
        # Refresh instances after commit
135
        user = uapi.get_one(uid)
136
        workspace_api = WorkspaceApi(current_user=user, session=self.session)
137
        workspace = workspace_api.get_one(wid)
138
        api = ContentApi(
139
            current_user=user,
140
            session=self.session,
141
            config=self.app_config,
142
        )
143
        items = api.get_all(None, ContentType.Any, workspace)
144
        eq_(2, len(items))
145
146
        items = api.get_all(None, ContentType.Any, workspace)
147
        with new_revision(
148
                session=self.session,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation (remove 4 spaces).
Loading history...
149
                tm=transaction.manager,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation (remove 4 spaces).
Loading history...
150
                content=items[0]
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation (remove 4 spaces).
Loading history...
151
        ):
152
            api.delete(items[0])
153
        transaction.commit()
154
155
        # Refresh instances after commit
156
        user = uapi.get_one(uid)
157
        workspace_api = WorkspaceApi(current_user=user, session=self.session)
158
        workspace = workspace_api.get_one(wid)
159
        api = ContentApi(
160
            current_user=user, 
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
161
            session=self.session,
162
            config=self.app_config,
163
        )
164
        items = api.get_all(None, ContentType.Any, workspace)
165
        eq_(1, len(items))
166
        transaction.commit()
167
168
        # Test that the item is still available if "show deleted" is activated
169
        # Refresh instances after commit
170
        user = uapi.get_one(uid)
171
        workspace_api = WorkspaceApi(current_user=user, session=self.session)
172
        api = ContentApi(
173
            current_user=user,
174
            session=self.session,
175
            config=self.app_config,
176
            show_deleted=True,
177
        )
178
        items = api.get_all(None, ContentType.Any, workspace)
179
        eq_(2, len(items))
180
181
    def test_archive(self):
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
182
        uapi = UserApi(
183
            session=self.session,
184
            config=self.app_config,
185
            current_user=None,
186
        )
187
        group_api = GroupApi(current_user=None, session=self.session)
188
        groups = [group_api.get_one(Group.TIM_USER),
189
                  group_api.get_one(Group.TIM_MANAGER),
190
                  group_api.get_one(Group.TIM_ADMIN)]
191
192
        user = uapi.create_user(email='this.is@user',
193
                                groups=groups, save_now=True)
194
        workspace_api = WorkspaceApi(current_user=user, session=self.session)
195
        workspace = workspace_api.create_workspace(
196
            'test workspace',
197
            save_now=True
198
        )
199
        api = ContentApi(
200
            current_user=user,
201
            session=self.session,
202
            config=self.app_config,
203
        )
204
        item = api.create(ContentType.Folder, workspace, None,
0 ignored issues
show
Unused Code introduced by
The variable item seems to be unused.
Loading history...
205
                          'not_archived', True)
206
        item2 = api.create(ContentType.Folder, workspace, None,
0 ignored issues
show
Unused Code introduced by
The variable item2 seems to be unused.
Loading history...
207
                           'to_archive', True)
208
        uid = user.user_id
209
        wid = workspace.workspace_id
210
        transaction.commit()
211
        # Refresh instances after commit
212
        user = uapi.get_one(uid)
213
        workspace_api = WorkspaceApi(current_user=user, session=self.session)
214
        api = ContentApi(
215
            session=self.session,
216
            current_user=user,
217
            config=self.app_config,
218
        )
219
220
        items = api.get_all(None, ContentType.Any, workspace)
221
        eq_(2, len(items))
222
223
        items = api.get_all(None, ContentType.Any, workspace)
224
        with new_revision(
225
                session=self.session,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation (remove 4 spaces).
Loading history...
226
                tm=transaction.manager,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation (remove 4 spaces).
Loading history...
227
                content=items[0],
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation (remove 4 spaces).
Loading history...
228
        ):
229
            api.archive(items[0])
230
        transaction.commit()
231
232
        # Refresh instances after commit
233
        user = uapi.get_one(uid)
234
        workspace_api = WorkspaceApi(current_user=user, session=self.session)
235
        workspace = workspace_api.get_one(wid)
236
        api = ContentApi(
237
            current_user=user, 
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
238
            session=self.session,
239
            config=self.app_config,
240
        )
241
242
        items = api.get_all(None, ContentType.Any, workspace)
243
        eq_(1, len(items))
244
        transaction.commit()
245
246
        # Refresh instances after commit
247
        user = uapi.get_one(uid)
248
        workspace_api = WorkspaceApi(current_user=user, session=self.session)
249
        workspace = workspace_api.get_one(wid)
250
        api = ContentApi(
251
            current_user=user,
252
            session=self.session,
253
            config=self.app_config,
254
        )
255
256
        # Test that the item is still available if "show deleted" is activated
257
        api = ContentApi(
258
            current_user=None,
259
            session=self.session,
260
            config=self.app_config,
261
            show_archived=True,
262
        )
263
        items = api.get_all(None, ContentType.Any, workspace)
264
        eq_(2, len(items))
265
266
    def test_get_all_with_filter(self):
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
Comprehensibility introduced by
This function exceeds the maximum number of variables (16/15).
Loading history...
267
        uapi = UserApi(
268
            session=self.session,
269
            config=self.app_config,
270
            current_user=None,
271
        )
272
        group_api = GroupApi(current_user=None, session=self.session)
273
        groups = [group_api.get_one(Group.TIM_USER),
274
                  group_api.get_one(Group.TIM_MANAGER),
275
                  group_api.get_one(Group.TIM_ADMIN)]
276
277
        user = uapi.create_user(
278
            email='this.is@user',
279
            groups=groups,
280
            save_now=True
281
        )
282
        workspace = WorkspaceApi(
283
            current_user=user,
284
            session=self.session
285
        ).create_workspace(
286
            'test workspace',
287
            save_now=True
288
        )
289
290
        api = ContentApi(
291
            current_user=user,
292
            session=self.session,
293
            config=self.app_config,
294
        )
295
        item = api.create(ContentType.Folder, workspace, None,
0 ignored issues
show
Unused Code introduced by
The variable item seems to be unused.
Loading history...
296
                          'thefolder', True)
297
        item2 = api.create(ContentType.File, workspace, None, 'thefile', True)
0 ignored issues
show
Unused Code introduced by
The variable item2 seems to be unused.
Loading history...
298
        uid = user.user_id
299
        wid = workspace.workspace_id
300
        transaction.commit()
301
302
        # Refresh instances after commit
303
        user = uapi.get_one(uid)
304
        workspace_api = WorkspaceApi(current_user=user, session=self.session)
305
        workspace = workspace_api.get_one(wid)
306
        api = ContentApi(
307
            current_user=user, 
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
308
            session=self.session,
309
            config=self.app_config,
310
        )
311
312
        items = api.get_all(None, ContentType.Any, workspace)
313
        eq_(2, len(items))
314
315
        items2 = api.get_all(None, ContentType.File, workspace)
316
        eq_(1, len(items2))
317
        eq_('thefile', items2[0].label)
318
319
        items3 = api.get_all(None, ContentType.Folder, workspace)
320
        eq_(1, len(items3))
321
        eq_('thefolder', items3[0].label)
322
323
    def test_get_all_with_parent_id(self):
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
Comprehensibility introduced by
This function exceeds the maximum number of variables (18/15).
Loading history...
324
        uapi = UserApi(
325
            session=self.session,
326
            config=self.app_config,
327
            current_user=None,
328
        )
329
        group_api = GroupApi(current_user=None, session=self.session)
330
        groups = [group_api.get_one(Group.TIM_USER),
331
                  group_api.get_one(Group.TIM_MANAGER),
332
                  group_api.get_one(Group.TIM_ADMIN)]
333
334
        user = uapi.create_user(email='this.is@user',
335
                                groups=groups, save_now=True)
336
        workspace = WorkspaceApi(
337
            current_user=user,
338
            session=self.session
339
        ).create_workspace('test workspace', save_now=True)
340
        api = ContentApi(
341
            current_user=user, 
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
342
            session=self.session,
343
            config=self.app_config,
344
        )
345
        item = api.create(
346
            ContentType.Folder,
347
            workspace,
348
            None,
349
            'parent',
350
            do_save=True,
351
        )
352
        item2 = api.create(
353
            ContentType.File,
354
            workspace,
355
            item,
356
            'file1',
357
            do_save=True,
358
        )
359
        item3 = api.create(
0 ignored issues
show
Unused Code introduced by
The variable item3 seems to be unused.
Loading history...
360
            ContentType.File,
361
            workspace,
362
            None,
363
            'file2',
364
            do_save=True,
365
        )
366
        parent_id = item.content_id
367
        child_id = item2.content_id
368
        uid = user.user_id
369
        wid = workspace.workspace_id
370
        transaction.commit()
371
372
        # Refresh instances after commit
373
        user = uapi.get_one(uid)
374
        workspace_api = WorkspaceApi(current_user=user, session=self.session)
375
        workspace = workspace_api.get_one(wid)
376
        api = ContentApi(
377
            current_user=user,
378
            session=self.session,
379
            config=self.app_config,
380
        )
381
382
        items = api.get_all(None, ContentType.Any, workspace)
383
        eq_(3, len(items))
384
385
        items2 = api.get_all(parent_id, ContentType.File, workspace)
386
        eq_(1, len(items2))
387
        eq_(child_id, items2[0].content_id)
388
389
    def test_set_status_unknown_status(self):
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
390
        uapi = UserApi(
391
            session=self.session,
392
            config=self.app_config,
393
            current_user=None,
394
        )
395
        group_api = GroupApi(
396
            current_user=None,
397
            session=self.session
398
        )
399
        groups = [group_api.get_one(Group.TIM_USER),
400
                  group_api.get_one(Group.TIM_MANAGER),
401
                  group_api.get_one(Group.TIM_ADMIN)]
402
403
        user = uapi.create_user(email='this.is@user',
404
                                groups=groups, save_now=True)
405
406
        workspace = WorkspaceApi(
407
            current_user=user,
408
            session=self.session
409
        ).create_workspace(
410
            'test workspace',
411
            save_now=True
412
        )
413
        api = ContentApi(
414
            current_user=user, 
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
415
            session=self.session,
416
            config=self.app_config,
417
        )
418
        c = api.create(ContentType.Folder, workspace, None, 'parent', True)
0 ignored issues
show
Coding Style Naming introduced by
The name c does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
419
        with new_revision(
420
            session=self.session,
421
            tm=transaction.manager,
422
            content=c,
423
        ):
424
            with pytest.raises(ValueError):
425
                api.set_status(c, 'unknown-status')
426
427
    def test_set_status_ok(self):
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
428
        uapi = UserApi(
429
            session=self.session,
430
            config=self.app_config,
431
            current_user=None,
432
        )
433
        group_api = GroupApi(
434
            current_user=None,
435
            session=self.session
436
        )
437
        groups = [group_api.get_one(Group.TIM_USER),
438
                  group_api.get_one(Group.TIM_MANAGER),
439
                  group_api.get_one(Group.TIM_ADMIN)]
440
441
        user = uapi.create_user(email='this.is@user',
442
                                groups=groups, save_now=True)
443
444
        workspace = WorkspaceApi(
445
            current_user=user,
446
            session=self.session
447
        ).create_workspace(
448
            'test workspace',
449
            save_now=True
450
        )
451
        api = ContentApi(
452
            current_user=user,
453
            session=self.session,
454
            config=self.app_config,
455
        )
456
        c = api.create(ContentType.Folder, workspace, None, 'parent', True)
0 ignored issues
show
Coding Style Naming introduced by
The name c does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
457
        with new_revision(
458
            session=self.session,
459
            tm=transaction.manager,
460
            content=c,
461
        ):
462
            for new_status in ['open', 'closed-validated', 'closed-unvalidated',
463
                               'closed-deprecated']:
464
                api.set_status(c, new_status)
465
466
                eq_(new_status, c.status)
467
                eq_(ActionDescription.STATUS_UPDATE, c.revision_type)
468
469
    def test_create_comment_ok(self):
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
470
        uapi = UserApi(
471
            session=self.session,
472
            config=self.app_config,
473
            current_user=None,
474
        )
475
        group_api = GroupApi(
476
            current_user=None,
477
            session=self.session
478
        )
479
        groups = [group_api.get_one(Group.TIM_USER),
480
                  group_api.get_one(Group.TIM_MANAGER),
481
                  group_api.get_one(Group.TIM_ADMIN)]
482
483
        user = uapi.create_user(email='this.is@user',
484
                                groups=groups, save_now=True)
485
486
        workspace = WorkspaceApi(
487
            current_user=user,
488
            session=self.session
489
        ).create_workspace(
490
            'test workspace',
491
            save_now=True
492
        )
493
494
        api = ContentApi(
495
            current_user=user,
496
            session=self.session,
497
            config=self.app_config,
498
        )
499
        p = api.create(ContentType.Page, workspace, None, 'this_is_a_page')
0 ignored issues
show
Coding Style Naming introduced by
The name p does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
500
        c = api.create_comment(workspace, p, 'this is the comment', True)
0 ignored issues
show
Coding Style Naming introduced by
The name c does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
501
502
        eq_(Content, c.__class__)
503
        eq_(p.content_id, c.parent_id)
504
        eq_(user, c.owner)
505
        eq_(workspace, c.workspace)
506
        eq_(ContentType.Comment, c.type)
507
        eq_('this is the comment', c.description)
508
        eq_('', c.label)
509
        eq_(ActionDescription.COMMENT, c.revision_type)
510
511 View Code Duplication
    def test_unit_copy_file_different_label_different_parent_ok(self):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
Coding Style Naming introduced by
The name test_unit_copy_file_diff...bel_different_parent_ok does not conform to the method naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
512
        uapi = UserApi(
513
            session=self.session,
514
            config=self.app_config,
515
            current_user=None,
516
        )
517
        group_api = GroupApi(
518
            current_user=None,
519
            session=self.session
520
        )
521
        groups = [group_api.get_one(Group.TIM_USER),
522
                  group_api.get_one(Group.TIM_MANAGER),
523
                  group_api.get_one(Group.TIM_ADMIN)]
524
525
        user = uapi.create_user(
526
            email='user1@user',
527
            groups=groups,
528
            save_now=True
529
        )
530
        user2 = uapi.create_user(
531
            email='user2@user',
532
            groups=groups,
533
            save_now=True
534
        )
535
        workspace = WorkspaceApi(
536
            current_user=user,
537
            session=self.session
538
        ).create_workspace(
539
            'test workspace',
540
            save_now=True
541
        )
542
        RoleApi(current_user=user, session=self.session).create_one(
543
            user2,
544
            workspace,
545
            UserRoleInWorkspace.WORKSPACE_MANAGER,
546
            with_notif=False
547
        )
548
        api = ContentApi(
549
            current_user=user,
550
            session=self.session,
551
            config=self.app_config,
552
        )
553
        foldera = api.create(
554
            ContentType.Folder,
555
            workspace,
556
            None,
557
            'folder a',
558
            True
559
        )
560
        with self.session.no_autoflush:
561
            text_file = api.create(
562
                content_type=ContentType.File,
563
                workspace=workspace,
564
                parent=foldera,
565
                label='test_file',
566
                do_save=False,
567
            )
568
            api.update_file_data(
569
                text_file,
570
                'test_file',
571
                'text/plain',
572
                b'test_content'
573
            )
574
575
        api.save(text_file, ActionDescription.CREATION)
576
        api2 = ContentApi(
577
            current_user=user2,
578
            session=self.session,
579
            config=self.app_config,
580
        )
581
        workspace2 = WorkspaceApi(
582
            current_user=user2,
583
            session=self.session,
584
        ).create_workspace(
585
            'test workspace2',
586
            save_now=True
587
        )
588
        folderb = api2.create(
589
            ContentType.Folder,
590
            workspace2,
591
            None,
592
            'folder b',
593
            True
594
        )
595
596
        api2.copy(
597
            item=text_file,
598
            new_parent=folderb,
599
            new_label='test_file_copy'
600
        )
601
602
        transaction.commit()
603
        text_file_copy = api2.get_one_by_label_and_parent(
604
            'test_file_copy',
605
            folderb,
606
        )
607
608
        assert text_file != text_file_copy
609
        assert text_file_copy.content_id != text_file.content_id
610
        assert text_file_copy.workspace_id == workspace2.workspace_id
611
        assert text_file_copy.depot_file.file.read() == text_file.depot_file.file.read()   # nopep8
0 ignored issues
show
Bug introduced by
The Instance of FileIntent does not seem to have a member named file.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
Bug introduced by
The Instance of bytes does not seem to have a member named file.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
612
        assert text_file_copy.depot_file.path != text_file.depot_file.path
0 ignored issues
show
Bug introduced by
The Instance of FileIntent does not seem to have a member named path.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
Bug introduced by
The Instance of bytes does not seem to have a member named path.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
613
        assert text_file_copy.label == 'test_file_copy'
614
        assert text_file_copy.type == text_file.type
615
        assert text_file_copy.parent.content_id == folderb.content_id
616
        assert text_file_copy.owner.user_id == user.user_id
617
        assert text_file_copy.description == text_file.description
618
        assert text_file_copy.file_extension == text_file.file_extension
619
        assert text_file_copy.file_mimetype == text_file.file_mimetype
620
        assert text_file_copy.revision_type == ActionDescription.COPY
621
        assert len(text_file_copy.revisions) == len(text_file.revisions) + 1
622
623 View Code Duplication
    def test_unit_copy_file__same_label_different_parent_ok(self):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
Coding Style Naming introduced by
The name test_unit_copy_file__sam...bel_different_parent_ok does not conform to the method naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
624
        uapi = UserApi(
625
            session=self.session,
626
            config=self.app_config,
627
            current_user=None,
628
        )
629
        group_api = GroupApi(
630
            current_user=None,
631
            session=self.session
632
        )
633
        groups = [group_api.get_one(Group.TIM_USER),
634
                  group_api.get_one(Group.TIM_MANAGER),
635
                  group_api.get_one(Group.TIM_ADMIN)]
636
637
        user = uapi.create_user(
638
            email='user1@user',
639
            groups=groups,
640
            save_now=True
641
        )
642
        user2 = uapi.create_user(
643
            email='user2@user',
644
            groups=groups,
645
            save_now=True
646
        )
647
        workspace = WorkspaceApi(
648
            current_user=user,
649
            session=self.session
650
        ).create_workspace(
651
            'test workspace',
652
            save_now=True
653
        )
654
        RoleApi(current_user=user, session=self.session).create_one(
655
            user2,
656
            workspace,
657
            UserRoleInWorkspace.WORKSPACE_MANAGER,
658
            with_notif=False
659
        )
660
        api = ContentApi(
661
            current_user=user,
662
            session=self.session,
663
            config=self.app_config,
664
        )
665
        foldera = api.create(
666
            ContentType.Folder,
667
            workspace,
668
            None,
669
            'folder a',
670
            True
671
        )
672
        with self.session.no_autoflush:
673
            text_file = api.create(
674
                content_type=ContentType.File,
675
                workspace=workspace,
676
                parent=foldera,
677
                label='test_file',
678
                do_save=False,
679
            )
680
            api.update_file_data(
681
                text_file,
682
                'test_file',
683
                'text/plain',
684
                b'test_content'
685
            )
686
687
        api.save(text_file, ActionDescription.CREATION)
688
        api2 = ContentApi(
689
            current_user=user2,
690
            session=self.session,
691
            config=self.app_config,
692
        )
693
        workspace2 = WorkspaceApi(
694
            current_user=user2,
695
            session=self.session
696
        ).create_workspace(
697
            'test workspace2',
698
            save_now=True
699
        )
700
        folderb = api2.create(
701
            ContentType.Folder,
702
            workspace2,
703
            None,
704
            'folder b',
705
            True
706
        )
707
        api2.copy(
708
            item=text_file,
709
            new_parent=folderb,
710
        )
711
712
        transaction.commit()
713
        text_file_copy = api2.get_one_by_label_and_parent(
714
            'test_file',
715
            folderb,
716
        )
717
718
        assert text_file != text_file_copy
719
        assert text_file_copy.content_id != text_file.content_id
720
        assert text_file_copy.workspace_id == workspace2.workspace_id
721
        assert text_file_copy.depot_file.file.read() == text_file.depot_file.file.read()  # nopep8
0 ignored issues
show
Bug introduced by
The Instance of FileIntent does not seem to have a member named file.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
Bug introduced by
The Instance of bytes does not seem to have a member named file.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
722
        assert text_file_copy.depot_file.path != text_file.depot_file.path
0 ignored issues
show
Bug introduced by
The Instance of FileIntent does not seem to have a member named path.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
Bug introduced by
The Instance of bytes does not seem to have a member named path.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
723
        assert text_file_copy.label == text_file.label
724
        assert text_file_copy.type == text_file.type
725
        assert text_file_copy.parent.content_id == folderb.content_id
726
        assert text_file_copy.owner.user_id == user.user_id
727
        assert text_file_copy.description == text_file.description
728
        assert text_file_copy.file_extension == text_file.file_extension
729
        assert text_file_copy.file_mimetype == text_file.file_mimetype
730
        assert text_file_copy.revision_type == ActionDescription.COPY
731
        assert len(text_file_copy.revisions) == len(text_file.revisions) + 1
732
733
    def test_unit_copy_file_different_label_same_parent_ok(self):
0 ignored issues
show
Coding Style Naming introduced by
The name test_unit_copy_file_different_label_same_parent_ok does not conform to the method naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
734
        uapi = UserApi(
735
            session=self.session,
736
            config=self.app_config,
737
            current_user=None,
738
        )
739
        group_api = GroupApi(
740
            current_user=None,
741
            session=self.session
742
        )
743
        groups = [group_api.get_one(Group.TIM_USER),
744
                  group_api.get_one(Group.TIM_MANAGER),
745
                  group_api.get_one(Group.TIM_ADMIN)]
746
747
        user = uapi.create_user(
748
            email='user1@user',
749
            groups=groups,
750
            save_now=True,
751
        )
752
        user2 = uapi.create_user(
753
            email='user2@user',
754
            groups=groups,
755
            save_now=True
756
        )
757
        workspace = WorkspaceApi(
758
            current_user=user,
759
            session=self.session
760
        ).create_workspace(
761
            'test workspace',
762
            save_now=True
763
        )
764
        RoleApi(current_user=user, session=self.session).create_one(
765
            user2, workspace,
766
            UserRoleInWorkspace.WORKSPACE_MANAGER,
767
            with_notif=False
768
        )
769
        api = ContentApi(
770
            current_user=user,
771
            session=self.session,
772
            config=self.app_config,
773
        )
774
        foldera = api.create(
775
            ContentType.Folder,
776
            workspace,
777
            None,
778
            'folder a',
779
            True
780
        )
781
        with self.session.no_autoflush:
782
            text_file = api.create(
783
                content_type=ContentType.File,
784
                workspace=workspace,
785
                parent=foldera,
786
                label='test_file',
787
                do_save=False,
788
            )
789
            api.update_file_data(
790
                text_file,
791
                'test_file',
792
                'text/plain',
793
                b'test_content'
794
            )
795
796
        api.save(
797
            text_file,
798
            ActionDescription.CREATION
799
        )
800
        api2 = ContentApi(
801
            current_user=user2,
802
            session=self.session,
803
            config=self.app_config,
804
        )
805
806
        api2.copy(
807
            item=text_file,
808
            new_label='test_file_copy'
809
        )
810
811
        transaction.commit()
812
        text_file_copy = api2.get_one_by_label_and_parent(
813
            'test_file_copy',
814
            foldera,
815
        )
816
817
        assert text_file != text_file_copy
818
        assert text_file_copy.content_id != text_file.content_id
819
        assert text_file_copy.workspace_id == workspace.workspace_id
820
        assert text_file_copy.depot_file.file.read() == text_file.depot_file.file.read()  # nopep8
0 ignored issues
show
Bug introduced by
The Instance of FileIntent does not seem to have a member named file.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
Bug introduced by
The Instance of bytes does not seem to have a member named file.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
821
        assert text_file_copy.depot_file.path != text_file.depot_file.path
0 ignored issues
show
Bug introduced by
The Instance of FileIntent does not seem to have a member named path.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
Bug introduced by
The Instance of bytes does not seem to have a member named path.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
822
        assert text_file_copy.label == 'test_file_copy'
823
        assert text_file_copy.type == text_file.type
824
        assert text_file_copy.parent.content_id == foldera.content_id
825
        assert text_file_copy.owner.user_id == user.user_id
826
        assert text_file_copy.description == text_file.description
827
        assert text_file_copy.file_extension == text_file.file_extension
828
        assert text_file_copy.file_mimetype == text_file.file_mimetype
829
        assert text_file_copy.revision_type == ActionDescription.COPY
830
        assert len(text_file_copy.revisions) == len(text_file.revisions) + 1
831
832
    def test_mark_read__workspace(self):
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
Comprehensibility introduced by
This function exceeds the maximum number of variables (19/15).
Loading history...
833
        uapi = UserApi(
834
            session=self.session,
835
            config=self.app_config,
836
            current_user=None,
837
        )
838
        group_api = GroupApi(
839
            current_user=None,
840
            session=self.session
841
        )
842
        groups = [group_api.get_one(Group.TIM_USER),
843
                  group_api.get_one(Group.TIM_MANAGER),
844
                  group_api.get_one(Group.TIM_ADMIN)]
845
846
        user_a = uapi.create_user(email='this.is@user',
847
                                  groups=groups, save_now=True)
848
        user_b = uapi.create_user(email='[email protected]',
849
                                  groups=groups, save_now=True)
850
851
        wapi = WorkspaceApi(
852
            current_user=user_a,
853
            session=self.session,
854
        )
855
        workspace1 = wapi.create_workspace(
856
            'test workspace n°1',
857
            save_now=True)
858
        workspace2 = wapi.create_workspace(
859
            'test workspace n°2',
860
            save_now=True)
861
862
        role_api1 = RoleApi(
863
            current_user=user_a,
864
            session=self.session,
865
        )
866
        role_api1.create_one(
867
            user_b,
868
            workspace1,
869
            UserRoleInWorkspace.READER,
870
            False
871
        )
872
873
        role_api2 = RoleApi(
874
            current_user=user_b,
875
            session=self.session,
876
        )
877
        role_api2.create_one(user_b, workspace2, UserRoleInWorkspace.READER,
878
                             False)
879
880
        cont_api_a = ContentApi(
881
            current_user=user_a,
882
            session=self.session,
883
            config=self.app_config,
884
        )
885
        cont_api_b = ContentApi(
886
            current_user=user_b,
887
            session=self.session,
888
            config=self.app_config,
889
        )
890
891
        # Creates page_1 & page_2 in workspace 1
892
        #     and page_3 & page_4 in workspace 2
893
        page_1 = cont_api_a.create(ContentType.Page, workspace1, None,
894
                                   'this is a page', do_save=True)
895
        page_2 = cont_api_a.create(ContentType.Page, workspace1, None,
896
                                   'this is page1', do_save=True)
897
        page_3 = cont_api_a.create(ContentType.Thread, workspace2, None,
898
                                   'this is page2', do_save=True)
899
        page_4 = cont_api_a.create(ContentType.File, workspace2, None,
900
                                   'this is page3', do_save=True)
901
902
        for rev in page_1.revisions:
903
            eq_(user_b not in rev.read_by.keys(), True)
904
        for rev in page_2.revisions:
905
            eq_(user_b not in rev.read_by.keys(), True)
906
        for rev in page_3.revisions:
907
            eq_(user_b not in rev.read_by.keys(), True)
908
        for rev in page_4.revisions:
909
            eq_(user_b not in rev.read_by.keys(), True)
910
911
        # Set as read the workspace n°1
912
        cont_api_b.mark_read__workspace(workspace=workspace1)
913
914
        for rev in page_1.revisions:
915
            eq_(user_b in rev.read_by.keys(), True)
916
        for rev in page_2.revisions:
917
            eq_(user_b in rev.read_by.keys(), True)
918
        for rev in page_3.revisions:
919
            eq_(user_b not in rev.read_by.keys(), True)
920
        for rev in page_4.revisions:
921
            eq_(user_b not in rev.read_by.keys(), True)
922
923
        # Set as read the workspace n°2
924
        cont_api_b.mark_read__workspace(workspace=workspace2)
925
926
        for rev in page_1.revisions:
927
            eq_(user_b in rev.read_by.keys(), True)
928
        for rev in page_2.revisions:
929
            eq_(user_b in rev.read_by.keys(), True)
930
        for rev in page_3.revisions:
931
            eq_(user_b in rev.read_by.keys(), True)
932
        for rev in page_4.revisions:
933
            eq_(user_b in rev.read_by.keys(), True)
934
935
    def test_mark_read(self):
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
936
        uapi = UserApi(
937
            session=self.session,
938
            config=self.app_config,
939
            current_user=None,
940
        )
941
        group_api = GroupApi(
942
            current_user=None,
943
            session=self.session
944
        )
945
        groups = [group_api.get_one(Group.TIM_USER),
946
                  group_api.get_one(Group.TIM_MANAGER),
947
                  group_api.get_one(Group.TIM_ADMIN)]
948
949
        user_a = uapi.create_user(
950
            email='this.is@user',
951
            groups=groups,
952
            save_now=True
953
        )
954
        user_b = uapi.create_user(
955
            email='[email protected]',
956
            groups=groups,
957
            save_now=True
958
        )
959
960
        wapi = WorkspaceApi(current_user=user_a, session=self.session)
961
        workspace_api = WorkspaceApi(
0 ignored issues
show
Unused Code introduced by
The variable workspace_api seems to be unused.
Loading history...
962
            current_user=user_a,
963
            session=self.session
964
        )
965
        workspace = wapi.create_workspace(
966
            'test workspace',
967
            save_now=True)
968
969
        role_api = RoleApi(
970
            current_user=user_a,
971
            session=self.session,
972
        )
973
        role_api.create_one(
974
            user_b,
975
            workspace,
976
            UserRoleInWorkspace.READER,
977
            False
978
        )
979
        cont_api_a = ContentApi(
980
            current_user=user_a,
981
            session=self.session,
982
            config=self.app_config,
983
        )
984
        cont_api_b = ContentApi(
985
            current_user=user_b,
986
            session=self.session,
987
            config=self.app_config,
988
        )
989
990
        page_1 = cont_api_a.create(ContentType.Page, workspace, None,
991
                                   'this is a page', do_save=True)
992
993
        for rev in page_1.revisions:
994
            eq_(user_b not in rev.read_by.keys(), True)
995
996
        cont_api_b.mark_read(page_1)
997
998
        for rev in page_1.revisions:
999
            eq_(user_b in rev.read_by.keys(), True)
1000
1001
    def test_mark_read__all(self):
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
Comprehensibility introduced by
This function exceeds the maximum number of variables (16/15).
Loading history...
1002
        uapi = UserApi(
1003
            session=self.session,
1004
            config=self.app_config,
1005
            current_user=None,
1006
        )
1007
        group_api = GroupApi(current_user=None, session=self.session)
1008
        groups = [group_api.get_one(Group.TIM_USER),
1009
                  group_api.get_one(Group.TIM_MANAGER),
1010
                  group_api.get_one(Group.TIM_ADMIN)]
1011
1012
        user_a = uapi.create_user(
1013
            email='this.is@user',
1014
            groups=groups,
1015
            save_now=True
1016
        )
1017
        user_b = uapi.create_user(
1018
            email='[email protected]',
1019
            groups=groups,
1020
            save_now=True
1021
        )
1022
1023
        wapi = WorkspaceApi(
1024
            current_user=user_a,
1025
            session=self.session,
1026
        )
1027
        workspace = wapi.create_workspace(
1028
            'test workspace',
1029
            save_now=True)
1030
1031
        role_api = RoleApi(
1032
            current_user=user_a,
1033
            session=self.session,
1034
        )
1035
        role_api.create_one(
1036
            user_b,
1037
            workspace,
1038
            UserRoleInWorkspace.READER,
1039
            False
1040
        )
1041
        cont_api_a = ContentApi(
1042
            current_user=user_a,
1043
            session=self.session,
1044
            config=self.app_config,
1045
        )
1046
        cont_api_b = ContentApi(
1047
            current_user=user_b,
1048
            session=self.session,
1049
            config=self.app_config,
1050
        )
1051
1052
        page_2 = cont_api_a.create(
1053
            ContentType.Page,
1054
            workspace,
1055
            None,
1056
            'this is page1',
1057
            do_save=True
1058
        )
1059
        page_3 = cont_api_a.create(
1060
            ContentType.Thread,
1061
            workspace,
1062
            None,
1063
            'this is page2',
1064
            do_save=True
1065
        )
1066
        page_4 = cont_api_a.create(
1067
            ContentType.File,
1068
            workspace,
1069
            None,
1070
            'this is page3',
1071
            do_save=True
1072
        )
1073
1074
        for rev in page_2.revisions:
1075
            eq_(user_b not in rev.read_by.keys(), True)
1076
        for rev in page_3.revisions:
1077
            eq_(user_b not in rev.read_by.keys(), True)
1078
        for rev in page_4.revisions:
1079
            eq_(user_b not in rev.read_by.keys(), True)
1080
1081
        self.session.refresh(page_2)
1082
        self.session.refresh(page_3)
1083
        self.session.refresh(page_4)
1084
1085
        cont_api_b.mark_read__all()
1086
1087
        for rev in page_2.revisions:
1088
            eq_(user_b in rev.read_by.keys(), True)
1089
        for rev in page_3.revisions:
1090
            eq_(user_b in rev.read_by.keys(), True)
1091
        for rev in page_4.revisions:
1092
            eq_(user_b in rev.read_by.keys(), True)
1093
1094
    def test_update(self):
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
Comprehensibility introduced by
This function exceeds the maximum number of variables (21/15).
Loading history...
1095
        uapi = UserApi(
1096
            session=self.session,
1097
            config=self.app_config,
1098
            current_user=None,
1099
        )
1100
        group_api = GroupApi(current_user=None, session=self.session)
1101
        groups = [group_api.get_one(Group.TIM_USER),
1102
                  group_api.get_one(Group.TIM_MANAGER),
1103
                  group_api.get_one(Group.TIM_ADMIN)]
1104
1105
        user1 = uapi.create_user(
1106
            email='this.is@user',
1107
            groups=groups,
1108
            save_now=True
1109
        )
1110
1111
        workspace_api = WorkspaceApi(current_user=user1, session=self.session)
1112
        workspace = workspace_api.create_workspace(
1113
            'test workspace',
1114
            save_now=True
1115
        )
1116
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
1117
        wid = workspace.workspace_id
1118
1119
        user2 = uapi.create_user()
1120
        user2.email = '[email protected]'
1121
        uapi.save(user2)
1122
1123
        RoleApi(
1124
            current_user=user1,
1125
            session=self.session
1126
        ).create_one(
1127
            user2,
1128
            workspace,
1129
            UserRoleInWorkspace.CONTENT_MANAGER,
1130
            with_notif=False,
1131
            flush=True
1132
        )
1133
1134
        # Test starts here
1135
1136
        api = ContentApi(
1137
            current_user=user1,
1138
            session=self.session,
1139
            config=self.app_config,
1140
        )
1141
1142
        p = api.create(ContentType.Page, workspace, None,
0 ignored issues
show
Coding Style Naming introduced by
The name p does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
1143
                       'this_is_a_page', True)
1144
1145
        u1id = user1.user_id
1146
        u2id = user2.user_id
1147
        pcid = p.content_id
1148
        poid = p.owner_id
1149
1150
        transaction.commit()
1151
1152
        # Refresh instances after commit
1153
        user1 = uapi.get_one(u1id)
1154
        workspace = WorkspaceApi(
1155
            current_user=user1,
1156
            session=self.session
1157
        ).get_one(wid)
1158
        api = ContentApi(
1159
            current_user=user1,
1160
            session=self.session,
1161
            config=self.app_config,
1162
        )
1163
1164
        content = api.get_one(pcid, ContentType.Any, workspace)
1165
        eq_(u1id, content.owner_id)
1166
        eq_(poid, content.owner_id)
1167
1168
        u2 = UserApi(
0 ignored issues
show
Coding Style Naming introduced by
The name u2 does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
1169
            session=self.session,
1170
            config=self.app_config,
1171
            current_user=None,
1172
        ).get_one(u2id)
1173
        api2 = ContentApi(
1174
            current_user=u2,
1175
            session=self.session,
1176
            config=self.app_config,
1177
        )
1178
        content2 = api2.get_one(pcid, ContentType.Any, workspace)
1179
        with new_revision(
1180
           session=self.session,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation (add 1 space).
Loading history...
1181
           tm=transaction.manager,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation (add 1 space).
Loading history...
1182
           content=content2,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation (add 1 space).
Loading history...
1183
        ):
1184
            api2.update_content(
1185
                content2,
1186
                'this is an updated page',
1187
                'new content'
1188
            )
1189
        api2.save(content2)
1190
        transaction.commit()
1191
1192
        # Refresh instances after commit
1193
        user1 = uapi.get_one(u1id)
1194
        workspace = WorkspaceApi(
1195
            current_user=user1,
1196
            session=self.session,
1197
        ).get_one(wid)
1198
        api = ContentApi(
1199
            current_user=user1,
1200
            session=self.session,
1201
            config=self.app_config,
1202
        )
1203
1204
        updated = api.get_one(pcid, ContentType.Any, workspace)
1205
        eq_(u2id, updated.owner_id,
1206
            'the owner id should be {} (found {})'.format(u2id,
1207
                                                          updated.owner_id))
1208
        eq_('this is an updated page', updated.label)
1209
        eq_('new content', updated.description)
1210
        eq_(ActionDescription.EDITION, updated.revision_type)
1211
1212
    def test_update_no_change(self):
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
1213
        uapi = UserApi(
1214
            session=self.session,
1215
            config=self.app_config,
1216
            current_user=None,
1217
        )
1218
        group_api = GroupApi(
1219
            current_user=None,
1220
            session=self.session
1221
        )
1222
        groups = [group_api.get_one(Group.TIM_USER),
1223
                  group_api.get_one(Group.TIM_MANAGER),
1224
                  group_api.get_one(Group.TIM_ADMIN)]
1225
1226
        user1 = uapi.create_user(
1227
            email='this.is@user',
1228
            groups=groups,
1229
            save_now=True,
1230
        )
1231
1232
        workspace = WorkspaceApi(
1233
            current_user=user1,
1234
            session=self.session,
1235
        ).create_workspace(
1236
            'test workspace',
1237
            save_now=True
1238
        )
1239
1240
        user2 = uapi.create_user()
1241
        user2.email = '[email protected]'
1242
        uapi.save(user2)
1243
1244
        RoleApi(
1245
            current_user=user1,
1246
            session=self.session
1247
        ).create_one(
1248
            user2,
1249
            workspace,
1250
            UserRoleInWorkspace.CONTENT_MANAGER,
1251
            with_notif=False,
1252
            flush=True
1253
        )
1254
        api = ContentApi(
1255
            current_user=user1,
1256
            session=self.session,
1257
            config=self.app_config,
1258
        )
1259
        with self.session.no_autoflush:
1260
            page = api.create(
1261
                content_type=ContentType.Page,
1262
                workspace=workspace,
1263
                label="same_content",
1264
                do_save=False
1265
            )
1266
            page.description = "Same_content_here"
1267
        api.save(page, ActionDescription.CREATION, do_notify=True)
1268
        transaction.commit()
1269
1270
        api2 = ContentApi(
1271
            current_user=user2,
1272
            session=self.session,
1273
            config=self.app_config,
1274
        )
1275
        content2 = api2.get_one(page.content_id, ContentType.Any, workspace)
1276
        with new_revision(
1277
           session=self.session,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation (add 1 space).
Loading history...
1278
           tm=transaction.manager,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation (add 1 space).
Loading history...
1279
           content=content2,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation (add 1 space).
Loading history...
1280
        ):
1281
            with pytest.raises(SameValueError):
1282
                api2.update_content(
1283
                    item=content2,
1284
                    new_label='same_content',
1285
                    new_content='Same_content_here'
1286
                )
1287
        api2.save(content2)
1288
        transaction.commit()
1289
1290
    def test_update_file_data(self):
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
Comprehensibility introduced by
This function exceeds the maximum number of variables (22/15).
Loading history...
1291
        uapi = UserApi(
1292
            session=self.session,
1293
            config=self.app_config,
1294
            current_user=None,
1295
        )
1296
        group_api = GroupApi(
1297
            current_user=None,
1298
            session=self.session
1299
        )
1300
        groups = [group_api.get_one(Group.TIM_USER),
1301
                  group_api.get_one(Group.TIM_MANAGER),
1302
                  group_api.get_one(Group.TIM_ADMIN)]
1303
1304
        user1 = uapi.create_user(
1305
            email='this.is@user',
1306
            groups=groups,
1307
            save_now=True
1308
        )
1309
1310
        workspace_api = WorkspaceApi(current_user=user1, session=self.session)
1311
        workspace = workspace_api.create_workspace(
1312
            'test workspace',
1313
            save_now=True
1314
        )
1315
        wid = workspace.workspace_id
1316
1317
        user2 = uapi.create_user()
1318
        user2.email = '[email protected]'
1319
        uapi.save(user2)
1320
1321
        RoleApi(
1322
            current_user=user1,
1323
            session=self.session,
1324
        ).create_one(
1325
            user2,
1326
            workspace,
1327
            UserRoleInWorkspace.CONTENT_MANAGER,
1328
            with_notif=True,
1329
            flush=True
1330
        )
1331
1332
        # Test starts here
1333
        api = ContentApi(
1334
            current_user=user1,
1335
            session=self.session,
1336
            config=self.app_config,
1337
        )
1338
        p = api.create(ContentType.File, workspace, None,
0 ignored issues
show
Coding Style Naming introduced by
The name p does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
1339
                       'this_is_a_page', True)
1340
1341
        u1id = user1.user_id
1342
        u2id = user2.user_id
1343
        pcid = p.content_id
1344
        poid = p.owner_id
1345
1346
        api.save(p)
1347
        transaction.commit()
1348
1349
        # Refresh instances after commit
1350
        user1 = uapi.get_one(u1id)
1351
        workspace_api2 = WorkspaceApi(current_user=user1, session=self.session)
1352
        workspace = workspace_api2.get_one(wid)
1353
        api = ContentApi(
1354
            current_user=user1,
1355
            session=self.session,
1356
            config=self.app_config,
1357
        )
1358
1359
        content = api.get_one(pcid, ContentType.Any, workspace)
1360
        eq_(u1id, content.owner_id)
1361
        eq_(poid, content.owner_id)
1362
1363
        u2 = UserApi(
0 ignored issues
show
Coding Style Naming introduced by
The name u2 does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
1364
            current_user=None,
1365
            session=self.session,
1366
            config=self.app_config,
1367
        ).get_one(u2id)
1368
        api2 = ContentApi(
1369
            current_user=u2,
1370
            session=self.session,
1371
            config=self.app_config,
1372
        )
1373
        content2 = api2.get_one(pcid, ContentType.Any, workspace)
1374
        with new_revision(
1375
            session=self.session,
1376
            tm=transaction.manager,
1377
            content=content2,
1378
        ):
1379
            api2.update_file_data(
1380
                content2,
1381
                'index.html',
1382
                'text/html',
1383
                b'<html>hello world</html>'
1384
            )
1385
        api2.save(content2)
1386
        transaction.commit()
1387
1388
        # Refresh instances after commit
1389
        user1 = uapi.get_one(u1id)
1390
        workspace = WorkspaceApi(
1391
            current_user=user1,
1392
            session=self.session,
1393
        ).get_one(wid)
1394
1395
        updated = api.get_one(pcid, ContentType.Any, workspace)
1396
        eq_(u2id, updated.owner_id,
1397
            'the owner id should be {} (found {})'.format(u2id,
1398
                                                          updated.owner_id))
1399
        eq_('this_is_a_page.html', updated.file_name)
1400
        eq_('text/html', updated.file_mimetype)
1401
        eq_(b'<html>hello world</html>', updated.depot_file.file.read())
1402
        eq_(ActionDescription.REVISION, updated.revision_type)
1403
1404
    def test_update_no_change(self):
0 ignored issues
show
Bug introduced by
method already defined line 1212
Loading history...
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
1405
        uapi = UserApi(
1406
            session=self.session,
1407
            config=self.app_config,
1408
            current_user=None,
1409
        )
1410
        group_api = GroupApi(
1411
            current_user=None,
1412
            session=self.session,
1413
        )
1414
        groups = [group_api.get_one(Group.TIM_USER),
1415
                  group_api.get_one(Group.TIM_MANAGER),
1416
                  group_api.get_one(Group.TIM_ADMIN)]
1417
1418
        user1 = uapi.create_user(
1419
            email='this.is@user',
1420
            groups=groups,
1421
            save_now=True,
1422
        )
1423
1424
        workspace_api = WorkspaceApi(current_user=user1, session=self.session)
1425
        workspace = workspace_api.create_workspace(
1426
            'test workspace',
1427
            save_now=True
1428
        )
1429
1430
        user2 = uapi.create_user()
1431
        user2.email = '[email protected]'
1432
        uapi.save(user2)
1433
1434
        RoleApi(
1435
            current_user=user1,
1436
            session=self.session,
1437
        ).create_one(
1438
            user2,
1439
            workspace,
1440
            UserRoleInWorkspace.CONTENT_MANAGER,
1441
            with_notif=False,
1442
            flush=True
1443
        )
1444
        api = ContentApi(
1445
            current_user=user1,
1446
            session=self.session,
1447
            config=self.app_config,
1448
        )
1449
        with self.session.no_autoflush:
1450
            page = api.create(
1451
                content_type=ContentType.Page,
1452
                workspace=workspace,
1453
                label="same_content",
1454
                do_save=False
1455
            )
1456
            api.update_file_data(
1457
                page,
1458
                'index.html',
1459
                'text/html',
1460
                b'<html>Same Content Here</html>'
1461
            )
1462
        api.save(page, ActionDescription.CREATION, do_notify=True)
1463
        transaction.commit()
1464
1465
        api2 = ContentApi(
1466
            current_user=user2,
1467
            session=self.session,
1468
            config=self.app_config,
1469
        )
1470
        content2 = api2.get_one(page.content_id, ContentType.Any, workspace)
1471
        with new_revision(
1472
            session=self.session,
1473
            tm=transaction.manager,
1474
            content=content2,
1475
        ):
1476
            with pytest.raises(SameValueError):
1477
                api2.update_file_data(
1478
                    page,
1479
                    'index.html',
1480
                    'text/html',
1481
                    b'<html>Same Content Here</html>'
1482
                )
1483
        api2.save(content2)
1484
        transaction.commit()
1485
1486 View Code Duplication
    def test_archive_unarchive(self):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
Comprehensibility introduced by
This function exceeds the maximum number of variables (23/15).
Loading history...
1487
        uapi = UserApi(
1488
            session=self.session,
1489
            config=self.app_config,
1490
            current_user=None,
1491
        )
1492
        group_api = GroupApi(current_user=None, session=self.session)
1493
        groups = [group_api.get_one(Group.TIM_USER),
1494
                  group_api.get_one(Group.TIM_MANAGER),
1495
                  group_api.get_one(Group.TIM_ADMIN)]
1496
1497
        user1 = uapi.create_user(
1498
            email='this.is@user',
1499
            groups=groups,
1500
            save_now=True
1501
        )
1502
        u1id = user1.user_id
1503
1504
        workspace_api = WorkspaceApi(current_user=user1, session=self.session)
1505
        workspace = workspace_api.create_workspace(
1506
            'test workspace',
1507
            save_now=True
1508
        )
1509
        wid = workspace.workspace_id
1510
1511
        user2 = uapi.create_user()
1512
        user2.email = '[email protected]'
1513
        uapi.save(user2)
1514
1515
        RoleApi(
1516
            current_user=user1,
1517
            session=self.session
1518
        ).create_one(
1519
            user2,
1520
            workspace,
1521
            UserRoleInWorkspace.CONTENT_MANAGER,
1522
            with_notif=True,
1523
            flush=True
1524
        )
1525
1526
        # show archived is used at the top end of the test
1527
        api = ContentApi(
1528
            current_user=user1,
1529
            session=self.session,
1530
            show_archived=True,
1531
            config=self.app_config,
1532
        )
1533
        p = api.create(ContentType.File, workspace, None,
0 ignored issues
show
Coding Style Naming introduced by
The name p does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
1534
                       'this_is_a_page', True)
1535
1536
        u1id = user1.user_id
1537
        u2id = user2.user_id
1538
        pcid = p.content_id
1539
        poid = p.owner_id
1540
1541
        transaction.commit()
1542
1543
        ####
1544
1545
        # refresh after commit
1546
        user1 = UserApi(
1547
            current_user=None,
1548
            config=self.app_config,
1549
            session=self.session
1550
        ).get_one(u1id)
1551
        workspace = WorkspaceApi(
1552
            current_user=user1,
1553
            session=self.session
1554
        ).get_one(wid)
1555
1556
        content = api.get_one(pcid, ContentType.Any, workspace)
1557
        eq_(u1id, content.owner_id)
1558
        eq_(poid, content.owner_id)
1559
1560
        u2api = UserApi(
1561
            session=self.session,
1562
            config=self.app_config,
1563
            current_user=None,
1564
        )
1565
        u2 = u2api.get_one(u2id)
0 ignored issues
show
Coding Style Naming introduced by
The name u2 does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
1566
        api2 = ContentApi(
1567
            current_user=u2,
1568
            session=self.session,
1569
            config=self.app_config,
1570
            show_archived=True,
1571
        )
1572
        content2 = api2.get_one(pcid, ContentType.Any, workspace)
1573
        with new_revision(
1574
                session=self.session,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation (remove 4 spaces).
Loading history...
1575
                tm=transaction.manager,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation (remove 4 spaces).
Loading history...
1576
                content=content2,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation (remove 4 spaces).
Loading history...
1577
        ):
1578
            api2.archive(content2)
1579
        api2.save(content2)
1580
        transaction.commit()
1581
1582
        # refresh after commit
1583
        user1 = UserApi(
1584
            current_user=None,
1585
            session=self.session,
1586
            config=self.app_config,
1587
        ).get_one(u1id)
1588
        workspace = WorkspaceApi(
1589
            current_user=user1,
1590
            session=self.session,
1591
        ).get_one(wid)
1592
        u2 = UserApi(
0 ignored issues
show
Coding Style Naming introduced by
The name u2 does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
1593
            current_user=None,
1594
            session=self.session,
1595
            config=self.app_config,
1596
        ).get_one(u2id)
1597
        api = ContentApi(
1598
            current_user=user1,
1599
            session=self.session,
1600
            config=self.app_config,
1601
            show_archived=True,
1602
        )
1603
        api2 = ContentApi(
1604
            current_user=u2,
1605
            session=self.session,
1606
            config=self.app_config,
1607
            show_archived=True,
1608
        )
1609
1610
        updated = api2.get_one(pcid, ContentType.Any, workspace)
1611
        eq_(u2id, updated.owner_id,
1612
            'the owner id should be {} (found {})'.format(u2id,
1613
                                                          updated.owner_id))
1614
        eq_(True, updated.is_archived)
1615
        eq_(ActionDescription.ARCHIVING, updated.revision_type)
1616
1617
        ####
1618
1619
        updated2 = api.get_one(pcid, ContentType.Any, workspace)
1620
        with new_revision(
1621
            session=self.session,
1622
            tm=transaction.manager,
1623
            content=updated,
1624
1625
        ):
1626
            api.unarchive(updated)
1627
        api.save(updated2)
1628
        eq_(False, updated2.is_archived)
1629
        eq_(ActionDescription.UNARCHIVING, updated2.revision_type)
1630
        eq_(u1id, updated2.owner_id)
1631
1632 View Code Duplication
    def test_delete_undelete(self):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
Comprehensibility introduced by
This function exceeds the maximum number of variables (22/15).
Loading history...
1633
        uapi = UserApi(
1634
            session=self.session,
1635
            config=self.app_config,
1636
            current_user=None,
1637
        )
1638
        group_api = GroupApi(
1639
            current_user=None,
1640
            session=self.session
1641
        )
1642
        groups = [group_api.get_one(Group.TIM_USER),
1643
                  group_api.get_one(Group.TIM_MANAGER),
1644
                  group_api.get_one(Group.TIM_ADMIN)]
1645
1646
        user1 = uapi.create_user(
1647
            email='this.is@user',
1648
            groups=groups,
1649
            save_now=True
1650
        )
1651
        u1id = user1.user_id
1652
1653
        workspace_api = WorkspaceApi(current_user=user1, session=self.session)
1654
        workspace = workspace_api.create_workspace(
1655
            'test workspace',
1656
            save_now=True
1657
        )
1658
        wid = workspace.workspace_id
1659
1660
        user2 = uapi.create_user()
1661
        user2.email = '[email protected]'
1662
        uapi.save(user2)
1663
1664
        RoleApi(
1665
            current_user=user1,
1666
            session=self.session
1667
        ).create_one(
1668
            user2,
1669
            workspace,
1670
            UserRoleInWorkspace.CONTENT_MANAGER,
1671
            with_notif=True,
1672
            flush=True
1673
        )
1674
1675
        # show archived is used at the top end of the test
1676
        api = ContentApi(
1677
            current_user=user1,
1678
            session=self.session,
1679
            config=self.app_config,
1680
            show_deleted=True,
1681
        )
1682
        p = api.create(ContentType.File, workspace, None,
0 ignored issues
show
Coding Style Naming introduced by
The name p does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
1683
                       'this_is_a_page', True)
1684
1685
        u1id = user1.user_id
1686
        u2id = user2.user_id
1687
        pcid = p.content_id
1688
        poid = p.owner_id
1689
1690
        transaction.commit()
1691
1692
        ####
1693
        user1 = UserApi(
1694
            current_user=None,
1695
            session=self.session,
1696
            config=self.app_config,
1697
        ).get_one(u1id)
1698
        workspace = WorkspaceApi(
1699
            current_user=user1,
1700
            session=self.session,
1701
        ).get_one(wid)
1702
1703
        content = api.get_one(pcid, ContentType.Any, workspace)
1704
        eq_(u1id, content.owner_id)
1705
        eq_(poid, content.owner_id)
1706
1707
        u2 = UserApi(
0 ignored issues
show
Coding Style Naming introduced by
The name u2 does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
1708
            current_user=None,
1709
            session=self.session,
1710
            config=self.app_config,
1711
        ).get_one(u2id)
1712
        api2 = ContentApi(
1713
            current_user=u2,
1714
            session=self.session,
1715
            config=self.app_config,
1716
            show_deleted=True,
1717
        )
1718
        content2 = api2.get_one(pcid, ContentType.Any, workspace)
1719
        with new_revision(
1720
                session=self.session,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation (remove 4 spaces).
Loading history...
1721
                tm=transaction.manager,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation (remove 4 spaces).
Loading history...
1722
                content=content2,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation (remove 4 spaces).
Loading history...
1723
        ):
1724
            api2.delete(content2)
1725
        api2.save(content2)
1726
        transaction.commit()
1727
1728
        ####
1729
1730
        user1 = UserApi(
1731
            current_user=None,
1732
            session=self.session,
1733
            config=self.app_config,
1734
        ).get_one(u1id)
1735
        workspace = WorkspaceApi(
1736
            current_user=user1,
1737
            session=self.session,
1738
        ).get_one(wid)
1739
        # show archived is used at the top end of the test
1740
        api = ContentApi(
1741
            current_user=user1,
1742
            session=self.session,
1743
            config=self.app_config,
1744
            show_deleted=True,
1745
        )
1746
        u2 = UserApi(
0 ignored issues
show
Coding Style Naming introduced by
The name u2 does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
1747
            current_user=None,
1748
            session=self.session,
1749
            config=self.app_config,
1750
        ).get_one(u2id)
1751
        api2 = ContentApi(
1752
            current_user=u2,
1753
            session=self.session,
1754
            config=self.app_config,
1755
            show_deleted=True
1756
        )
1757
1758
        updated = api2.get_one(pcid, ContentType.Any, workspace)
1759
        eq_(u2id, updated.owner_id,
1760
            'the owner id should be {} (found {})'.format(u2id,
1761
                                                          updated.owner_id))
1762
        eq_(True, updated.is_deleted)
1763
        eq_(ActionDescription.DELETION, updated.revision_type)
1764
1765
        ####
1766
1767
        updated2 = api.get_one(pcid, ContentType.Any, workspace)
1768
        with new_revision(
1769
            tm=transaction.manager,
1770
            session=self.session,
1771
            content=updated2,
1772
        ):
1773
            api.undelete(updated2)
1774
        api.save(updated2)
1775
        eq_(False, updated2.is_deleted)
1776
        eq_(ActionDescription.UNDELETION, updated2.revision_type)
1777
        eq_(u1id, updated2.owner_id)
1778
1779 View Code Duplication
    def test_search_in_label(self):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
1780
        # HACK - D.A. - 2015-03-09
1781
        # This test is based on a bug which does NOT return results found
1782
        # at root of a workspace (eg a folder)
1783
        uapi = UserApi(
1784
            session=self.session,
1785
            config=self.app_config,
1786
            current_user=None,
1787
        )
1788
        group_api = GroupApi(
1789
            current_user=None,
1790
            session=self.session,
1791
        )
1792
        groups = [group_api.get_one(Group.TIM_USER),
1793
                  group_api.get_one(Group.TIM_MANAGER),
1794
                  group_api.get_one(Group.TIM_ADMIN)]
1795
1796
        user = uapi.create_user(email='this.is@user',
1797
                                groups=groups, save_now=True)
1798
1799
        workspace = WorkspaceApi(
1800
            current_user=user,
1801
            session=self.session
1802
        ).create_workspace(
1803
            'test workspace',
1804
            save_now=True
1805
        )
1806
1807
        api = ContentApi(
1808
            current_user=user, 
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
1809
            session=self.session,
1810
            config=self.app_config,
1811
1812
        )
1813
        a = api.create(ContentType.Folder, workspace, None,
0 ignored issues
show
Coding Style Naming introduced by
The name a does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
1814
                       'this is randomized folder', True)
1815
        p = api.create(ContentType.Page, workspace, a,
0 ignored issues
show
Coding Style Naming introduced by
The name p does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
1816
                       'this is randomized label content', True)
1817
1818
        with new_revision(
1819
            session=self.session,
1820
            tm=transaction.manager,
1821
            content=p,
1822
        ):
1823
            p.description = 'This is some amazing test'
1824
1825
        api.save(p)
1826
        original_id = p.content_id
1827
1828
        res = api.search(['randomized'])
1829
        eq_(1, len(res.all()))
1830
        item = res.all()[0]
1831
        eq_(original_id, item.content_id)
1832
1833 View Code Duplication
    def test_search_in_description(self):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
1834
        # HACK - D.A. - 2015-03-09
1835
        # This test is based on a bug which does NOT return results found
1836
        # at root of a workspace (eg a folder)
1837
1838
        uapi = UserApi(
1839
            session=self.session,
1840
            config=self.app_config,
1841
            current_user=None,
1842
        )
1843
        group_api = GroupApi(
1844
            current_user=None,
1845
            session=self.session,
1846
        )
1847
        groups = [group_api.get_one(Group.TIM_USER),
1848
                  group_api.get_one(Group.TIM_MANAGER),
1849
                  group_api.get_one(Group.TIM_ADMIN)]
1850
1851
        user = uapi.create_user(email='this.is@user',
1852
                                groups=groups, save_now=True)
1853
1854
        workspace = WorkspaceApi(
1855
            current_user=user,
1856
            session=self.session
1857
        ).create_workspace(
1858
            'test workspace',
1859
            save_now=True,
1860
        )
1861
1862
        api = ContentApi(
1863
            current_user=user, 
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
1864
            session=self.session,
1865
            config=self.app_config,
1866
        )
1867
        a = api.create(ContentType.Folder, workspace, None,
0 ignored issues
show
Coding Style Naming introduced by
The name a does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
1868
                       'this is randomized folder', True)
1869
        p = api.create(ContentType.Page, workspace, a,
0 ignored issues
show
Coding Style Naming introduced by
The name p does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
1870
                       'this is dummy label content', True)
1871
1872
        with new_revision(
1873
            tm=transaction.manager,
1874
            session=self.session,
1875
            content=p,
1876
        ):
1877
            p.description = 'This is some amazing test'
1878
1879
        api.save(p)
1880
        original_id = p.content_id
1881
1882
        res = api.search(['dummy'])
1883
        eq_(1, len(res.all()))
1884
        item = res.all()[0]
1885
        eq_(original_id, item.content_id)
1886
1887
    def test_search_in_label_or_description(self):
0 ignored issues
show
Coding Style Naming introduced by
The name test_search_in_label_or_description does not conform to the method naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
1888
        # HACK - D.A. - 2015-03-09
1889
        # This test is based on a bug which does NOT return results found
1890
        # at root of a workspace (eg a folder)
1891
1892
        uapi = UserApi(
1893
            session=self.session,
1894
            config=self.app_config,
1895
            current_user=None,
1896
        )
1897
        group_api = GroupApi(current_user=None, session=self.session)
1898
        groups = [group_api.get_one(Group.TIM_USER),
1899
                  group_api.get_one(Group.TIM_MANAGER),
1900
                  group_api.get_one(Group.TIM_ADMIN)]
1901
1902
        user = uapi.create_user(email='this.is@user',
1903
                                groups=groups, save_now=True)
1904
1905
        workspace = WorkspaceApi(
1906
            current_user=user,
1907
            session=self.session
1908
        ).create_workspace('test workspace', save_now=True)
1909
1910
        api = ContentApi(
1911
            current_user=user, 
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
1912
            session=self.session,
1913
            config=self.app_config,
1914
        )
1915
        a = api.create(ContentType.Folder, workspace, None,
0 ignored issues
show
Coding Style Naming introduced by
The name a does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
1916
                       'this is randomized folder', True)
1917
        p1 = api.create(ContentType.Page, workspace, a,
0 ignored issues
show
Coding Style Naming introduced by
The name p1 does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
1918
                        'this is dummy label content', True)
1919
        p2 = api.create(ContentType.Page, workspace, a, 'Hey ! Jon !', True)
0 ignored issues
show
Coding Style Naming introduced by
The name p2 does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
1920
1921
        with new_revision(
1922
            session=self.session,
1923
            tm=transaction.manager,
1924
            content=p1,
1925
        ):
1926
            p1.description = 'This is some amazing test'
1927
1928
        with new_revision(
1929
            session=self.session,
1930
            tm=transaction.manager,
1931
            content=p2,
1932
        ):
1933
            p2.description = 'What\'s up ?'
1934
1935
        api.save(p1)
1936
        api.save(p2)
1937
1938
        id1 = p1.content_id
1939
        id2 = p2.content_id
1940
1941
        eq_(1, self.session.query(Workspace).filter(Workspace.label == 'test workspace').count())
1942
        eq_(1, self.session.query(ContentRevisionRO).filter(ContentRevisionRO.label == 'this is randomized folder').count())
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (124/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
1943
        eq_(2, self.session.query(ContentRevisionRO).filter(ContentRevisionRO.label == 'this is dummy label content').count())
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (126/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
1944
        eq_(1, self.session.query(ContentRevisionRO).filter(ContentRevisionRO.description == 'This is some amazing test').count())
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (130/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
1945
        eq_(2, self.session.query(ContentRevisionRO).filter(ContentRevisionRO.label == 'Hey ! Jon !').count())
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (110/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
1946
        eq_(1, self.session.query(ContentRevisionRO).filter(ContentRevisionRO.description == 'What\'s up ?').count())
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (117/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
1947
1948
        res = api.search(['dummy', 'jon'])
1949
        eq_(2, len(res.all()))
1950
1951
        eq_(True, id1 in [o.content_id for o in res.all()])
1952
        eq_(True, id2 in [o.content_id for o in res.all()])
1953
1954
    def test_unit__search_exclude_content_under_deleted_or_archived_parents__ok(self):  # nopep8
0 ignored issues
show
Coding Style Naming introduced by
The name test_unit__search_exclud...or_archived_parents__ok does not conform to the method naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
1955
        admin = self.session.query(User)\
1956
            .filter(User.email == '[email protected]').one()
1957
        workspace = self._create_workspace_and_test(
1958
            'workspace_1',
1959
            admin
1960
        )
1961
        folder_1 = self._create_content_and_test(
1962
            'folder_1',
1963
            workspace=workspace,
1964
            type=ContentType.Folder
1965
        )
1966
        folder_2 = self._create_content_and_test(
1967
            'folder_2',
1968
            workspace=workspace,
1969
            type=ContentType.Folder
1970
        )
1971
        page_1 = self._create_content_and_test(
1972
            'foo', workspace=workspace,
1973
            type=ContentType.Page,
1974
            parent=folder_1
1975
        )
1976
        page_2 = self._create_content_and_test(
1977
            'bar',
1978
            workspace=workspace,
1979
            type=ContentType.Page,
1980
            parent=folder_2
1981
        )
1982
1983
        api = ContentApi(
1984
            current_user=admin,
1985
            session=self.session,
1986
            config=self.app_config,
1987
        )
1988
1989
        foo_result = api.search(['foo']).all()
1990
        eq_(1, len(foo_result))
1991
        assert page_1 in foo_result
1992
1993
        bar_result = api.search(['bar']).all()
1994
        eq_(1, len(bar_result))
1995
        assert page_2 in bar_result
1996
1997
        with new_revision(
1998
            session=self.session,
1999
            tm=transaction.manager,
2000
            content=folder_1,
2001
        ):
2002
            api.delete(folder_1)
2003
        with new_revision(
2004
            session=self.session,
2005
            tm=transaction.manager,
2006
            content=folder_2,
2007
        ):
2008
            api.archive(folder_2)
2009
2010
        # Actually ContentApi.search don't filter it
2011
        foo_result = api.search(['foo']).all()
2012
        eq_(1, len(foo_result))
2013
        assert page_1 in foo_result
2014
2015
        bar_result = api.search(['bar']).all()
2016
        eq_(1, len(bar_result))
2017
        assert page_2 in bar_result
2018
2019
        # ContentApi offer exclude_unavailable method to do it
2020
        foo_result = api.search(['foo']).all()
2021
        api.exclude_unavailable(foo_result)
2022
        eq_(0, len(foo_result))
2023
2024
        bar_result = api.search(['bar']).all()
2025
        api.exclude_unavailable(bar_result)
2026
        eq_(0, len(bar_result))
2027
2028
2029
class TestContentApiSecurity(DefaultTest):
0 ignored issues
show
Coding Style introduced by
This class should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
Unused Code introduced by
The variable __class__ seems to be unused.
Loading history...
2030
    fixtures = [FixtureTest, ]
2031
2032
    def test_unit__cant_get_non_access_content__ok__nominal_case(self):
0 ignored issues
show
Coding Style Naming introduced by
The name test_unit__cant_get_non_...ntent__ok__nominal_case does not conform to the method naming conventions ((([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
2033
        admin = self.session.query(User)\
2034
            .filter(User.email == '[email protected]').one()
2035
        bob = self.session.query(User)\
2036
            .filter(User.email == '[email protected]').one()
2037
2038
        bob_workspace = WorkspaceApi(
2039
            current_user=bob,
2040
            session=self.session,
2041
        ).create_workspace(
2042
            'bob_workspace',
2043
            save_now=True,
2044
        )
2045
        admin_workspace = WorkspaceApi(
2046
            current_user=admin,
2047
            session=self.session,
2048
        ).create_workspace(
2049
            'admin_workspace',
2050
            save_now=True,
2051
        )
2052
2053
        bob_page = ContentApi(
0 ignored issues
show
Unused Code introduced by
The variable bob_page seems to be unused.
Loading history...
2054
            current_user=bob,
2055
            session=self.session,
2056
            config=self.app_config,
2057
        ).create(
2058
            content_type=ContentType.Page,
2059
            workspace=bob_workspace,
2060
            label='bob_page',
2061
            do_save=True,
2062
        )
2063
2064
        admin_page = ContentApi(
0 ignored issues
show
Unused Code introduced by
The variable admin_page seems to be unused.
Loading history...
2065
            current_user=admin,
2066
            session=self.session,
2067
            config=self.app_config,
2068
        ).create(
2069
            content_type=ContentType.Page,
2070
            workspace=admin_workspace,
2071
            label='admin_page',
2072
            do_save=True,
2073
        )
2074
2075
        bob_viewable = ContentApi(
2076
            current_user=bob,
2077
            session=self.session,
2078
            config=self.app_config,
2079
        ).get_all()
2080
        eq_(1, len(bob_viewable), 'Bob should view only one content')
2081
        eq_(
2082
            'bob_page',
2083
            bob_viewable[0].label,
2084
            'Bob should not view "{0}" content'.format(
2085
                bob_viewable[0].label,
2086
            )
2087
        )
2088