tracim.fixtures.content   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 149
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 115
dl 0
loc 149
rs 10
c 0
b 0
f 0
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
B Content.insert() 0 132 1
1
# -*- coding: utf-8 -*-
0 ignored issues
show
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
from depot.io.utils import FileIntent
3
4
from tracim import models
5
from tracim.fixtures import Fixture
6
from tracim.fixtures.users_and_groups import Test
7
from tracim.lib.core.content import ContentApi
8
from tracim.lib.core.userworkspace import RoleApi
9
from tracim.lib.core.workspace import WorkspaceApi
10
from tracim.models.data import ContentType
11
from tracim.models.data import UserRoleInWorkspace
12
13
14
class Content(Fixture):
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...
15
    require = [Test]
16
17
    def insert(self):
0 ignored issues
show
Comprehensibility introduced by
This function exceeds the maximum number of variables (22/15).
Loading history...
18
        admin = self._session.query(models.User) \
19
            .filter(models.User.email == '[email protected]') \
20
            .one()
21
        bob = self._session.query(models.User) \
22
            .filter(models.User.email == '[email protected]') \
23
            .one()
24
        admin_workspace_api = WorkspaceApi(
25
            current_user=admin,
26
            session=self._session,
27
        )
28
        bob_workspace_api = WorkspaceApi(
29
            current_user=bob,
30
            session=self._session,
31
        )
32
        content_api = ContentApi(
0 ignored issues
show
Bug introduced by
It seems like a value for argument config is missing in the constructor call.
Loading history...
33
            current_user=admin,
34
            session=self._session,
35
        )
36
        role_api = RoleApi(
37
            current_user=admin,
38
            session=self._session,
39
        )
40
41
        # Workspaces
42
        w1 = admin_workspace_api.create_workspace('w1', save_now=True)
0 ignored issues
show
Coding Style Naming introduced by
The name w1 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...
43
        w2 = bob_workspace_api.create_workspace('w2', save_now=True)
0 ignored issues
show
Coding Style Naming introduced by
The name w2 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...
44
        w3 = admin_workspace_api.create_workspace('w3', save_now=True)
0 ignored issues
show
Coding Style Naming introduced by
The name w3 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...
45
46
        # Workspaces roles
47
        role_api.create_one(
48
            user=bob,
49
            workspace=w1,
50
            role_level=UserRoleInWorkspace.CONTENT_MANAGER,
51
            with_notif=False,
52
        )
53
54
        # Folders
55
        w1f1 = content_api.create(
56
            content_type=ContentType.Folder,
57
            workspace=w1,
58
            label='w1f1',
59
            do_save=True,
60
        )
61
        w1f2 = content_api.create(
0 ignored issues
show
Unused Code introduced by
The variable w1f2 seems to be unused.
Loading history...
62
            content_type=ContentType.Folder,
63
            workspace=w1,
64
            label='w1f2',
65
            do_save=True,
66
        )
67
68
        w2f1 = content_api.create(
69
            content_type=ContentType.Folder,
70
            workspace=w2,
71
            label='w2f1',
72
            do_save=True,
73
        )
74
        w2f2 = content_api.create(
0 ignored issues
show
Unused Code introduced by
The variable w2f2 seems to be unused.
Loading history...
75
            content_type=ContentType.Folder,
76
            workspace=w2,
77
            label='w2f2',
78
            do_save=True,
79
        )
80
81
        w3f1 = content_api.create(
0 ignored issues
show
Unused Code introduced by
The variable w3f1 seems to be unused.
Loading history...
82
            content_type=ContentType.Folder,
83
            workspace=w3,
84
            label='w3f3',
85
            do_save=True,
86
        )
87
88
        # Pages, threads, ..
89
        w1f1p1 = content_api.create(
0 ignored issues
show
Unused Code introduced by
The variable w1f1p1 seems to be unused.
Loading history...
90
            content_type=ContentType.Page,
91
            workspace=w1,
92
            parent=w1f1,
93
            label='w1f1p1',
94
            do_save=True,
95
        )
96
        w1f1t1 = content_api.create(
97
            content_type=ContentType.Thread,
98
            workspace=w1,
99
            parent=w1f1,
100
            label='w1f1t1',
101
            do_save=False,
102
        )
103
        w1f1t1.description = 'w1f1t1 description'
104
        self._session.add(w1f1t1)
105
        w1f1d1_txt = content_api.create(
106
            content_type=ContentType.File,
107
            workspace=w1,
108
            parent=w1f1,
109
            label='w1f1d1',
110
            do_save=False,
111
        )
112
        w1f1d1_txt.file_extension = '.txt'
113
        w1f1d1_txt.depot_file = FileIntent(
114
            b'w1f1d1 content',
115
            'w1f1d1.txt',
116
            'text/plain',
117
        )
118
        self._session.add(w1f1d1_txt)
119
        w1f1d2_html = content_api.create(
120
            content_type=ContentType.File,
121
            workspace=w1,
122
            parent=w1f1,
123
            label='w1f1d2',
124
            do_save=False,
125
        )
126
        w1f1d2_html.file_extension = '.html'
127
        w1f1d2_html.depot_file = FileIntent(
128
            b'<p>w1f1d2 content</p>',
129
            'w1f1d2.html',
130
            'text/html',
131
        )
132
        self._session.add(w1f1d2_html)
133
        w1f1f1 = content_api.create(
0 ignored issues
show
Unused Code introduced by
The variable w1f1f1 seems to be unused.
Loading history...
134
            content_type=ContentType.Folder,
135
            workspace=w1,
136
            label='w1f1f1',
137
            parent=w1f1,
138
            do_save=True,
139
        )
140
141
        w2f1p1 = content_api.create(
0 ignored issues
show
Unused Code introduced by
The variable w2f1p1 seems to be unused.
Loading history...
142
            content_type=ContentType.Page,
143
            workspace=w2,
144
            parent=w2f1,
145
            label='w2f1p1',
146
            do_save=True,
147
        )
148
        self._session.flush()
149