Skip to content

Commit 4c4c8ef

Browse files
committed
Merge pull request #207 from Syncano/LIB-175
[LIB-175] Add custom exception when user is not found on groups methods.
2 parents 357ee5e + f7349b4 commit 4c4c8ef

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

syncano/exceptions.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,7 @@ class SyncanoDoesNotExist(SyncanoException):
7575

7676
class RevisionMismatchException(SyncanoRequestError):
7777
"""Revision do not match with expected one"""
78+
79+
80+
class UserNotFound(SyncanoRequestError):
81+
"""Special error to handle user not found case."""

syncano/models/accounts.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from syncano.exceptions import SyncanoValueError
1+
from syncano.exceptions import SyncanoRequestError, SyncanoValueError, UserNotFound
22

33
from . import fields
44
from .base import Model
@@ -214,7 +214,14 @@ def _group_users_method(self, user_id=None, method='GET'):
214214
if user_id is not None:
215215
endpoint += '{}/'.format(user_id)
216216
connection = self._get_connection()
217-
return connection.request(method, endpoint)
217+
try:
218+
response = connection.request(method, endpoint)
219+
except SyncanoRequestError as e:
220+
if e.status_code == 404:
221+
raise UserNotFound(e.status_code, 'User not found.')
222+
raise
223+
224+
return response
218225

219226
def list_users(self):
220227
return self._group_users_method()
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# -*- coding: utf-8 -*-
2+
from syncano.exceptions import UserNotFound
23
from syncano.models import User
34
from tests.integration_test import InstanceMixin, IntegrationTest
45

@@ -39,3 +40,18 @@ def test_profile_change_schema(self):
3940
self.user.profile.save()
4041
user = User.please.get(id=self.user.id)
4142
self.assertEqual(user.profile.profile_pic, self.SAMPLE_PROFILE_PIC)
43+
44+
45+
class UserTest(InstanceMixin, IntegrationTest):
46+
47+
@classmethod
48+
def setUpClass(cls):
49+
super(UserTest, cls).setUpClass()
50+
51+
cls.group = cls.instance.groups.create(
52+
label='testgroup'
53+
)
54+
55+
def test_if_custom_error_is_raised_on_user_group(self):
56+
with self.assertRaises(UserNotFound):
57+
self.group.user_details(user_id=221)

0 commit comments

Comments
 (0)