tracim.tests.library.test_workspace   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 110
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 89
dl 0
loc 110
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A TestThread.test_get_notifiable_roles() 0 23 1
B TestThread.test_unit__get_all_manageable() 0 44 1
A TestThread.test_children() 0 22 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
3
from tracim.lib.core.content import ContentApi
4
from tracim.lib.core.group import GroupApi
5
from tracim.lib.core.user import UserApi
6
from tracim.lib.core.userworkspace import RoleApi
7
from tracim.lib.core.workspace import WorkspaceApi
8
from tracim.models import Content
9
from tracim.models import User
10
from tracim.models.auth import Group
11
from tracim.models.data import UserRoleInWorkspace
12
from tracim.models.data import Workspace
13
#from tracim.tests import BaseTestThread
14
from tracim.tests import DefaultTest
15
from tracim.tests import eq_
16
17
class TestThread(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...
18
19
    def test_children(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...
20
        admin = self.session.query(User).filter(
21
            User.email == '[email protected]'
22
        ).one()
23
        self._create_thread_and_test(
24
            workspace_name='workspace_1',
25
            folder_name='folder_1',
26
            thread_name='thread_1',
27
            user=admin
28
        )
29
        workspace = self.session.query(Workspace).filter(
30
            Workspace.label == 'workspace_1'
31
        ).one()
32
        content_api = ContentApi(
33
            session=self.session,
34
            current_user=admin,
35
            config=self.app_config,
36
        )
37
        folder = content_api.get_canonical_query().filter(
38
            Content.label == 'folder_1'
39
        ).one()
40
        eq_([folder, ], list(workspace.get_valid_children()))
41
42
    def test_get_notifiable_roles(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...
43
        admin = self.session.query(User) \
44
            .filter(User.email == '[email protected]').one()
45
        wapi = WorkspaceApi(
46
            session=self.session,
47
            current_user=admin,
48
        )
49
        w = wapi.create_workspace(label='workspace w', save_now=True)
0 ignored issues
show
Coding Style Naming introduced by
The name w 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...
50
        uapi = UserApi(
51
            session=self.session,
52
            current_user=admin,
53
            config=self.config
54
        )
55
        u = uapi.create_user(email='[email protected]', save_now=True)
0 ignored issues
show
Coding Style Naming introduced by
The name u 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...
56
        eq_([], wapi.get_notifiable_roles(workspace=w))
57
        rapi = RoleApi(
58
            session=self.session,
59
            current_user=admin,
60
        )
61
        r = rapi.create_one(u, w, UserRoleInWorkspace.READER, with_notif=True)
0 ignored issues
show
Coding Style Naming introduced by
The name r 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...
62
        eq_([r, ], wapi.get_notifiable_roles(workspace=w))
63
        u.is_active = False
64
        eq_([], wapi.get_notifiable_roles(workspace=w))
65
66
    def test_unit__get_all_manageable(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...
67
        admin = self.session.query(User) \
68
            .filter(User.email == '[email protected]').one()
69
        uapi = UserApi(
70
            session=self.session,
71
            current_user=admin,
72
            config=self.config,
73
        )
74
        # Checks a case without workspaces.
75
        wapi = WorkspaceApi(
76
            session=self.session,
77
            current_user=admin,
78
        )
79
        eq_([], wapi.get_all_manageable())
80
        # Checks an admin gets all workspaces.
81
        w4 = wapi.create_workspace(label='w4')
0 ignored issues
show
Coding Style Naming introduced by
The name w4 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...
82
        w3 = wapi.create_workspace(label='w3')
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...
83
        w2 = wapi.create_workspace(label='w2')
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...
84
        w1 = wapi.create_workspace(label='w1')
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...
85
        eq_([w1, w2, w3, w4], wapi.get_all_manageable())
86
        # Checks a regular user gets none workspace.
87
        gapi = GroupApi(
88
            session=self.session,
89
            current_user=None,
90
        )
91
        u = uapi.create_user('[email protected]', [gapi.get_one(Group.TIM_USER)], True)
0 ignored issues
show
Coding Style Naming introduced by
The name u 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...
92
        wapi = WorkspaceApi(
93
            session=self.session,
94
            current_user=u
95
        )
96
        rapi = RoleApi(
97
            session=self.session,
98
            current_user=u
99
        )
100
        rapi.create_one(u, w4, UserRoleInWorkspace.READER, False)
101
        rapi.create_one(u, w3, UserRoleInWorkspace.CONTRIBUTOR, False)
102
        rapi.create_one(u, w2, UserRoleInWorkspace.CONTENT_MANAGER, False)
103
        rapi.create_one(u, w1, UserRoleInWorkspace.WORKSPACE_MANAGER, False)
104
        eq_([], wapi.get_all_manageable())
105
        # Checks a manager gets only its own workspaces.
106
        u.groups.append(gapi.get_one(Group.TIM_MANAGER))
107
        rapi.delete_one(u.user_id, w2.workspace_id)
108
        rapi.create_one(u, w2, UserRoleInWorkspace.WORKSPACE_MANAGER, False)
109
        eq_([w1, w2], wapi.get_all_manageable())
110