Browse Source

workspace not found exception in workspace api + few tests for user endpoints

Guénaël Muller 6 years ago
parent
commit
881a4a4683

+ 10 - 2
backend/tracim_backend/lib/core/workspace.py View File

3
 
3
 
4
 from sqlalchemy.orm import Query
4
 from sqlalchemy.orm import Query
5
 from sqlalchemy.orm import Session
5
 from sqlalchemy.orm import Session
6
+from sqlalchemy.orm.exc import NoResultFound
6
 
7
 
7
 from tracim_backend import CFG
8
 from tracim_backend import CFG
8
 from tracim_backend.exceptions import EmptyLabelNotAllowed
9
 from tracim_backend.exceptions import EmptyLabelNotAllowed
10
+from tracim_backend.exceptions import WorkspaceNotFound
9
 from tracim_backend.lib.utils.translation import fake_translator as _
11
 from tracim_backend.lib.utils.translation import fake_translator as _
10
 
12
 
11
 from tracim_backend.lib.core.userworkspace import RoleApi
13
 from tracim_backend.lib.core.userworkspace import RoleApi
132
         return workspace
134
         return workspace
133
 
135
 
134
     def get_one(self, id):
136
     def get_one(self, id):
135
-        return self._base_query().filter(Workspace.workspace_id == id).one()
137
+        try:
138
+            return self._base_query().filter(Workspace.workspace_id == id).one()
139
+        except NoResultFound as exc:
140
+            raise WorkspaceNotFound('workspace {} does not exist or not visible for user'.format(id)) from exc  # nopep8
136
 
141
 
137
     def get_one_by_label(self, label: str) -> Workspace:
142
     def get_one_by_label(self, label: str) -> Workspace:
138
-        return self._base_query().filter(Workspace.label == label).one()
143
+        try:
144
+            return self._base_query().filter(Workspace.label == label).one()
145
+        except NoResultFound as exc:
146
+            raise WorkspaceNotFound('workspace {} does not exist or not visible for user'.format(id)) from exc  # nopep8
139
 
147
 
140
     """
148
     """
141
     def get_one_for_current_user(self, id):
149
     def get_one_for_current_user(self, id):

File diff suppressed because it is too large
+ 1805 - 161
backend/tracim_backend/tests/functional/test_user.py