Kaynağa Gözat

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

Guénaël Muller 5 yıl önce
ebeveyn
işleme
881a4a4683

+ 10 - 2
backend/tracim_backend/lib/core/workspace.py Dosyayı Görüntüle

@@ -3,9 +3,11 @@ import typing
3 3
 
4 4
 from sqlalchemy.orm import Query
5 5
 from sqlalchemy.orm import Session
6
+from sqlalchemy.orm.exc import NoResultFound
6 7
 
7 8
 from tracim_backend import CFG
8 9
 from tracim_backend.exceptions import EmptyLabelNotAllowed
10
+from tracim_backend.exceptions import WorkspaceNotFound
9 11
 from tracim_backend.lib.utils.translation import fake_translator as _
10 12
 
11 13
 from tracim_backend.lib.core.userworkspace import RoleApi
@@ -132,10 +134,16 @@ class WorkspaceApi(object):
132 134
         return workspace
133 135
 
134 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 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 149
     def get_one_for_current_user(self, id):

Dosya farkı çok büyük olduğundan ihmal edildi
+ 1805 - 161
backend/tracim_backend/tests/functional/test_user.py